I had a dataset in OpenRefine that included a column of geoJSON objects as strings. Each geoJSON object represented a public park. I wanted to import the collection of parks to Wikidata, so I needed to convert the geoJSON polygon data into a central "point" that could be put into the P625 coordinate location
field.
NB: your geoJSON should have coordinates already in the WGS84 coordinate system (this is the standard for geoJSON).
To use this in OpenRefine:
- Click the down-arrow at the top of your raw geoJSON column.
- Select
Edit Column
->Add column based on this column...
- Choose a name for your new column.
- Change the
Expression language
dropdown toPython / Jython
. - Paste in the code from
script.py
- You should see pairs of latitude/longitude in the preview.
- Click
OK
to create the new column.
If your object is a MultiPolygon
, the centroid from the polygon with the largest bounding box will be chosen. In this way, your resulting coordinate will always be inside one of the polygons.
(There's probably a better way to do this but this worked well).