Using Feeds 7.x-2.x-dev to import fielded Taxonomy terms, it throws the error on every row:

Cannot construct Point. x and y should be numeric

The only reference I found for this error happens when the latitude/longitude are empty: #1717388: Empty values in Lat/lng and Bounds widgets does not work

but they are present in my case

Recommended version of Feeds 7.x-2.0-alpha8 works fine

Sample Feeds log message (this is not sensitve PI it is from a public data source)

Cannot construct Point. x and y should be numeric
Original item
array(
  'name' => 'DeVry University-Arizona',
  'description' => '',
  'school_alias_data' => 'DeVry University-Mesa |DeVry University-Phoenix |DeVry University-Northeast Phoenix |DeVry University-Glendale',
  'school_url_data' => 'http://www.devry.edu',
  'school_state_data' => 'AZ',
  'school_city_data' => 'Phoenix',
  'school_zip_data' => '85021-2995',
  'school_address_data' => '2149 W Dunlap Ave',
  'school_county_data' => 'Maricopa County',
  'school_chief_data' => 'Craig Jacob',
  'school_chief_title_data' => 'Metro President',
  'school_phone_data' => '6028709222',
  'school_admin_url_data' => ' ',
  'school_aid_url_data' => ' ',
  'school_apply_url_data' => ' ',
  'school_latitude_data' => '33.566087',
  'school_longitude_data' => '-112.104445',
  'school_unitid_data' => '104531',
)
Entity
(object) array(
  'vid' => '2',
  'vocabulary_machine_name' => 'categories',
  'format' => 'plain_text',
  'feeds_item' => (object) array(
      'is_new' => TRUE,
      'entity_id' => 0,
      'entity_type' => 'taxonomy_term',
      'id' => 'taxonomy_schools_importer',
      'feed_nid' => '0',
      'imported' => 1392000001,
      'hash' => '21ddaa3d1418b7980e9212a20071dd88',
      'url' => '',
      'guid' => '104531',
    ),
  'name' => 'DeVry University-Arizona',
  'field_school_alias_data' => array(
    'und' => array(
      array(
        'value' => 'DeVry University-Mesa |DeVry University-Phoenix |DeVry University-Northeast Phoenix |DeVry University-Glendale',
        'format' => 'plain_text',
      ),
    ),
  ),
  'description' => '',
  'field_school_url_data' => array(
    'und' => array(
      array(
        'value' => 'http://www.devry.edu',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_address_data' => array(
    'und' => array(
      array(
        'value' => '2149 W Dunlap Ave',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_city_data' => array(
    'und' => array(
      array(
        'value' => 'Phoenix',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_state_data' => array(
    'und' => array(
      array(
        'value' => 'AZ',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_zip_data' => array(
    'und' => array(
      array(
        'value' => '85021-2995',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_county_data' => array(
    'und' => array(
      array(
        'value' => 'Maricopa County',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_chief_data' => array(
    'und' => array(
      array(
        'value' => 'Craig Jacob',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_chief_title_data' => array(
    'und' => array(
      array(
        'value' => 'Metro President',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_phone_data' => array(
    'und' => array(
      array(
        'value' => '6028709222',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_field_school_admin_url_dat' => array(
    'und' => array(
      array(
        'value' => ' ',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_field_school_aid_url_data' => array(
    'und' => array(
      array(
        'value' => ' ',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_field_school_apply_url_dat' => array(
    'und' => array(
      array(
        'value' => ' ',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_geofield_data' => array(
    'und' => array(
      array(
        'lat' => array(
          '33.566087',
        ),
        'lon' => array(
          '-112.104445',
        ),
      ),
    ),
  ),
  'guid' => NULL,
  'field_school_unitid_data' => array(
    'und' => array(
      array(
        'value' => '104531',
        'format' => 'plain_text',
      ),
    ),
  ),
)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

twistor’s picture

Title: Feeds Importer fails on Geofield mapping » Fix Feeds integration
Project: Feeds » Geofield

Looks like geofield was bitten by #2093651: Simplify target callbacks..

I will roll a patch for this in a moment.

twistor’s picture

Status: Active » Needs review
FileSize
4.21 KB

This is the shortest route to being forward and backward compatible.

It looks like this could use some more validation, but that's probably out of scope for this issue.

@decibel.places, I didn't test the patch, if you could be so kind.

decibel.places’s picture

although Feeds 7.x-2.0-alpha8 works better (imported hundreds of rows) still getting errors

I'll test the patch tomorrow

10 00:45:01	 Cannot construct Point. x and y should be numeric
Original item
array(
  'name' => 'University of San Francisco',
  'description' => '',
  'school_alias_data' => ' ',
  'school_url_data' => 'http://www.usfca.edu/',
  'school_state_data' => 'CA',
  'school_city_data' => 'San Francisco',
  'school_zip_data' => '94117-1080',
  'school_address_data' => '2130 Fulton St',
  'school_county_data' => 'San Francisco County',
  'school_chief_data' => 'Stephen A Privett',
  'school_chief_title_data' => ' S.J.',
  'school_phone_data' => 'President',
  'school_admin_url_data' => '4154225555',
  'school_aid_url_data' => 'http://www.usfca.edu/admission/',
  'school_apply_url_data' => 'http://www.usfca.edu/financialaid/apply/',
  'school_latitude_data' => 'http://www.usfca.edu/applyusf/',
  'school_longitude_data' => '37.775564',
  'school_unitid_data' => '-122.450977',
)
Entity
(object) array(
  'vid' => '2',
  'vocabulary_machine_name' => 'categories',
  'format' => 'plain_text',
  'feeds_item' => (object) array(
      'is_new' => TRUE,
      'entity_id' => 0,
      'entity_type' => 'taxonomy_term',
      'id' => 'taxonomy_schools_importer',
      'feed_nid' => '0',
      'imported' => 1392011101,
      'hash' => 'f1ed642d6bc5612d82e9594a0cc2b3ae',
      'url' => '',
      'guid' => '-122.450977',
    ),
  'name' => 'University of San Francisco',
  'field_school_alias_data' => array(
    'und' => array(
      array(
        'value' => ' ',
        'format' => 'plain_text',
      ),
    ),
  ),
  'description' => '',
  'field_school_url_data' => array(
    'und' => array(
      array(
        'value' => 'http://www.usfca.edu/',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_address_data' => array(
    'und' => array(
      array(
        'value' => '2130 Fulton St',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_city_data' => array(
    'und' => array(
      array(
        'value' => 'San Francisco',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_state_data' => array(
    'und' => array(
      array(
        'value' => 'CA',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_zip_data' => array(
    'und' => array(
      array(
        'value' => '94117-1080',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_county_data' => array(
    'und' => array(
      array(
        'value' => 'San Francisco County',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_chief_data' => array(
    'und' => array(
      array(
        'value' => 'Stephen A Privett',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_chief_title_data' => array(
    'und' => array(
      array(
        'value' => ' S.J.',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_phone_data' => array(
    'und' => array(
      array(
        'value' => 'President',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_field_school_admin_url_dat' => array(
    'und' => array(
      array(
        'value' => '4154225555',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_field_school_aid_url_data' => array(
    'und' => array(
      array(
        'value' => 'http://www.usfca.edu/admission/',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_field_school_apply_url_dat' => array(
    'und' => array(
      array(
        'value' => 'http://www.usfca.edu/financialaid/apply/',
        'format' => 'plain_text',
      ),
    ),
  ),
  'field_school_geofield_data' => array(
    'und' => array(
      array(
        'lat' => 'http://www.usfca.edu/applyusf/',
        'lon' => '37.775564',
      ),
    ),
  ),
  'field_school_unitid_data' => array(
    'und' => array(
      array(
        'value' => '-122.450977',
        'format' => 'plain_text',
      ),
    ),
  ),
)
Yorgg’s picture

I had to update geophp to the dev.

Sinovchi’s picture

Patch didn't help when I use Feeds 7.x-2.0-alpha8 or Feeds 7.x-2.x-dev. Updating geophp to the dev also didn't help.
Currently using Feeds 7.x-2.0-alpha7+29-dev (2013-Jan-25) and latest dev of Geofield without any error.

P.S. When I use Feeds 7.x-2.0-alpha8 with attached latest patch I had no errors but it didn't import x,y, coordinates too.

olofbokedal’s picture

Changed the path so that it respects any previous values that has been set.

This works for me, tested using latitude and longitude import.

dobe’s picture

I am not sure if it has to do with this patch or something else. When updating a geofield's lat lon, It does not update it keeps the field as it was. Even though I get no errors and it states that the entity was updated.

When I dpm the $entity within geofield_set_target_simple($source, $entity, $target, $values) it does contain the values it is suppose to be updating to.

** Update ** It was updating nodes correctly. But since I was using another Importer it created new items and they were being updating so no issues from my end on the patch

-Jesse

bigssam’s picture

FileSize
464 bytes

the x, y values are empty because of mallformed values expected (numerci instead of array) by the constructor of Point class.
To fix that issue i use the attached patch il works for me.

diff --git a/geofield.module b/geofield.module
index d025e2e..8d22603 100644
--- a/geofield.module
+++ b/geofield.module
@@ -477,7 +477,7 @@
       }
       // Special case, raw input (Services/Feeds) that only specifies lat/lon.
       elseif (!empty($raw_data['lat']) && !empty($raw_data['lon'])) {
-        $geometry = new Point($raw_data['lon'], $raw_data['lat']);
+        $geometry = new Point($raw_data['lon'][0], $raw_data['lat'][0]);
       }
     }
   }

Issam.

bigssam’s picture

bigssam’s picture

the x, y values are empty because of mallformed values expected (numerci instead of array) by the constructor of Point class.
To fix that issue i use the attached patch il works for me.

diff --git a/geofield.module b/geofield.module
index d025e2e..8d22603 100644
--- a/geofield.module
+++ b/geofield.module
@@ -477,7 +477,7 @@
       }
       // Special case, raw input (Services/Feeds) that only specifies lat/lon.
       elseif (!empty($raw_data['lat']) && !empty($raw_data['lon'])) {
-        $geometry = new Point($raw_data['lon'], $raw_data['lat']);
+        $geometry = new Point($raw_data['lon'][0], $raw_data['lat'][0]);
       }
     }
   }

Issam.

soraver’s picture

The patch in #6 works for me, thanks.

1mundus’s picture

#10 works very well, it was an easy fix. Thank you!

Exploratus’s picture

I had this problem when updating to latest dev version of feeds #10 did not work for me, but #6 did. Thanks!

pal4life’s picture

Hi,
I applied the patch in both number 10 and number 6, the issue still persists, its almost driven me to tear my hairs.
I can see the correct values being parsed through and it shows the field has been updated but nothing shows in the point coordinate. Not sure why this is happening?

Also if any once can point to the place where I can debug the exact update query to the database for feeds, I can check that spot what update query is being passed through?

Thanks.

basvredeling’s picture

To properly import wkt value the feed importer target should be set to WKT and patch #6 should be changed to the patch below (wkt is actually imported in a array key called 'geom', not 'wkt')...

joelstein’s picture

The patch in #6 worked for me, with latest Feeds dev. Thanks!

rjl’s picture

WTK imports are not woking. If I understand basvredeling's patch, it attempts to convert the WTK to an array of values, but that won't work with a Polygon, where the WKT is "Polygon((1 1, 2 2, 3 3, etc))"

I got it to work properly by adding another elseif statement in the same code section where bigssam's patch applies (just before his elseif statement).


elseif (!empty($raw_data['wkt'])) {
$geometry = geoPHP::load($raw_data['wkt']);
}

But not sure if this is the right place to fix it, or if function geofield_set_target_wkt($source, $entity, $target, $value) should be re-worked?

basvredeling’s picture

Clarification of my patch in #15
most important aspects are:

  • patch includes previous improvements from #6 / #10 and some minor code style improvements
  • target geofield mapping resides in a key called 'geom', NOT 'wkt'
  • I'm not converting to an array of values, 'geom' accepts a string. It should accept LINESTRING(1 1, 2 2, 3 3) as well as POLYGON(1 1, 2 2, 3 3)
  • I'm not using WKT conversion from GeoPHP lib, but I do like that approach
rjl’s picture

basvredeling, sorry, I am looking at your patch more closely and I was wrong in thinking it was converting to array. I haven't tried your patch, but it looks like it should work fine.

It would be nice if there were more of a sense of what the "$raw_data" variable should be or is intended to be. For example: Is the 'geom' key OK to use for WKT? Is function geofield_set_target_wkt incorrect in assigning a value to a 'wkt' key? Is the 'wkt' key allowed?

basvredeling’s picture

$raw_data = the unprocessed value from the feeds mapped source, or the unprocessed value stored in the geofield (I believe, the variable name is used ambiguously in geofield.module)

the geofield value, when stored as an array simply doesn't have a 'wkt' key, it does have a 'geom' key, and that is where the wkt value should be stored. so the 'wkt' key is not allowed.
a clear example can be found in code in geofield.formatters.inc lines 265-273

 case 'geofield_wkt':
      geophp_load();
      foreach ($items as $delta => $item) {
        $geometry = geoPHP::load($item['geom']);
        $wkt = $geometry->out('wkt');
        $microdata = _geofield_item_microdata_propertyvalue($entity, $instance, $item);
        $element[$delta] = array('#markup' => $wkt . $microdata);
      }
      return $element;
rjl’s picture

basvredeling, I had a chance finally to apply your patch at #15. At first it didn't work. Looks like the the single quotes used around the 'geom' key came in funny. I changed them to the other style of single quotes used throughout the patch and then it worked fine.

The funny quotes are on line 86 (the 3rd line shown here).

+  $geofield_values = array();
+  foreach ($values as $wkt) {
+    $field = array(‘geom’ => $wkt);
     $geofield_values[] = geofield_compute_values($field, 'wkt');
   }

For my purposes, uploading CSV files with a WKT polygon field, the patch works fine (given the quote fix). Thank you!

robertwb’s picture

The patch in #15 is right on, but I think that it may not actually be made against the 7.x-2.x-dev branch (or perhaps the branch was changed and this patch was not included)? I get an "Unreversed patch detected!" error and then it fails to apply. Also, as noted by @rjl the quotes come through funny. I have re-applied the code fix outlined in your original to the function geofield_set_target_wkt(), with quotes that don't cause troubles.

The attached patch successfully enabled me to use Feeds Importer to take WKT from an import file and stores it in a field that is stored using the PostGIS backend plugin. This is now ready for further testing if anyone can do so.

robertwb’s picture

Priority: Normal » Critical

Setting priority to Critical: Critical to establishing a system of regularly updated/synchronized geospatial data sets in Drupal. Feeds importer is a great way to do this. Moreover, this bug broke something that once worked.

Brandonian’s picture

Status: Needs review » Fixed

Thanks for the patch, @robertwb! Committed to 7.x-2.x

http://drupalcode.org/project/geofield.git/commit/5cda7f7

twistor’s picture

This doesn't address the fact that geofield_set_target_simple() accepts a single value. That will never be the case in later versions of Feeds.

Brandonian’s picture

Good to know, @twistor. Any tips on how to address that?

twistor’s picture

The first part of #2, #6, and #15 have the changes that should work for geofield_set_target_simple().

  • Brandonian committed 400ac26 on 7.x-2.x
    #2192421 - Futureproofing feeds integration
    
Brandonian’s picture

Thank you for the guidance, @twistor. I manually applied the patch in 15 to handle multiple values from Feeds.

http://cgit.drupalcode.org/geofield/commit/?id=400ac26

robertwb’s picture

Thanks @Brandonian for pushing this forward and thanks @Twistor for nailing down the multiple values detail.

Status: Fixed » Closed (fixed)

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