as far as i remember it is not possible to simply extend the FeatureSchema of a FeatureDataSet and the set the attribute. You need to "copy/transform" every Feature towards the new Schema and create a new Feature and a new Feature Collection.
see for instance: org.openjump.core.spatialAttributeOps.copyFeature(Feature feature, FeatureSchema newSchema) i think in the pirol package are also similar functions: de.fho.jump.pirol.apiTools.FeatureCollectionTools stefan Anthony Jjumba wrote: > I would like to add a new attribute to a schema and then start adding > values to the added attribute however I am > > having problems with it. > > > > I have a shapefile from which I get: > > > > FeatureCollection allFeatures; > > FeatureSchema lyrSchema = allFeatures.getFeatureSchema(); > > Iterator fIt = allFeatures.iterator(); > > > > //check to see if attribute does not exist > already > > if(!lyrSchema.hasAttribute("myField")){ > > lyrSchema.addAttribute("myField",AttributeType.STRING); > > } > > //loop through all the features and add an > attribute value in the 'myField' column > > while (fIt.hasNext()){ > > Feature currFeature = (Feature)fIt.next(); > > currFeature.setSchema(lyrSchema); > > String attrValue = "someText"; > > currFeature.setAttribute("myField",attrValue); // program > crashes here > > } > > > > > > I have checked and I am sure I can get the attribute index of the > 'myField' attribute that has just been added. > > However, for some reason I am not able to add the attribute value. > > > > It gives me this error: > > Exception in thread "AWT-EventQueue-0" > java.lang.ArrayIndexOutOfBoundsException: 4 > > > > Any ideas or help will be appreciated. > > Thanks, > > Anthony > > > No virus found in this outgoing message. > Checked by AVG Free Edition. > Version: 7.5.476 / Virus Database: 269.10.6/900 - Release Date: > 7/14/2007 3:36 PM > >------------------------------------------------------------------------ > >------------------------------------------------------------------------- >This SF.net email is sponsored by DB2 Express >Download DB2 Express C - the FREE version of DB2 express and take >control of your XML. No limits. Just data. Click to get it now. >http://sourceforge.net/powerbar/db2/ > >------------------------------------------------------------------------ > >_______________________________________________ >Jump-pilot-devel mailing list >Jump-pilot-devel@lists.sourceforge.net >https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel > > ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel