I am current migrating lat/lng values in separate fields as so..

$this->addFieldMapping('field_prop_lat', 'LAT');
$this->addFieldMapping('field_prop_lng', 'LNG');

but now need a geofield which contains both lat and lng values (in order for search_api_location module to work). is there any way to map geofields?

Comments

mikeryan’s picture

Project: Migrate » Migrate Extras
Version: 7.x-2.3-rc1 » 7.x-2.x-dev
Component: Code » Geofield
Assigned: Unassigned » mikeryan
Status: Active » Fixed

The Migrate module itself does not have support for contrib modules - that goes, ideally, into the contrib module itself, or if that's not practical into the Migrate Extras module. As it happens, Migrate Extras does have support for geofield - install and enable it, and see geofield.inc for help on mapping.

farse’s picture

thanks a lot for that. i have been having a play at it and this is what my old code looked like with separate fields

$this->source = new MigrateSourceSQL($query, array(), $count_query);

// Set up our destination - nodes of type property
$this->destination = new MigrateDestinationNode('property');

$this->addFieldMapping('field_prop_lat', 'LAT'); 
    $this->addFieldMapping('field_prop_lng', 'LNG'); 

now my new field is called field_data_field_latlng and this is what I have now:

$this->source = new MigrateSourceSQL($query, array(), $count_query);

// Set up our destination - nodes of type property
$this->destination = new MigrateDestinationNode('property');

     $geo_arguments = array(
   'lat' => array('LAT' => 'LAT'),
   'lon' => array('LAT' => 'LAT'),
   );
   
   // The geometry type should be passed in as the primary value.
    $this->addFieldMapping('field_data_field_latlng', '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, 'LAT');
   $this->addFieldMapping(NULL, 'LAT');

this doesn't seem to work and i'm a bit confused by the $geo_arguments as

$geo_arguments = array(
     'lat' => array('source_field' => 'source_field_latidute'),
     'lon' => array('source_field' => 'source_field_longitude'),
    );

where I'm not sure if in my case 'source_field' is the same as 'source_field_latitude' as my LAT value is just a column from the whole table i'm migrating from. i tried also,

 $geo_arguments = array(
   'lat' => array('source_table' => 'LAT'),
   'lon' => array('source_table' => 'LAT'),
   );

but i don't think that works either. i'm sure i'm missing something here?

thanks.

farse’s picture

Status: Fixed » Active
mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

The last one there is almost right, but it's 'source_field', not 'source_table'. And, the second one should be 'LNG', not 'LAT', correct?

farse’s picture

oh god ya, how embarrasing, so should it be:


$geo_arguments = array(
   'lat' => array('LAT' => 'LAT'),
   'lon' => array('LNG' => 'LNG'),
   );

since my source_field is the same as source_field_lat/lng?

did this and no apparent errors seem to be showing (under mapping tab):

field_latlng Point OK
LAT OK
LNG OK

but when i update the migration, nothing seems to migrate to the geofield... (after indexing and clearing caches)

farse’s picture

Status: Postponed (maintainer needs more info) » Active
mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)
$geo_arguments = array(
   'lat' => array('source_field' => 'LAT'),
   'lon' => array('source_field' => 'LNG'),
   );
mikeryan’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.