Adrian Custer wrote:

On Sat, 2006-03-11 at 21:35 +1300, Mark Presling wrote:
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

But note that, in this example, the feature has no CRS which means it
cannot be displayed with other layers. In other words we have a feature,
but it's not really 'valid'. Eventually, I'd like to have a ValidFeature
or a ValidatedFeatureFactory subclass which guarantees that Feature is
geometrically complete. While it's probably important that Features be
general enough to be allowed to exist without a CRS, it's a hurdle for
us beginners to get over.

I've been trying to figure out how to build a feature from scratch with
a CRS. When I do, I hope to update the docs.
I use the following code to draw the feature on the map:

DrawFeatureCommand cmd = 
mapContext.getDrawFactory().createDrawFeatureCommand(theRoad, 
mapContext.getCRS());
mapContext.sendASyncCommand(cmd);


As you can see, the CRS is passed through to createDrawFeatureCommand(). I knew the CRS of the coords that I passed through to geomFactory.createLineString() because I created them from another feature on a layer (which has the same CRS as the map, hence the mapContext.getCRS()). So if you know the CRS you can render the feature to the map by doing a transform from your CRS to the maps CRS (which you can retrieve). This is what the DrawFeatureCommand does.

So saying that it is not 'valid' is a little misleading in my view ;-) . Maybe I just don't fully understand where you are coming from.

Mark

all the best,
adrian

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


--
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