- 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 2:50pm 22 August 2023 - 🇮🇹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.