Parsing JSON geometry data from a csv file

I have csv files where one column contains a string with the geometry data in JSON format (similar to what is specified in the ESRI document).

Here is an example:

ID,SHAPE
123456,"{'rings' : [[[-97.06138,32.837], [-97.06133,32.836], [-97.06124,32.834], [-97.06127,32.832], [-97.06138,32.837]], [[-97.06326,32.759], [-97.06298,32.755], [-97.06153,32.749], [-97.06326,32.759]]], 'spatialReference' : {'wkid' : 4326}}"

Can you recommend a solution to read, parse and convert to sf object this type of csv files?
Thank you

In theory geojsonsf::geojson_sf() should do the trick, as it does accept GeoJSONs-as-strings for argument.

In practice I was not able to make it work with the example provided, as it claimed your GeoJSON is malformed.

Do give it a try, but it seems a lot will depend on your actual data (which it was not practical do share here).

@jlacko, thank you for your recommendation.

My understanding that this string is not a "pure" GeoJSON format, but rather a different JSON format.
After an extensive search, I think that this geometry format is an ESRI (ArcGIS) JSON, documented here

Unfortunately, so far I haven't found any existing package to parse this format.

this is kind of unexpected... for GeoJSON is pretty well described format, with all the proper MUST and SHALL and what not... RFC 7946 - The GeoJSON Format

but I guess that you have to deal with what you have - I feel your pain

Converting ArcGIS Server JSON to GeoJSON? - Geographic Information Systems Stack Exchange

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.