PostGIS Schema from empty GeoJSON set

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

PostGIS Schema from empty GeoJSON set


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

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

This is valid GeoJSON, so I'd like to support this case. 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 = GeoToolsUtil.getPostGisDataStore(/*params*/);

The final line throws an error 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 commit 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. 

Is there a way I can get this schema creation to succeed with an empty GeoJSON set? I would like to add more feature data to it later, but I would like to handle table creation immediately upon being provided with this initial GeoJSON. 


Check out the vibrant tech community on one of the world's most
engaging tech sites,!
GeoTools-GT2-Users mailing list
[hidden email]