Unable to Import via Feeds

Created on 14 August 2023, over 1 year ago
Updated 23 August 2023, about 1 year ago

Problem/Motivation

I am trying to import locations from a JSON feed to an entity type with a Geofield. However, the 3 parameters (lat, long, geometry) when mapped using Feeds, and altered as required with Feeds Tamper, generate more than one Geofield location value, with Feeds reporting:

The content...failed to validate with the following errors:
location (location): location: this field cannot hold more than 1 values.

A similar problem was reported at #2952745-22: Feeds integration: add a mapping target for geofield and numerous issues relating to Feeds.

The problem can be resolved by setting the Geofield field to allow 'Unlimited' values, but this presents other UX problems with the site.

In particular, it's not clear what value should go in Geometry for single points.

Steps to reproduce

1. Have a content type with a single Geofield field, with only 1 value permitted.
2. Create a Feeds Type to handle our import, mapping the 3 parameters from our source:
- latitude
- longitude
- geometry

Lat and long are proivided by the Feeds source. I have tried the following options with the Geometry value (using Feeds Tamper):
- setting to `point`
- set to empty
- rewrite with tokens: POINT([latitude], [longitude])

Proposed resolution

Is this a documentation issue, or is there a bug? Does this issue belong in Geofield, or is it related to the many issues in Feeds relating to cardinality?

💬 Support request
Status

Closed: works as designed

Version

1.54

Component

Documentation

Created by

🇬🇧United Kingdom robcarr Perthshire, Scotland

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @robcarr
  • 🇬🇧United Kingdom robcarr Perthshire, Scotland

    After a bit of trial and error, I have successfully mapped lat/long from a JSON source into a content type with a single value Geofield.

    The following settings for the 3 values of the location (Geofield) for a single point address:

    • Map the values for latitude and longitude to Feeds 'Temporary targets' (so that tokens are generated)
    • Latitude - should be empty. I mapped a blank source to this value (as Feeds Tamper didn't seem to implement NULL effectively using a 'Set value or default value' tamper.
    • Longitude - should be empty (as above)
    • Geometry - use a Feeds Tamper rewrite with the previously generated tokens: POINT ([longitude] [latitude]) - note order of lat/long and a space (not a comma)

    If either of the lat/long values [in the Geofield] are anything other than NULL in the Feeds mapping, Feeds attempts to create a second instance of the location, hence the cardinality errors during the import. I don't understand why Geofield does this, nor why a location cannot be imported using just lat and long values (and ignoring the geometry value).

    It might be useful to refer to this in the documentation of the module. Alternatively, simplify mapping of Geofield for single point imports.

  • Status changed to Closed: works as designed about 1 year ago
  • 🇮🇹Italy itamair

    I tested something similar to your use case and all looks good to me, with a single value Geofield and the following json source:

    {
      "items": [
        {
          "name": "point1",
          "geometry": "POINT (-6.3205847 54.7342997)"
        },
        {
          "name": "point2",
          "geometry": "POINT (-7.3205847 53.7342997)"
        }
      ]
    }

    This comment of mine is still valid: https://www.drupal.org/project/geofield/issues/2952745#comment-14877262 Feeds integration: add a mapping target for geofield Closed: outdated

    if you are importing Geometries use just the geometry property in the mapping (and leave unset the Lat and Lon selects).

    So I generated the attached json file and imported it in feeds with the help of the drupal/feeds_ex module
    with the Mapping settings that you could see in the attached screenshot, with the following focus:
    - the "Context" set as: "$.items.*"
    - only geometry is being set (while Centroid Latitude and Centroid Longitude should be left unset)

    All really importing correctly. Two nodes in Drupal with those geofield values.
    Just remember that the geometry field allows both WKT (this use case) and geojson valid formats values.

    I am closing this as it works as designed ...

  • 🇬🇧United Kingdom robcarr Perthshire, Scotland

    @itamair - thanks for the reply - I hadn't appreciated that the fields within the Geofield could be just left blank: I've just tested it with the location>Geometry left to 'Select a source' and the multi-value issue during import is gone. Documentation (or the UI?) could be a little clearer in that all 3 parameters do not need to be selected, but hopefully this post will act a reference for those that solve the problem by Googling.

    For reference, I had used feeds_ex module with the following JSON used:

    {
          "attributes" : {
            "OBJECTID" : 2, 
            "latitude" : 54.98569782, 
            "longitude" : -3.249683852, 
            "site" : "Car Park", 
          }
        }, 
    

    Mapping the lat and long values to the Centroid Lat/Long worked just fine.

    Thanks for your work on the module.

Production build 0.71.5 2024