1

I'm attempting to create a schema for some user-provided input GeoJSON so that I can store this data using PostGIS transactions. I am experiencing a problem with input that is a completely empty GeoJSON set.

{"type": "FeatureCollection", "features": []}

This is valid GeoJSON, so I'd like to support this case when users provide this input to me. I am retrieving a PostGIS data store and then creating a schema for this GeoJSON.

FeatureJSON featureJSON = new FeatureJSON(); SimpleFeatureType featureSchema = featureJSON.readFeatureCollectionSchema(inputStream, false); DataStore postGisStore = myProjectUtilities.getPostGisDataStore(/*params*/); postGisStore.createSchema(featureSchema);

The final line throws an error Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near ")" because it cannot find the default geometry field. This is because, for my empty GeoJSON set, there's obviously no geometry and no attributes.

If I turn on FINEST logging, I can see the SQL statement that is failing:

FINE: Create schema: CREATE TABLE "public"."feature" ( "fid" SERIAL PRIMARY KEY, )

The SQL statement is attempting to set a primary key, but since my GeoJSON is empty, no value exists and it ends up creating an invalid SQL statement.

Is there a way I can get this schema creation to succeed with an empty GeoJSON set? In my program, users can potentially add more features to this later, so I would really like to be able to create the table at this point in time.

  • what would be the schema of an empty table? – Ian Turton Mar 16 '17 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.