gdal icon indicating copy to clipboard operation
gdal copied to clipboard

orginfo: GeoJSON: FID and Geometry Column not printed

Open jidanni opened this issue 1 year ago • 3 comments

Everything looks good,

ogr2ogr n.gpkg n.geojson
ogrinfo -al n.geojson|grep 'POINT '|head -n 2
  POINT (-88.3150833689999 40.1860313140002)
  POINT (-88.0855250979999 40.0112723820001)
ogrinfo -al n.gpkg   |grep 'POINT '|head -n 2
  POINT (-88.3150833689999 40.1860313140002)
  POINT (-88.0855250979999 40.0112723820001)

until we do

ogrinfo -so n.geojson BLM_ES_PLSSPoint|grep Column
ogrinfo -so n.gpkg    BLM_ES_PLSSPoint|grep Column
FID Column = fid
Geometry Column = geom

For *.geojson, orginfo can print the contents of Geometry Column just fine, but neglects telling the user its name.

It must know the names of the FID and Geometry columns, else it wouldn't be able to access them itself. It simply neglects reporting those names to the user.

GDAL 3.8.5

jidanni avatar May 16 '24 08:05 jidanni

There are datasources which do not have named geometry columns and GeoJSON is one of those. By the definition https://www.rfc-editor.org/rfc/rfc7946#section-3.1 the geometry is always stored into a Geometry Object. The same thing with a fixed way to store the geometry applies to shapefiles, MapInfo files etc.

The name of the geometry column, if it exists, is fetched with GetGeometryColumn() https://gdal.org/doxygen/classOGRLayer.html#af68036c23622c954ce3a91861f22b724

This method returns the name of the underlying database column being used as the geometry column, or "" if not supported.

Another piece of documentation about this is at https://gdal.org/user/ogr_sql_dialect.html#geometry-field.

If the method returns an empty string then a special name "ogr_geometry" must be used.

GeoJSON has also a fixed place for the id

If a Feature has a commonly used identifier, that identifier
SHOULD be included as a member of the Feature object with the name
"id", and the value of this member is either a JSON string or number.

The FID column is not printed because GeoJSON does not have a named FID column. Again the same applies to shapefiles and friends.

jratike80 avatar May 16 '24 10:05 jratike80

I see. It seems then for GeoJSON, etc., ogrinfo could say

Geometry Column = _ogr_geometry_

jidanni avatar May 16 '24 14:05 jidanni

I see. It seems then for GeoJSON, etc., ogrinfo could say

not really, because GetGeometryColumn() reports an empty string.

This is admitedly an area where things are a bit confusing. Perhaps this is mostly a documentation issue, and adding hints in the ogrinfo documentation page about that, and linking to https://gdal.org/user/ogr_sql_dialect.html#geometry-field or https://gdal.org/user/sql_sqlite_dialect.html#geometry-field

rouault avatar May 16 '24 14:05 rouault