In case you are using 7.x-2.0-dev version of geofield you need to change the field structure using ['geom'] and ["input_format"], see attachment
array(1) {
["und"]=>
array(1) {
[0]=>
array(2) {
["geom"]=>
array(3) {
["geo_type"]=>
string(5) "point"
["lat"]=>
string(9) "41.895466"
["lon"]=>
string(9) "12.482324"
}
["input_format"]=>
string(7) "lat/lon"
}
}
}

In your migration class you should define
in constructor:
$geo_arguments = array(
'lat' => array('source_field' => 'profile_lat'),
'lon' => array('source_field' => 'profile_long'),
'input_format' => array('source_field' => 'field_source_geotype_input_format'),
);
And in prepareRow
$row->field_source_geotype_input_format = 'lat/lon';

Files: 
CommentFileSizeAuthor
geofield.inc_.patch940 bytesmarco.giaco

Comments

Sheldon Rampton’s picture

Geofield migrations were failing for me using Geofield 1.2. I was able to get them working by updating to Geofield 2.0 and then applying this patch to Migrate Extras.

scottrouse’s picture

This works, but it took me a while to figure it out.

Reviewing the comments in the migrate_extras/geofield.inc file, we configure an array of arguments inside our constructor:

$geo_arguments = array(
    'lat' => array('source_field' => 'Latitude'),
    'lon' => array('source_field' => 'Longitude'),
    'input_format' => array('source_field' => 'geotype_input_format'),
);

Note that Latitude and Longitude are the names of the respective fields from my source data.

Per the comments in the migrate_extras/geofield.inc file, the geometry type should be passed in as the primary value

$this->addFieldMapping('field_station_coordinates', 'point')
    ->arguments($geo_arguments);

Note that point in the snippet above didn’t exist in my source data, so I define it in prepareRow().

In your prepareRow() function, we need to define two more “rows” that we’re referencing above (geotype_input_format and point):

function prepareRow($row) {
    $row->geotype_input_format = 'lat/lon';
    $row->point = 'Point'; //So we can pass the Geometry Type in addFieldMapping
}
scottrouse’s picture

Issue summary: View changes
Status: Active » Reviewed & tested by the community
Miguelos’s picture

I used this code and got this error:

The field mapping arguments() method is now deprecated - please use subfield notation instead.

Using subfield notation:

  • <?php
        $this->addFieldMapping('field_location', 'point');
        $this->addFieldMapping('field_location:input_format', 'input_format');
        $this->addFieldMapping('field_location:geo_type', 'point');
        $this->addFieldMapping('field_location:lat', 'Latitude')
             ->xpath('Latitude');
        $this->addFieldMapping('field_location:lon', 'Longitude')
             ->xpath('Longitude');?>
  • Inside prepareRow()
    <?php
      public function prepareRow($row) {
      $row->geo_type = 'point';
      $row->input_format = 'lat/lon';
     }?>

Also I tried with the patch proposed in #1411836: Field handler for Migrate module but I had to modify it to got it working with 'lat/lon' input_type. This worked for me fine.

fonant’s picture

That could be written more simply as

  $this->addFieldMapping('field_location', 'point');
  $this->addFieldMapping('field_location:input_format')->defaultValue('lat/lon');
  $this->addFieldMapping('field_location:geo_type')->defaultValue('point');
  $this->addFieldMapping('field_location:lat', 'Latitude')
         ->xpath('Latitude');
  $this->addFieldMapping('field_location:lon', 'Longitude')
         ->xpath('Longitude');
philipz’s picture

I really can't make this work. I've tried all combinations listed here and #5 looks best but still nothing.
Has anyone a suggestion on how to debug this one?

Using Geofield 7.x-2.1, Migrate Extras 7.x-2.5+4-dev.

philipz’s picture

I can't see any subfield named :input_format. Maybe something changed now?

Sorry I thought the patch was no longer needed :) This really should be commited!

philipz’s picture

Priority: Normal » Major

I think this is a major bug, maybe not for whole Migrate Extras but definitely for Geofield.
If it will not be commited here then should we move this to Geofield issue queue?

mpdonadio’s picture

Does this patch work with multivalued geofields? When I try to use it, I end up with

trim() expects parameter 1 to be string, array given 
File .../docroot/sites/all/modules/geofield/geofield.module, line 347

which is because my prepareRow() is building up a lat and lon array to pass in for the subfield mapping.

glueckskind’s picture

The patch and #2 worked for me.

szeidler’s picture

Doesn't work for me using geofield 7.x-2.3, migrate 7.x-2.6 and migrate_extras 7.x-2.0-dev.

I got it working fine with the patch #17 from the geofield issue list: https://www.drupal.org/node/1411836#comment-9180687

milos.kroulik’s picture

I also managed to make it using the patch mentioned in #11

Summit’s picture

Hi,
Shouldn't Geofield Migrate be moved out of Migrate Extra because of https://www.drupal.org/node/1411836#comment-9180687?
greetings, Martijn

DuaelFr’s picture

I can confirm the patch works.
Until the Geofield module has its own migrate support, we should keep it in migrate_extras and commit this fix.
Thanks for reporting and fixing it.

ZeiP’s picture

The patch seemed to be working, although I decided to instead use the patch for Geofield instead. Perhaps this could be committed to the VCS as it is RTBC?