Hi everybody, I met some difficulties with the CSV2SHP example. To test it, I just want to create a shapefile with one point.
I get the following error (everything else is ok) : "The type org.geotools.factory.Factory cannot be resolved. It is indirectly referenced from required .class files" for the following lines : "GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);" and "ShapefileDataStore newDataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);" I have changed these lignes into new GeometryFactory() and new ShapefileDataStore(url,true) to fix them. But this error still appears at the begining of the class. I don't understand why this factory type is missing... Could you help me to fix it ? Thanksfully Sidonie ----------------------------------------------------- Code : // start source /* * GeoTools - The Open Source Java GIS Tookit * http://geotools.org * * (C) 2006-2008, Open Source Geospatial Foundation (OSGeo) * * This file is hereby placed into the Public Domain. This means anyone is * free to do whatever they wish with this file. Use it well and enjoy! */ package MethodesGT; import java.io.File; import org.geotools.data.DataStoreFactorySpi; import org.geotools.data.DataUtilities; import org.geotools.data.DefaultTransaction; import org.geotools.data.FeatureStore; import org.geotools.data.Transaction; import org.geotools.data.shapefile.ShapefileDataStore; import org.geotools.data.shapefile.ShapefileDataStoreFactory; import org.geotools.feature.FeatureCollection; import org.geotools.feature.FeatureCollections; import org.geotools.feature.simple.SimpleFeatureBuilder; import org.geotools.feature.simple.SimpleFeatureTypeBuilder; import org.geotools.referencing.crs.DefaultGeographicCRS; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.Point; /** * This example reads data for point locations and associated attributes from * a comma separated text (CSV) file and exports them as a new shapefile. It * illustrates how to build a feature type. * <p> * Note: to keep things simple in the code below the input file should not have * additional spaces or tabs between fields. * * @source $URL$ */ public class Csv2shp { public static void main(String[] args) throws Exception { // docs break feature type /* * We use the DataUtilities class to create a FeatureType that * will describe the data in our shapefile. * * See also the createFeatureType method below for another, * more flexible approach. */ final SimpleFeatureType TYPE = DataUtilities.createType( "Location", // <- the name for our feature type "location:Point:srid=4326," + // <- the geometry attribute: Point type "name:String" // <- a String attribute ); // docs break feature collection /* * We create a FeatureCollection into which we will put each Feature * created from a record in the input csv data file */ FeatureCollection<SimpleFeatureType, SimpleFeature> collection = FeatureCollections.newCollection(); /* * GeometryFactory will be used to create the geometry attribute * of each feature (a Point object for the location) */ //GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null); GeometryFactory geometryFactory = new GeometryFactory(); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE); double longitude = 5.770850000; double latitude = 45.192285000; String name = "Mon point"; /* Longitude (= x coord) first ! */ Point point = geometryFactory.createPoint(new Coordinate(longitude, latitude)); featureBuilder.add(point); featureBuilder.add(name); SimpleFeature feature = featureBuilder.buildFeature(null); collection.add(feature); // docs break new shapefile /* * Get an output file name and create the new shapefile */ File newFile = new File("new_shp.shp"); DataStoreFactorySpi dataStoreFactory = new ShapefileDataStoreFactory(); /* Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put("url", newFile.toURI().toURL()); params.put("create spatial index", Boolean.TRUE); */ // ShapefileDataStore newDataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params); ShapefileDataStore newDataStore = new ShapefileDataStore( newFile.toURI().toURL(), Boolean.TRUE); newDataStore.createSchema(TYPE); newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84); // docs break transaction /* * Write the features to the shapefile */ Transaction transaction = new DefaultTransaction("create"); String typeName = newDataStore.getTypeNames()[0]; FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) newDataStore.getFeatureSource(typeName); featureStore.setTransaction(transaction); try { featureStore.addFeatures(collection); transaction.commit(); } catch (Exception problem) { problem.printStackTrace(); transaction.rollback(); } finally { transaction.close(); } System.exit(0); }
------------------------------------------------------------------------------
_______________________________________________ Geotools-gt2-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
