在对空间数据操作时,有时需要对shp中的feature要素进行属性的增加或者修改。由于GeoTool对象繁多,常常有很多种不同的解决方式,记录下我操作的方式:
1、对feature要素属性进行copy,并新增字段
//创建新的featuretype
featureType = feature.getFeatureType();//feature类型
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.init(featureType);//类似于属性copy
builder.add("newid", Integer.class);
SimpleFeatureType newstf=builder.buildFeatureType();
System.out.println(newstf);
2、对feature要素属性进行修改
要素字段the_geom,name,id,将id字段去掉。
SimpleFeatureType modifystf=DataUtilities.createSubType(featureType, new String[]{"the_geom","name"});
System.out.println(modifystf);