Hello:
I am trying to create a new layer from a group of features from another
existing layer but I would like to change the schema from the data store first
to add then new attribute types and new attributes to the features. I would
appreciate some advice on this.
So far I have done the following:
1) Got the features from an old existing layer
2) Got an iterator to get each feature an add them to an array of
Features (Features [])
3) I used the 'addFeatures' method with a 'FeatureReader'
4) created the new Layer (this is just a copy from the old one) (*)
/******************************************************************/
(*)//This is the method to create the new layer, it has a lot of deprecated
functions.....
public void featuresToShapefile(String fileName,Feature[] features) throws
Exception{
File file=new File(fileName);
ShapefileDataStore datastore = new ShapefileDataStore(file.toURL());
datastore.createSchema(features[0].getFeatureType());
/** file saving*/
FeatureStore featureStore = (FeatureStore)
(datastore.getFeatureSource());
FeatureReader aReader = DataUtilities.reader(features);
try {
featureStore.addFeatures(aReader);
}catch (Exception e) {
System.err.println(e.getMessage());
}
/** Adding the generated shape to the current map*/
List<IService> shpServiceList = new
ServiceFactoryImpl().aquire(file.toURL());
/**ArrayList<IGeoResource> LayersList = null;*/
for( IService service : shpServiceList ) {
if (service != null) {
if (service.members(null) != null) {
try {
MapFactory.instance().process(null,
service.members(null), false);
break;
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
}
}
/*******************************************************************/
Thank you in advance.
Magna
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel