OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.87k stars 2.54k forks source link

ogr2ogr: GeoJSON with mixed property types is converted to string #7336

Closed elpaso closed 1 year ago

elpaso commented 1 year ago

Input:

gh_51911_original.json

{
"type": "FeatureCollection",
"name": "gh_51911",
"features": [
{ "type": "Feature", "properties": { "prop0": 42 }, "geometry": { "type": "Point", "coordinates": [ 102.0, 0.5 ] } },
{ "type": "Feature", "properties": { "prop0": "astring" }, "geometry": { "type": "Point", "coordinates": [ 102.0, 0.5 ] } },
{ "type": "Feature", "properties": { "prop0": { "nested": 75 } }, "geometry": { "type": "Point", "coordinates": [ 102.0, 0.5 ] } }
]
}

ogrinfo output (partial)

prop0: String(JSON) (0.0)
OGRFeature(gh_51911):0
  prop0 (String(JSON)) = 42
  POINT (102.0 0.5)

OGRFeature(gh_51911):1
  prop0 (String(JSON)) = astring
  POINT (102.0 0.5)

OGRFeature(gh_51911):2
  prop0 (String(JSON)) = { "nested": 75 }
  POINT (102.0 0.5)

Command:

ogr2ogr --debug on -f GeoJSON gh_51911_translated.json gh_51911_original.json
GeoJSON: First pass: 100.00 %
GDAL: GDALOpen(gh_51911_original.json, this=0x563b09ceb480) succeeds as GeoJSON.
GDAL: QuietDelete(gh_51911_translated.json) invoking Delete()
GDAL: GDALDriver::Create(GeoJSON,gh_51911_translated.json,0,0,0,Unknown,(nil))
GDALVectorTranslate: Transferring layer NATIVE_DATA
GDALVectorTranslate: 3 features written in layer 'gh_51911'
GDAL: GDALClose(gh_51911_original.json, this=0x563b09ceb480)
GDAL: GDALClose(gh_51911/gh_51911_translated.json, this=0x563b09d228d0)
GDAL: In GDALDestroy - unloading GDAL shared library.

gh_51911_translated.json

{
"type": "FeatureCollection",
"name": "gh_51911",
"features": [
{ "type": "Feature", "properties": { "prop0": "42" }, "geometry": { "type": "Point", "coordinates": [ 102.0, 0.5 ] } },
{ "type": "Feature", "properties": { "prop0": "astring" }, "geometry": { "type": "Point", "coordinates": [ 102.0, 0.5 ] } },
{ "type": "Feature", "properties": { "prop0": { "nested": 75 } }, "geometry": { "type": "Point", "coordinates": [ 102.0, 0.5 ] } }
]
}
jratike80 commented 1 year ago

I have not bright idea about what you plan to do, but I suggest to add also numeric strings into your test data

{ "type": "Feature", "properties": { "prop0": "42" }, "geometry": { "type": "Point", "coordinates": [ 102.0, 0.5 ] } } and the common pitfall of leading zeroes { "type": "Feature", "properties": { "prop0": "0042" }, "geometry": { "type": "Point", "coordinates": [ 102.0, 0.5 ] } }