[gdal-dev] AsGeoJSON with SQLite dialect returns an empty string
Rahkonen Jukka (MML)
jukka.rahkonen at maanmittauslaitos.fi
Thu Mar 28 08:01:20 PDT 2019
Hi,
I noticed this question https://gis.stackexchange.com/questions/316776/ogr2ogr-fails-with-no-such-table and tried to study that odd shapefile by repeating the test with GDAL 2.4.0 from OSGeo4W and there happens something with ST_AsGeoJSON that I do not understand.
This command indeed returns an empty result
ogrinfo -dialect sqlite -sql "select AsGeoJSON(geom) from \"geo_export_98941210-c995-4502-8ebb-93a09f29d615\" limit 1" fix.gpkg
INFO: Open of `fix.gpkg'
using driver `GPKG' successful.
Layer name: SELECT
Geometry: None
Feature Count: 1
Layer SRS WKT:
(unknown)
AsGeoJSON(geom): String (0.0)
OGRFeature(SELECT):0
AsGeoJSON(geom) (String) = (null)
Other Spatialite functions (AsGML, AsKML, AsBinary, AsSVG) do return the geometry, it is only AsGeoJSON that gives an empty result.
However, with a trick I could get also GeoJSON out:
ogrinfo -dialect sqlite -sql "select AsGeoJSON(st_geomfromtext(st_astext(geom))) from \"geo_export_98941210-c995-4502-8ebb-93a09f29d615\" limit 1" fix.gpkg
INFO: Open of `fix.gpkg'
using driver `GPKG' successful.
Layer name: SELECT
Geometry: None
Feature Count: 1
Layer SRS WKT:
(unknown)
AsGeoJSON(st_geomfromtext(st_astext(geom))): String (0.0)
OGRFeature(SELECT):0
AsGeoJSON(st_geomfromtext(st_astext(geom))) (String) = {"type":"Polygon","coordinates":[[[-87.666731,41.707976],[-87.66686799999998,41.70797699999999],[-87.66686699999999,41.708063],[-87.666684,41.708064],[-87.666683,41.70799499999999],[-87.66673,41.70799499999999],[-87.666731,41.707976]]]}
I could only repeat the result by reading the data directly from geopackage, not by saving the feature taken from gpkg into shapefile or OpenJUMP JML format. I produced a minimal geopackage http://latuviitta.org/downloads/one_chicago.gpkg with only one feature for testing. The command to try is
ogrinfo -dialect sqlite -sql "select AsGeoJSON(geom) from \"geo_export_98941210-c995-4502-8ebb-93a09f29d615\"" one_chicago.gpkg
-Jukka Rahkonen-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20190328/639f6f74/attachment.html>
More information about the gdal-dev
mailing list