Skip to content

Instantly share code, notes, and snippets.

@aborruso
Last active March 23, 2024 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aborruso/e698d73224feaa39974c0c7bbf541236 to your computer and use it in GitHub Desktop.
Save aborruso/e698d73224feaa39974c0c7bbf541236 to your computer and use it in GitHub Desktop.

Intro

Simon Willison as usual wrote a very interesting post:
https://simonwillison.net/2024/Mar/22/claude-and-chatgpt-case-study/

He had a linear shapefile of the Adirondack Park in the USA, composed of multiple lines. His goal was to transform these lines into a polygonal GeoJSON. The challenge was to create a continuous polygon that represented the park's boundary, as defined by the lines.

The article discusses the author's use of AI tools, Claude and ChatGPT, for a quick sidequest involving converting a shapefile to GeoJSON.

Here the direct and very simple ogr way to do it, simply using his beloved sqlite and its spatial extension.

The ogr way to do it

ogr2ogr -f "GeoJSON" output.geojson AdirondackParkBoundary2017.shp -dialect sqlite -sql "
SELECT ST_Polygonize(geometry) AS geom FROM AdirondackParkBoundary2017
" -lco RFC7946=YES

ogr2ogr: https://gdal.org/programs/ogr2ogr.html

The spatialite SQL functions reference list:
https://www.gaia-gis.it/gaia-sins/spatialite-sql-5.1.0.html

Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment