From: <xav...@fr...> - 2004-11-30 14:38:42
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> Thanks Chris for your advices!!!<br> If I understood, I should use the addFeatures , so we could have such a code :<br> FeatureStore featureStore = (FeatureStore) datastore.getFeatureSource("road"); <br> FeatureReader aReader = datastore.getFeatureReader(aQuery,featureStore.getTransaction());<br> featureStore. addFeatures( aReader);<br> <br> could you indiacte me which kind of Query I've to put in this expression? (the minimal one)<br> Thanks <br> Xavier<br> <br> <br> Chris Holmes a écrit : <blockquote cite="mid...@be..." type="cite"> <pre wrap="">FeatureWriters are meant to be low level access, and indeed we are thinking of deprecating them. To add a feature you should just get a FeatureStore (shapefile implements it), and call addFeatures. Note that this may not work if your on a windows ntfs file system, as it sometimes has trouble with nio I believe. Chris On Tue, 30 Nov 2004, Xavier Méhaut wrote: </pre> <blockquote type="cite"> <pre wrap="">Hello, I've write the following simple code below to save a feature and then reopen it to add a new feature to the file. It almost runs, except for the appending. Does someone could help me? regards Xavier ________________________________________________________________________________ public class EssaisWriter { private static String URI = "C:/Documents andSettings/utilisateur/Bureau/eclipse/workspace/DecouverteGeotools/data/essai.shp ; public static void main(String[] args) throws IOException, ParseException, IllegalAttributeException, FactoryConfigurationError, SchemaException { saveFeatures(); appendFeature(); } // ///////////////////////////////////////////////// // save shapefile // ///////////////////////////////////////////////// public static void saveFeatures() throws FactoryConfigurationError, SchemaException, ParseException, IllegalAttributeException, IOException { // feature : creation du type AttributeType geom = AttributeTypeFactory.newAttributeType("the_geom", LineString.class); AttributeType roadWidth = AttributeTypeFactory.newAttributeType( "width", Float.class); FeatureType ftRoad = FeatureTypeFactory.newFeatureType( new AttributeType[] { geom, roadWidth }, "road"); // feature : creation de l'instance WKTReader wktReader = new WKTReader(); LineString geometry = (LineString) wktReader .read("LINESTRING (0 0, 10 10)"); Float width = new Float(10); Feature theRoad = ftRoad.create(new Object[] { geometry, width }, "myRoad"); // creation du datastore URL anURL = (new File(URI)).toURL(); ShapefileDataStore datastore = new ShapefileDataStore(anURL); datastore.createSchema(ftRoad); // sauvegarde du fichier FeatureWriter aWriter = datastore.getFeatureWriter("road", ((FeatureStore) datastore.getFeatureSource("road")) .getTransaction()); Feature aNewFeature = aWriter.next(); aNewFeature.setAttributes(new Object[] { geometry, width }); aWriter.write(); aWriter.close(); } // ///////////////////////////////////////////////// // appendFeature // ///////////////////////////////////////////////// public static void appendFeature() throws IOException, ParseException, IllegalAttributeException, FactoryConfigurationError, SchemaException { // feature : creation des attributs de l'instance WKTReader wktReader = new WKTReader(); LineString geometry = (LineString) wktReader .read("LINESTRING (10 10, 20 20)"); Float width = new Float(10); //on recupere la feature URL anURL = (new File(URI)).toURL(); ShapefileDataStore datastore = new ShapefileDataStore(anURL); String featureName = datastore.getTypeNames()[0]; //road" FeatureSource source = datastore.getFeatureSource(featureName); // append feature FeatureWriter aWriter = datastore.getFeatureWriterAppend(featureName, ((FeatureStore) source).getTransaction()); Feature f = aWriter.next(); f.setAttributes(new Object[] { geometry, width }); aWriter.write(); aWriter.close(); } } ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. <a class="moz-txt-link-freetext" href="http://productguide.itmanagersjournal.com/">http://productguide.itmanagersjournal.com/</a> _______________________________________________ Geotools-gt2-users mailing list <a class="moz-txt-link-abbreviated" href="mailto:Geo...@li...">Geo...@li...</a> <a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users">https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users</a> </pre> </blockquote> <pre wrap=""><!----> </pre> </blockquote> </body> </html> |