TransWikia.com

org.geotools.jdbc.JDBCDataStore stores shape files in the database but files stored in own tables

Geographic Information Systems Asked by user840930 on February 7, 2021

Using geotools to store shape files in a PostgreSQL database. Each shape file is being stored in it’s own table in the database. Is there a way to store the files in a single table? Also, the tables created for each file have a different structure. Is there a way to check the shape files to know the difference in tables that will be created and group the files accordingly?

One Answer

If GeoTools is storing your shapefiles in separate tables then it will be because you asked it to. When you create a JDBCDataStore on a PostGIS database you specify the database and schema, then you create FeatureSources (and FeatureStores if you want to write) using a FeatureType (confusingly often referred to as a schema) that specifies the table name and layout.

So I suspect that when you read in your shapefiles you use the schema of the shapefile to create the new database table so it shares the name and attributes of the shapefile.

You can of course open an existing table by using its name but then your features must match the table's. You can't modify the features' schema directly because they are immutable but there some helper methods in the DataUtilities class such as DataUtilities.createSubType(SimpleFeatureType, String[]) that reduce the number of attributes in a FeatureType and DataUtilities.reType(schema, feature) which makes a new feature of the new type.

Answered by Ian Turton on February 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP