[gdal-dev] ogr.VectorTranslate to json appears to be incomplete

Even Rouault even.rouault at spatialys.com
Fri May 26 06:28:44 PDT 2023


Michael,

I've also just tried with 3.7.0 from conda-forge and this works fine for me:

I've just slightly modified your script to output more info:

from osgeo import ogr, gdal

ds = gdal.OpenEx('{ "type": "Polygon", "coordinates": [ [ [ 
179.828821134787177, 66.686572724877635 ], [ -179.718786846664386, 
66.695039153881993 ], [ -179.699204739767083, 66.515803857102057 ], [ 
179.851649370943306, 66.507409512673448 ], [ 179.828821134787177, 
66.686572724877635 ] ] ] }')
gdal.VectorTranslate("/vsimem/out.json", ds, format="GeoJSON", 
layerCreationOptions=["RFC7946=YES", "WRAPDATELINE=YES", "WRITE_BBOX=YES"])
f = gdal.VSIFOpenL("/vsimem/out.json", "rb")
content = gdal.VSIFReadL(1, 10000, f).decode("UTF-8")
gdal.VSIFCloseL(f)
gdal.Unlink("/vsimem/out.json")
print(content)
print(len(content))

newds = ogr.Open(content)
lyr = newds.GetLayer(0)
f = lyr.GetNextFeature()
f.DumpReadable()

and it outputs:

{
"type": "FeatureCollection",
"bbox": [ 179.8288211, 66.5074095, -179.6992047, 66.6950392 ],
"features": [
{ "type": "Feature", "properties": { }, "bbox": [ 179.8288211, 
66.5074095, -179.6992047, 66.6950392 ], "geometry": { "type": 
"MultiPolygon", "coordinates": [ [ [ [ 180.0, 66.6897763 ], [ 
179.8288211, 66.6865727 ], [ 179.8516494, 66.5074095 ], [ 180.0, 
66.5101821 ], [ 180.0, 66.6897763 ] ] ], [ [ [ -179.7187868, 66.6950392 
], [ -180.0, 66.6897763 ], [ -180.0, 66.5101821 ], [ -179.6992047, 
66.5158039 ], [ -179.7187868, 66.6950392 ] ] ] ] } }
]
}

625
OGRFeature(OGRGeoJSON):0
   MULTIPOLYGON (((180.0 66.6897763,179.8288211 66.6865727,179.8516494 
66.5074095,180.0 66.5101821,180.0 66.6897763)),((-179.7187868 
66.6950392,-180 66.6897763,-180 66.5101821,-179.6992047 
66.5158039,-179.7187868 66.6950392)))

Even


Le 26/05/2023 à 15:12, Michael Smith a écrit :
> I assume I am doing something incorrect here but I am taking an incoming geojson feature and attempting to split it on the dateline:
>
> Using gdal 3.7.0 from conda-forge
>
> ds = gdal.OpenEx('{ "type": "Polygon", "coordinates": [ [ [ 179.828821134787177, 66.686572724877635 ], [ -179.718786846664386, 66.695039153881993 ], [ -179.699204739767083, 66.515803857102057 ], [ 179.851649370943306, 66.507409512673448 ], [ 179.828821134787177, 66.686572724877635 ] ] ] }')
> gdal.VectorTranslate("/vsimem/out.json", ds, format="GeoJSON", layerCreationOptions=["RFC7946=YES", "WRAPDATELINE=YES", "WRITE_BBOX=YES"])
> f = gdal.VSIFOpenL("/vsimem/out.json", "rb")
> content = gdal.VSIFReadL(1, 10000, f).decode("UTF-8")
> gdal.VSIFCloseL(f)
> gdal.Unlink("/vsimem/out.json")
>
> If I just do:
>
> newds = ogr.Open(content)
>
> I get RuntimeError: Failed to read GeoJSON data
> It appears to be missing the closing “]}”.
>
> If I do:
> newds = ogr.Open(content+"]}")
>
> Then it works fine.
>
>
> -- 
> Michael Smith
> Remote Sensing/GIS Center
> US Army Corps of Engineers
>
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev

-- 
http://www.spatialys.com
My software is free, but my time generally not.



More information about the gdal-dev mailing list