1

I'm developing a gis app with geotools 19-SNAPSHOT. I want to get some gis data from another app. After getting data, save them in local db. Received data has a String primary key as follow:

@Id
private String code;

First, I want to get featureType,then create table and finally getting data and save them.

When I create a table with SimpleFeatureType, it create int fid primary key, But I want to it create String primary key named code. How Can I do it with GeoTools?

Update:

I create table as follow:

SimpleFeatureType getReceivedFeatureType()
{
     return getDataStore(cfgs).getSchema("myTableName");
}

DataStore getDataStore(cfgs)
{
     URI uri = new URI("db-url");
     Map<String, Object> params = new HashMap();

     params.put("dbtype", "postgis");
     params.put("host", url.getHost());
     //Other Db Connection Configs

     return DataStoreFinder.getDataStore(params);
}

store = getDataStore(cfgs);
SimpleFeatureType sft = getReceivedFeatureType();
store.createSchema(sft);
  • 1
    we need to see more of your code, especially the part creating the schema (featureType) and the features. – Ian Turton Dec 12 '17 at 8:24
  • @IanTurton I updated it. – Morteza Malvandi Dec 12 '17 at 10:05
  • You are still missing the feature creation code – Ian Turton Dec 12 '17 at 10:36
  • 1
    @IanTurton first, I want to create correct table, then add features. (if the name of primary key be fid and its type be int, my code save features correctly). My problem is creating table with special primary key. – Morteza Malvandi Dec 12 '17 at 11:06
  • hello @Morteza Malvandi, I have the same issue, did you find a solution? thank you – Anas Ben Mansour Oct 2 '18 at 12:05

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.