From: Jody G. <jga...@re...> - 2007-09-21 15:39:56
|
> >> To change the contents you will need to use a transaction and >> > FeatureStore just like normal. > Thanks. In trying to do this (code below), I run into two issues: > > a) On the first invocation of this function, the geometries of mds are > still untranslated (i.e. they are still equal to those of the input > features). > > b) On the second invocation, I get an IllegalStateException from > DefaultTransaction.getState(), saying "transaction has been closed". > > Any pointers? > Just a question - where does your origional FeatureCollection come from? It feels like once again you are trying to make a function out of a service. If you want a Collection<Feature> make a collection of Feature. The only reason to use DataStore is if you are going to work with MASSIVE content on Disk or Database. The only reason to work with MemoryDataStore is when debugging your code that works with MASSIVE content on Disk or Database. If your parameter features was obtained from a shapefile using FeatureSource.getFeatures( Filter ) then I think I can understand the problem ... Jody > Thanks again, > > Jerry. > > /////////////////////////////////////////////////// > > private static FeatureCollection > translate( FeatureCollection features, double xt, double yt ) > { > MemoryDataStore mds = new MemoryDataStore( features ); > String typeName = mds.getTypeNames()[0]; > > try > { > FeatureSource featureSource = > mds.getFeatureSource( typeName ); > FeatureStore featureStore = > (FeatureStore)featureSource; > Transaction transaction = new > DefaultTransaction(); > featureStore.setTransaction( transaction ); > > try > { > featureStore.getFeatures().accepts( new > TranslateGeometryVisitor( xt, yt ), > new NullProgressListener() ); > > transaction.commit(); > > return featureStore.getFeatures(); > > } > catch( IOException ioe ) > { > transaction.rollback(); > throw new UncheckedException( ioe ); > } > finally > { > transaction.close(); > } > } > catch( IOException ioe ) > { > throw new UncheckedException( ioe ); > } > } > > /////////////////////////////////////////////////// > > This message has been checked for viruses but the contents of an attachment > may still contain software viruses, which could damage your computer system: > you are advised to perform your own checks. Email communications with the > University of Nottingham may be monitored as permitted by UK legislation. > > |