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.
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