duckdb_spatial icon indicating copy to clipboard operation
duckdb_spatial copied to clipboard

st_read() error on a geojson API

Open ericemc3 opened this issue 9 months ago • 3 comments

load spatial ;
load httpfs;
FROM st_read('https://geo.api.gouv.fr/communes?codePostal=31140&geometry=contour&format=geojson');

GDAL Error (4): `https://geo.api.gouv.fr/communes?codePostal=31140&geometry=contour&format=geojson' not recognized as a supported file format.

But it works well on the duckdb wasm shell: https://tinyurl.com/2p4wuvad

And the API stream looks valid for that EU validator https://www.itb.ec.europa.eu/json/geojson/upload

ericemc3 avatar May 19 '25 13:05 ericemc3

It seems like using the GDAL /vsicurl/ filesystem works, as a work-around.

FROM st_read('/vsicurl/https://geo.api.gouv.fr/communes?codePostal=31140&geometry=contour&format=geojson');
----
┌───────────────────┬─────────┬───┬────────────┬──────────────────────┐
│        nom        │  code   │ … │ population │         geom         │
│      varchar      │ varchar │   │   int32    │       geometry       │
├───────────────────┼─────────┼───┼────────────┼──────────────────────┤
│ Aucamville        │ 31022   │ … │       9578 │ POLYGON ((1.41194 …  │
│ Fonbeauzard       │ 31186   │ … │       3086 │ POLYGON ((1.422825…  │
│ Launaguet         │ 31282   │ … │       9216 │ POLYGON ((1.461964…  │
│ Montberon         │ 31364   │ … │       3121 │ POLYGON ((1.476399…  │
│ Pechbonnieu       │ 31410   │ … │       4792 │ POLYGON ((1.461424…  │
│ Saint-Alban       │ 31467   │ … │       6447 │ POLYGON ((1.430731…  │
│ Saint-Loup-Cammas │ 31497   │ … │       2343 │ POLYGON ((1.459407…  │
├───────────────────┴─────────┴───┴────────────┴──────────────────────┤
│ 7 rows                                          9 columns (4 shown) │
└─────────────────────────────────────────────────────────────────────┘

I need to take another shot at implementing the DuckDB/GDAL filesystem adapter soon anyway as there has been a lot of changed duckdb-side, so I'll look why this doesn't work as well then.

Maxxen avatar May 19 '25 13:05 Maxxen

Thank you for the tip! And for looking after this, i appreciate

ericemc3 avatar May 19 '25 13:05 ericemc3

For the record, that other API call crashes DuckDB CLI (current dev 1.3):

load spatial ;
load httpfs;
FROM st_read('/vsicurl/https://geo.api.gouv.fr/communes?codeDepartement=31&geometry=contour&format=geojson');

though

load spatial ;
FROM st_read('https://geo.api.gouv.fr/communes?codeDepartement=09&geometry=contour&format=geojson');

is fine with the DuckDB shell (1.2)

ericemc3 avatar May 19 '25 13:05 ericemc3

This seems to be fixed now

Maxxen avatar Nov 19 '25 11:11 Maxxen

Thank you!

LOAD spatial ;
FROM st_read('https://geo.api.gouv.fr/communes?codePostal=31140&geometry=contour&format=geojson');

works indeed fine now, and without the need of LOAD HTTPFS;, which is really great.

This works also:

LOAD spatial ;
FROM st_read('https://geo.api.gouv.fr/communes?codeDepartement=32&geometry=contour&format=geojson');

But for the record, with /vsicurl/ it crashes DuckDB 1.4.2:

LOAD spatial ;
FROM st_read('/vsicurl/https://geo.api.gouv.fr/communes?codeDepartement=32&geometry=contour&format=geojson');

crash

ericemc3 avatar Nov 20 '25 04:11 ericemc3

This crashes 1.4.2 as well:

LOAD spatial ;
FROM st_read('https://geo.api.gouv.fr/communes?codeDepartement=91&geometry=contour&format=geojson');

though you can visualize the geojson here: https://gavinr.github.io/geojson-viewer/?url=https%3A%2F%2Fgeo.api.gouv.fr%2Fcommunes%3FcodeDepartement%3D91%26geometry%3Dcontour%26format%3Dgeojson

ericemc3 avatar Nov 23 '25 10:11 ericemc3

It seems to work for me? What OS are you on?

load spatial;
D load httpfs;
D LOAD spatial ;
D FROM st_read('https://geo.api.gouv.fr/communes?codeDepartement=91&geometry=contour&format=geojson');
┌──────────────────────┬─────────┬───┬────────────┬──────────────────────┐
│         nom          │  code   │ … │ population │         geom         │
│       varchar        │ varchar │   │   int32    │       geometry       │
├──────────────────────┼─────────┼───┼────────────┼──────────────────────┤
│ Abbéville-la-Rivière │ 91001   │ … │        331 │ POLYGON ((2.181551…  │
│ Angerville           │ 91016   │ … │       4416 │ POLYGON ((1.962079…  │
│ Angervilliers        │ 91017   │ … │       1720 │ POLYGON ((2.035741…  │
│ Arpajon              │ 91021   │ … │      11503 │ POLYGON ((2.241533…  │
│ Arrancourt           │ 91022   │ … │        119 │ POLYGON ((2.169184…  │
│ Athis-Mons           │ 91027   │ … │      36451 │ POLYGON ((2.400469…  │
│ Authon-la-Plaine     │ 91035   │ … │        371 │ POLYGON ((1.942874…  │
│ Auvernaux            │ 91037   │ … │        330 │ POLYGON ((2.474189…  │
│ Auvers-Saint-Georges │ 91038   │ … │       1250 │ POLYGON ((2.216929…  │
│ Avrainville          │ 91041   │ … │       1045 │ POLYGON ((2.258958…  │
│ Ballainvilliers      │ 91044   │ … │       4838 │ POLYGON ((2.276096…  │
│ Ballancourt-sur-Es…  │ 91045   │ … │       7795 │ POLYGON ((2.374376…  │
│ Baulne               │ 91047   │ … │       1468 │ POLYGON ((2.406243…  │
│ Bièvres              │ 91064   │ … │       4700 │ POLYGON ((2.204046…  │
│ Blandy               │ 91067   │ … │        115 │ POLYGON ((2.237996…  │
│ Boigneville          │ 91069   │ … │        376 │ POLYGON ((2.38531 …  │
│ Bois-Herpin          │ 91075   │ … │         83 │ POLYGON ((2.229762…  │
│ Boissy-la-Rivière    │ 91079   │ … │        533 │ POLYGON ((2.125321…  │
│ Boissy-le-Cutté      │ 91080   │ … │       1343 │ POLYGON ((2.281861…  │
│ Boissy-le-Sec        │ 91081   │ … │        693 │ POLYGON ((2.082595…  │
│     ·                │   ·     │ · │         ·  │          ·           │
│     ·                │   ·     │ · │         ·  │          ·           │
│     ·                │   ·     │ · │         ·  │          ·           │
│ Vauhallan            │ 91635   │ … │       1954 │ POLYGON ((2.19028 …  │
│ Vayres-sur-Essonne   │ 91639   │ … │        974 │ POLYGON ((2.362506…  │
│ Verrières-le-Buisson │ 91645   │ … │      14772 │ POLYGON ((2.274553…  │
│ Vert-le-Grand        │ 91648   │ … │       2348 │ POLYGON ((2.347519…  │
│ Vert-le-Petit        │ 91649   │ … │       2716 │ POLYGON ((2.357678…  │
│ Videlles             │ 91654   │ … │        584 │ POLYGON ((2.444259…  │
│ Vigneux-sur-Seine    │ 91657   │ … │      31233 │ POLYGON ((2.439719…  │
│ Villabé              │ 91659   │ … │       5654 │ POLYGON ((2.441309…  │
│ Villebon-sur-Yvette  │ 91661   │ … │      10353 │ POLYGON ((2.20476 …  │
│ Villeconin           │ 91662   │ … │        768 │ POLYGON ((2.122183…  │
│ La Ville-du-Bois     │ 91665   │ … │       8140 │ POLYGON ((2.277065…  │
│ Villejust            │ 91666   │ … │       2502 │ POLYGON ((2.241414…  │
│ Villemoisson-sur-O…  │ 91667   │ … │       7226 │ POLYGON ((2.318762…  │
│ Villeneuve-sur-Auv…  │ 91671   │ … │        595 │ POLYGON ((2.265317…  │
│ Villiers-le-Bâcle    │ 91679   │ … │       1040 │ POLYGON ((2.106251…  │
│ Villiers-sur-Orge    │ 91685   │ … │       4576 │ POLYGON ((2.299128…  │
│ Viry-Châtillon       │ 91687   │ … │      31112 │ POLYGON ((2.396189…  │
│ Wissous              │ 91689   │ … │       6924 │ POLYGON ((2.32487 …  │
│ Yerres               │ 91691   │ … │      28349 │ POLYGON ((2.465451…  │
│ Les Ulis             │ 91692   │ … │      25633 │ POLYGON ((2.204273…  │
├──────────────────────┴─────────┴───┴────────────┴──────────────────────┤
│ 194 rows (40 shown)                                9 columns (4 shown) │
└────────────────────────────────────────────────────────────────────────┘
D pragma version;
┌─────────────────┬────────────┬──────────┐
│ library_version │ source_id  │ codename │
│     varchar     │  varchar   │ varchar  │
├─────────────────┼────────────┼──────────┤
│ v1.4.2          │ 68d7555f68 │ Andium   │
└─────────────────┴────────────┴──────────┘

Maxxen avatar Nov 24 '25 08:11 Maxxen

Thanks, i am on Win11, using the CLI v 1.4.2

LOAD httpfs;
LOAD spatial ;
FROM st_read('https://geo.api.gouv.fr/communes?codeDepartement=91&geometry=contour&format=geojson');

ClI closes without warning. Same thing with DBeaver (Java DuckDB version) : DBeaver closes without warning.

ericemc3 avatar Nov 24 '25 09:11 ericemc3