[udig-devel] Need help to change the schema and add new attribute
types in a new layer
Jesse Eichar
jeichar at refractions.net
Tue Apr 10 10:47:23 PDT 2007
Hi Magna,
There is a command that does most of this work for you.
I've made a code snippet at:
http://svn.geotools.org/udig/branches/1.1.x/udig/tutorials/
net.refractions.udig.code.examples/src/net/refractions/udig/code/
examples/CopyFeatures.java.
Jesse
On Apr 9, 2007, at 8:21 AM, Schmitt, Magna (CIP) wrote:
> 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
More information about the udig-devel
mailing list