[gdal-dev] Simple schema support for GeoJSON

Jukka Rahkonen jukka.rahkonen at mmmtike.fi
Fri Nov 21 04:55:16 PST 2014


I wonder if GDAL could have some simple and relatively user friendly way for
defining a schema for GeoJSON data. The GeoJSON driver seems to guess the
data types of attributes with some undocumented way but users could have
better knowledge about the desired schema.

I know I can control the data type by using OGR SQL and CAST as in
ogrinfo -sql "select cast(EMPLOYED as float) from OGRGeojson" states.json -so

However, perhaps GeoJSON is enough popular for deserving an easier way for
writing a schema. First I thought that it would be enough to copy the "csvt"
text file mechanism from the GDAL CSV driver
http://www.gdal.org/drv_csv.html. However, the csvt file is a plain list of
types which will be applied to the attributes in the same order than they
appear in the text file 

For GeoJSON it would feel more user friendly to include the attribute names
in the list somehow like

This would make it easier for users to write a valid "jsont" file. A list
with attribute names could perhaps also help GDAL as well because the
features in GeoJSON file do not necessarily have same attributes.

As an example this is the right schema for a WFS feature type which is
captured from

name="the_geom" type="gml:MultiPolygonPropertyType"/> 
name="STATE_NAME" type="xsd:string"/> 
name="STATE_FIPS" type="xsd:string"/> 
name="SUB_REGION" type="xsd:string"/> 
name="STATE_ABBR" type="xsd:string"/> 
name="LAND_KM" type="xsd:double"/> 
name="WATER_KM" type="xsd:double"/> 
name="PERSONS" type="xsd:double"/> 
name="FAMILIES" type="xsd:double"/> 
name="HOUSHOLD" type="xsd:double"/> 
name="MALE" type="xsd:double"/> 
name="FEMALE" type="xsd:double"/> 
name="WORKERS" type="xsd:double"/> 
name="DRVALONE" type="xsd:double"/> 
name="CARPOOL" type="xsd:double"/> 
name="PUBTRANS" type="xsd:double"/> 
name="EMPLOYED" type="xsd:double"/> 
name="UNEMPLOY" type="xsd:double"/> 
name="SERVICE" type="xsd:double"/> 
name="MANUAL" type="xsd:double"/> 
name="P_MALE" type="xsd:double"/> 
name="P_FEMALE" type="xsd:double"/> 
name="SAMP_POP" type="xsd:double"/> 

This is what GDAL is guessing:
STATE_NAME: String (0.0)
STATE_FIPS: String (0.0)
SUB_REGION: String (0.0)
STATE_ABBR: String (0.0)
LAND_KM: Real (0.0)
WATER_KM: Real (0.0)
PERSONS: Real (0.0)
FAMILIES: Integer (0.0)
HOUSHOLD: Real (0.0)
MALE: Real (0.0)
FEMALE: Real (0.0)
WORKERS: Real (0.0)
DRVALONE: Integer (0.0)
CARPOOL: Integer (0.0)
PUBTRANS: Integer (0.0)
EMPLOYED: Real (0.0)
UNEMPLOY: Integer (0.0)
SERVICE: Integer (0.0)
MANUAL: Integer (0.0)
P_MALE: Real (0.0)
P_FEMALE: Real (0.0)
SAMP_POP: Integer (0.0)
bbox: RealList (0.0)

-Jukka Rahkonen-

More information about the gdal-dev mailing list