Hi, 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 ?

M.

Comments

Jan van Diepen’s picture

I initially came up with the same code fragment.
I got the following message.

geoPHP could not find an adapter of type (/var/www/.../geophp/geoPHP/geoPHP.inc:65)

Googling the message did not bring me anything.
I went through the issue queue some more and found #1852202: Unable to migrate geofield data and #1997316: geofield 7.x-2.0-dev migration.

Based on these issues I made the following code changes:

  1. I added two more fields to the columns.
        $columns = array(
          ...
          9 => array('geo_type', 'geo_type'),
          10 => array('input_format', 'input_format'),
        }
    
  2. I changed your code fragment to look like this.
        $geo_arguments = array(
          'lat' => array('source_field' => 'latitudine'),
          'lon' => array('source_field' => 'longitudine'),
          'geo_type' => array('source_field', 'geo_type'),
          'input_format' => array('source_field' => 'input_format'),
        );
        // The geometry type should be passed in as the primary value.
        $this->addFieldMapping('field_iati_geofield', 'geo_type')->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');
        $this->addFieldMapping(NULL, 'geo_type');
        $this->addFieldMapping(NULL, 'input_format');
    
  3. I added the function prepareRow().
      public function prepareRow($row) {
        $row->geo_type = 'point';
        $row->input_format = 'lat/lon';
      }
    
  4. I removed the function prepare().

This works for me.

DrCord’s picture

Title: How to use and for example GEOFILED » How to use and for example GEOFIELD
Issue summary: View changes