I can not understand how to use migrate_extras and for example how to use geofield migrate extra support.

I have create a Migration class that work. In my "source" I have 2 "fields" called latitudine and longitudine. I have follow the instruction that I have found in geofiled.inc:

$geo_arguments = array(
  'lat' => array('source_field' => 'latitudine'),
  'lon' => array('source_field' => 'longitudine'),
);
// The geometry type should be passed in as the primary value.
$this->addFieldMapping('field_coordinate', 'Point')->arguments($geo_arguments);
// Since the excerpt is mapped via an argument, add a null mapping so it's
// not flagged as unmapped.
$this->addFieldMapping(NULL, 'latitudine');
$this->addFieldMapping(NULL, 'longitudine');

But my "test node" is created (via migrate) without "geofileld" field (field_coordinate). But if I comment the lines above and insert this function:

public function prepare($node, stdClass $current_row) {
  $node->field_coordinate = array(LANGUAGE_NONE => array(0 => array(
    'geom' => 'POINT ('.$current_row->longitudine." ".$current_row->latitudine.')',
    'geo_type' => 'point',
    'lat' => $current_row->latitudine,
             'lon' => $current_row->longitudine,
             'left' => $current_row->longitudine,
             'top' => $current_row->latitudine,
             'right' =>$current_row->longitudine,
            'bottom' => $current_row->latitudine,
   )));
}

"geofield field" is "created".

Where is my error?

  • i dont see any error in either approach ... interesting. – tenken Apr 29 '13 at 4:24

Using arguments is deprecated.

Now you can migrate geofields without migrate_extras.

$this->addFieldMapping('field_location', 'point');

And in your prepare row

public function prepareRow($row) {
 $row->point = 'POINT (' . $row->longitude . ' ' . $row->latitude. ')';
}
  • 2
    If you still need migrate_extras and want to use this method, you'll need to disable MigrateGeoFieldHandler. Go to admin/content/migrate/configure and scroll down to the field handlers section to disable it. – Ivan Zugec May 27 '14 at 11:17

Ok, I have found the solution.

From geofield.inc: "Primary value passed to this field must be the geometry type of the geofield: Point, LineString, Polygon" But this need to be passed in a different way:

  • in the "prepareRow($row)" I need to set "Point" like a current row field:

    public function prepareRow($row) {
    [...] 
       $row->geo_type = 'point';
    [...]
    }
    
  • and in the __construct() function the right line is:

    $this->addFieldMapping('field_coordinate', 'geo_type')->arguments($arguments);
    

Now it works.

M.

  • good one tracking that down. – tenken Apr 29 '13 at 13:19

Use of arguments is now deprecated. You will get this error:

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

To migrate geofield (2.0) using migrate_extras apply the patch in https://drupal.org/node/1997316.

Code using subfield notation:

$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', 'latitudine')
   ->xpath('Latitude');
$this->addFieldMapping('field_location:lon', 'longitudine')
   ->xpath('Longitude');

Inside prepareRow():

public function prepareRow($row) {
  ...
  $row->geo_type = 'point';
  $row->input_format = 'lat/lon';
  ...
}

Got it to work without migrate_extras:

in your prepareRow() use:

 $row->point = 'POINT (' . $row->longitude . ' ' . $row->latitude. ')';

and in the construct:

$this->addFieldMapping('field_location', 'point');
$this->addFieldMapping('field_location:geom', 'point');
$this->addFieldMapping('field_location:geo_type')->defaultValue('point');

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.