Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am attempting to build a simple java program that loads shapefiles into a Postgis 2.0 database. Everything is working out great except that I would like to be able to modify the FeatureType in the following ways:

1) change the geometry column name from "the_geom" to "geom" 2) set all columns to be lower case. 3) change the primary key from serial to bigserial.

The following is my current code which basically is just transferring the shpSchema to the pgSchema. I am fairly certain that what I am trying to do is fairly simple and common, but I can find no obvious way to do it or any documentation --or even any examples of someone trying to do this.

    Map shpConnectParams = new HashMap();
    shpConnectParams.put("url", shapefile.toURI().toURL());

    DataStore shpStore = DataStoreFinder.getDataStore(shpConnectParams);

    String shpTypeName = shpStore.getTypeNames()[0];
    FeatureSource shpFS = shpStore.getFeatureSource(shpTypeName);

    SimpleFeatureType shpSchema = (SimpleFeatureType) shpFS.getSchema();
    CoordinateReferenceSystem crs = shpSchema.getCoordinateReferenceSystem();
    Map pgParams = new HashMap();
    for (AttributeDescriptor attrDesc : shpSchema.getAttributeDescriptors()) {


    pgParams.put("dbtype", "postgis");                   //must be postgis
    pgParams.put("host", "localhost");      //the name or ip address of the machine running PostGIS
    pgParams.put("port", new Integer(5432));             //the port that PostGIS is running on (generally 5432)
    pgParams.put("database", "test");              //the name of the database to connect to.
    pgParams.put("user", "postgres");                    //the user to connect with
    pgParams.put("passwd", "test!");                 //the password of the user.
    pgParams.put("schema", "scratch");   //the schema of the database
    pgParams.put("create spatial index", Boolean.TRUE);

    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();


    DataStore pgDatastore = DataStoreFinder.getDataStore(pgParams);

    SimpleFeatureSource pgFS = pgDatastore.getFeatureSource(shpTypeName);

    SimpleFeatureType pgSchema = pgFS.getSchema();

    Transaction transaction = new DefaultTransaction("create");

    if (pgFS instanceof SimpleFeatureStore) {
        SimpleFeatureStore pgFeatureStore = (SimpleFeatureStore) pgFS;

        SimpleFeatureCollection features = (SimpleFeatureCollection) shpFS.getFeatures();
        try {

        } catch (Exception problem) {

        } finally {
        System.exit(0); // success!
    } else {
        System.out.println(shpTypeName + " does not support read/write access");

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.