M.S.Bachler wrote:
Message

Hi!

Silly question.

Earlier you helpfully gave me a code snippet to create a new shapefile.

IndexedShapefileDatastoreFactory fac=new IndexedShapefileDataStoreFactory();

ShapefileDataStore ds=fac.createDatastore(url);

// I assume this is the URL of the new shapefile I want it to create?

GeometryFactory gf = new GeometryFactory();

ds.createSchema( featureType );

// Here I got lost. Started to investigate FeatureType and felt like I was walking through tar.

I did some stuff with FeatureType the other day... trying to create a new Feature from scratch. Here is the code I found to create a new FeatureType:
                    AttributeType geomAttr = AttributeTypeFactory.newAttributeType("the_geom", LineString.class);
                    FeatureType ftRoad = FeatureTypeBuilder.newFeatureType(new AttributeType[] {geomAttr}, "road");
                        
    //                WKTReader wktReader = new WKTReader();
    //                Point geometry = (Point) wktReader.read("POINT (" + lat + " " + lon + ")");
                    GeometryFactory geomFactory = new GeometryFactory();
                    LineString geometry = geomFactory.createLineString(coords);
                    Feature theRoad = ftRoad.create(new Object[] {geometry}, "myRoad");

This example Feature only has one attribute which is the geometry, the_geom. You can create and add other attributes in the AttributType[] and Object[] if needed.

These classes are from the org.geotools.feature package.

Hopefully you may find this useful. I'm not sure if this is the most up-to-date way of doing it, but it worked for me.

Mark

--
This message has been scanned for viruses and dangerous
content by MailScanner, and is believed to be clean.
begin:vcard
fn:Mark Presling
n:Presling;Mark
email;internet:[EMAIL PROTECTED]
tel;home:+6442322774
tel;cell:+6421549540
version:2.1
end:vcard

_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel

Reply via email to