César Martínez Izquierdo ha scritto: > Hello list, > > I'm using Sextante through the GeoTools-Sextante bindings to create a > Graticule (using CreateGraticuleBuilder algorithm form Sextante). > This creates a shapefile containing a graticule of rectangles. > > However, performance is really poor: ~ 63 minutes to just write around > 14000 features. > The relevant part of code is: > FeatureStore<SimpleFeatureType, SimpleFeature> > store = > ((FeatureStore<SimpleFeatureType, SimpleFeature>) getFeatureSource()); > List<Object> attributes = new > ArrayList<Object>(); > attributes.add(geom); > attributes.addAll(Arrays.asList(values)); > SimpleFeatureType ft = store.getSchema(); > FeatureCollection<SimpleFeatureType, > SimpleFeature> collection = > FeatureCollections > .newCollection(); > > SimpleFeature feature = > SimpleFeatureBuilder.build(ft, attributes, > SimpleFeatureBuilder.createDefaultFeatureId()); > collection.add(feature); > store.addFeatures(collection); > Note that "geom" is a JTS geometry, and "values" is an Object[]. > > I've been measuring times, and 99% of the time is spent in the last line: > > store.addFeatures(collection);
I guess the relevant part of the code is contained in a loop? Two suggestions: - create a SimpleFeatureBuilder outside of the loop and reuse it to build all features - create a new Transaction, set it in the store (that you will get just once) - then loop and add - when the loop is done commit the transaction Cheers Andrea -- Andrea Aime OpenGeo - http://opengeo.org Expert service straight from the developers. ------------------------------------------------------------------------------ This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev _______________________________________________ Geotools-gt2-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
