[gdal-dev] Handle geojson bigger than 200MB
Francesco Bartoli
xbartolone at gmail.com
Sat Feb 29 11:34:14 PST 2020
Thanks Even, it works but I have strange result with the size value. I wouldn’t have been expected the exception from this test:
$ OGR_GEOJSON_MAX_OBJ_SIZE=500MB ogr2ogr -f "GeoJSON" indonesia.geojson "WFS:geonode.wfp.org/geoserver/wfs?request=GetFeature&typename=geonode:glb_bnd_adm0_1&outputformat=json" -where “adm0_id=‘272’"
indonesia.geojson is around 35MB so the exception shouldn’t raise if OGR_GEOJSON_MAX_OBJ_SIZE=50 AFAIK:
$ python
Python 3.7.6 (default, Jan 28 2020, 15:35:48)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ["OGR_GEOJSON_MAX_OBJ_SIZE"] = “50”
>>> from osgeo import ogr
>>> ogr.UseExceptions()
>>> ds = ogr.Open('/Users/geobart/Downloads/indonesia.geojson’)
>>> lyr = ds.GetLayer(0)
>>> lyr.GetNextFeature()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/geobart/.pyenv/versions/pygeoapi/lib/python3.7/site-packages/osgeo/ogr.py", line 1632, in GetNextFeature
return _ogr.Layer_GetNextFeature(self, *args)
RuntimeError: GeoJSON object too complex, please see the OGR_GEOJSON_MAX_OBJ_SIZE environment option
Is it a bug?
Il 28 feb 2020, 17:29 +0100, Even Rouault <even.rouault at spatialys.com>, ha scritto:
> On vendredi 28 février 2020 17:22:28 CET Francesco Bartoli wrote:
> > However, we are using both modules so how can we handle exceptions properly
> > for both of them?
>
> You can use both gdal.UseExceptions() and ogr.UseExceptions()
>
> >
> > Using ogr.UseExceptions() the
> > call https://github.com/geopython/pygeoapi/pull/372/files#diff-b105ae3f7a36
> > 059b16bdc16a08071016R361 gives the same result silently without any message
> > to system output this time.
>
> On a quick test, ogr.UseExceptions() does the job for me:
>
> $ OGR_GEOJSON_MAX_OBJ_SIZE=0 python
> > > > from osgeo import ogr
> > > > ogr.UseExceptions()
> > > > ds = ogr.Open('poly.geojson')
> > > > lyr = ds.GetLayer(0)
> > > > lyr.GetNextFeature()
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/home/even/gdal/git/gdal/gdal/swig/python/build/lib.linux-x86_64-2.7/
> osgeo/ogr.py", line 1339, in GetNextFeature
> return _ogr.Layer_GetNextFeature(self, *args)
> RuntimeError: GeoJSON object too complex, please see the
> OGR_GEOJSON_MAX_OBJ_SIZE environment option
> > > >
>
> --
> Spatialys - Geospatial professional services
> http://www.spatialys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20200229/33d2fe9d/attachment.html>
More information about the gdal-dev
mailing list