From: Manu_macros <mac...@gm...> - 2007-11-20 10:38:47
|
Hi, I resolve my problem with this method, if someone wants. I have no time now to integrate it to the MemoryDataStore, soon perhaps but the idea will be the same. Manu //----------------------------------------- private synchronized static FeatureSource buildMemoryFeatureSource(FeatureCollection coll, String typename, FeatureType currentFeatureType, AttributeType newTypes[]){ FeatureType ftState=null; MemoryDataStore MStore=null; try { MStore = new MemoryDataStore(); //---- current attributes AttributeType currentTypes[] = currentFeatureType.getAttributeTypes(); //---- new array of attributes = current array+ new attributes AttributeType typesNew[] = new AttributeType[currentTypes.length+newTypes.length]; for(int i=0;i<currentTypes.length;i++){ typesNew[i] = currentTypes[i]; } for(int i=0;i<newTypes.length;i++){ typesNew[currentTypes.length+i] = newTypes[i]; } ftState = FeatureTypeFactory.newFeatureType(typesNew, typename); MStore.createSchema(ftState); Iterator iterator = coll.iterator(); FeatureCollection newColl = FeatureCollections.newCollection(); Feature feature, newFeature; Object[] objs; try { for( int count=0; iterator.hasNext(); count++) { feature = (Feature) iterator.next(); objs = new Object[feature.getNumberOfAttributes()+newTypes.length]; for (int i = 0; i < feature.getNumberOfAttributes(); i++) { objs[i] = feature.getAttribute(i); } newFeature = ftState.create( objs, feature.getID()); newColl.add(newFeature); } } finally { coll.close( iterator ); } MStore.addFeatures(newColl); return MStore.getFeatureSource(typename); } catch (Exception e) { e.printStackTrace(); } return null; } -- View this message in context: http://www.nabble.com/Add-Remove-Attribute-in-a-MemoryDataStore-tf4797128.html#a13854506 Sent from the geotools-gt2-users mailing list archive at Nabble.com. |