PostgreSQL – ogr2ogr Import Fails with ‘GeoJSON Object Too Complex’ Error

geojsonogr2ogrpostgresql

I'm trying to import a large (8.8GB) GeoJSON file to a Postgres 9.6 database with the following command:

ogr2ogr -f "PostgreSQL" -nln final_diffs PG:"host=localhost dbname=inspire user=me" diffs.geojson

But I get lots of warnings like this:

ERROR 1: GeoJSON object too complex
ERROR 1: GeoJSON object too complex
More than 1000 errors or warnings have been reported. No more will be reported from now.

And the process runs without errors, but at the end, nothing has been imported into the Postgres database.

Any ideas? I've not seen this warning before, and the only online reference I can find is in the GDAL source code.

All I get from ogrinfo is the above warnings, then:

Layer name: diffs
Geometry: Unknown (any)
Feature Count: 0
Layer SRS WKT:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4326"]]

Best Answer

Error comes from the GDAL GeoJSON driver. The source code is in https://github.com/OSGeo/gdal/blob/master/gdal/ogr/ogrsf_frmts/geojson/ogrgeojsonreader.cpp.

The max value is defined on line 50

const size_t MAX_OBJECT_SIZE = 200 * 1024 * 1024;

There are tooComplex checks in many places and that throws the errot that you saw

void OGRGeoJSONReaderStreamingParser::TooComplex()
{
    if( !ExceptionOccurred() )
        Exception("GeoJSON object too complex");
}

I do not know really what to do but I can suggest

  • Send a link of your data to gdal-dev mailing list and ask them to evaluate if that GeoJSON dataset is unreasonable or if the 200 * 1024 * 1024 limit should be raised again. It has already been doubled a few months ago because of this ticket https://github.com/OSGeo/gdal/issues/807.
  • Raise the value yourself; it would require to compile GDAL from the sources
  • Write a mail to the data provider and ask them to analyze if they could make the offending geometry smaller or use some other format, perhaps GeoPackage.