Please, show me where is the problem:
File fileout;
    fileout = new File("F:\\Disp.shp");

final SimpleFeatureType TYPE = DataUtilities.createType("the_geom",
                "location:Polygon:srid=4326," + // <- the geometry
attribute: Polygon type
                        "name:String," + // <- a String attribute
                        "number:Integer" // a number attribute
        );
SimpleFeatureCollection collection1 = FeatureCollections.newCollection();
Geometry geom = (Geometry) feature.getDefaultGeometry();
CoordInit = geom.getCoordinates();

SimpleFeature feature1 = CreateFeature(CoordInit,TYPE);
collection1.add(feature1);
CreateFile(TYPE,collection1,fileout);
public void CreateFile(SimpleFeatureType TYPE,SimpleFeatureCollection
collection1, File fileout) throws MalformedURLException, IOException {

ShapefileDataStoreFactory dataStoreFactory = new
ShapefileDataStoreFactory();

        Map<String, Serializable> params = new HashMap<String,
Serializable>();
        params.put("url", fileout.toURI().toURL());
        params.put("create spatial index", Boolean.TRUE);

        ShapefileDataStore newDataStore = (ShapefileDataStore)
dataStoreFactory.createNewDataStore(params);
        newDataStore.createSchema(TYPE);

        /*
         * You can comment out this line if you are using the
createFeatureType method (at end of
         * class file) rather than DataUtilities.createType
         */
        newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
        Transaction transaction = new DefaultTransaction("create");

        String typeName = newDataStore.getTypeNames()[0];
        SimpleFeatureSource featureSource1 =
newDataStore.getFeatureSource(typeName);

        if (featureSource1 instanceof SimpleFeatureStore) {
            SimpleFeatureStore featureStore1 = (SimpleFeatureStore)
featureSource1;

            featureStore1.setTransaction(transaction);
            try {
                featureStore1.addFeatures(collection1);
                transaction.commit();

            } catch (Exception problem) {
                problem.printStackTrace();
                transaction.rollback();

            } finally {
                transaction.close();
            }
            System.exit(0); // success!
        } else {
            System.out.println(typeName + " does not support read/write
access");
            System.exit(1);
        }
    

}

public SimpleFeature CreateFeature(Coordinate[] Coord,SimpleFeatureType
TYPE) {

//Create de SHP Type
    
System.out.println("je suis dans l'afficheur");


 
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
//GeometryFactory geometryFactory =
JTSFactoryFinder.getGeometryFactory(null);
String name = "thing" + Math.random();
int number = (int) Math.round(Math.random() * 10.0);

GeometryFactory geometryFactory = new GeometryFactory();
/* Longitude (= x coord) first ! */
LinearRing ring = geometryFactory.createLinearRing(Coord);

    com.vividsolutions.jts.geom.Polygon polygon =
geometryFactory.createPolygon(ring,null);


featureBuilder.add(polygon);
featureBuilder.add(name);
featureBuilder.add(number );
final SimpleFeature feature = featureBuilder.buildFeature(null);

return feature;
    
}



--
View this message in context: 
http://osgeo-org.1560.x6.nabble.com/Write-feature-in-shapefile-tp5196083.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to