Hi Rob,
Thank you for the kind words.
I've been cutting through parts of geotools over the last month 1/2.
I think Michael also posted on a more effective way to do Multi to LineString
conversion.
He may be better for answering your WKT write but I would think you would need
to build a new FeatureCollection for the new x y points. But I could be wrong
because I've never used WKT writer.
The following method will build a FeatureCollection of LineString given a
TreeMap of X, Y points.
public FeatureCollection getLineFeature(TreeMap allPoints) throws Exception {
SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
typeBuilder.setName("mytype");
typeBuilder.setCRS(crs);
typeBuilder.add("route", LineString.class);
typeBuilder.length(MAX_NAME_LENGTH).add("name", String.class);
final SimpleFeatureType TYPE = typeBuilder.buildFeatureType();
FeatureCollection collection = FeatureCollections.newCollection();
GeometryFactory factory = JTSFactoryFinder.getGeometryFactory(null);
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
ArrayList coordList = new ArrayList();
Collection cl = allPoints.values();
Iterator it = cl.iterator();
while (it.hasNext()){
XyzPoint xyz = (XyzPoint)it.next();
coordList.add(new Coordinate(xyz.getX(),xyz.getY()));
//featureBuilder.set("name",xyz.getName());
}
Coordinate[] coords = CoordinateArrays.toCoordinateArray(coordList);
LineString lineString = factory.createLineString(coords);
//featureBuilder.set("name", "testing123");
featureBuilder.add(lineString);
collection.add(featureBuilder.buildFeature(null));
coordList.clear();
return collection;
}
Oliver
-----Original Message-----
From: "Heise, Robert" <[email protected]>
Sent: Saturday, November 28, 2009 9:12am
To: "Oliver Gottwald" <[email protected]>
Subject: RE: [Geotools-gt2-users] Converting MultiLineString to Linestring
Hello Oliver,
Thanks for the response. Your example did not directly solve the problem I was
having but certainly gave me a lot of ideas and insight on how to use geotools.
Thank you very much for taking the time to send me your code.
I have managed, using the below code to convert a MultiLineString to a
LineString, but am having problems converting that to WKT.. any thoughts?
MultiLineString multiLineString = (MultiLineString)
pSimpleFeature.getDefaultGeometry();
int N = multiLineString.getNumGeometries();
LineString lines[] = new LineString[ N ];
for (int i = 0; i < N; i++ ) {
lines[ i ] = (LineString) multiLineString.getGeometryN( i );
}
WKTWriter writer = new WKTWriter();
Thanks again
Rob
From: Oliver Gottwald [[email protected]]
Sent: Wednesday, November 25, 2009 4:37 PM
To: Heise, Robert
Subject: Re: [Geotools-gt2-users] Converting MultiLineString to Linestring
Rob,
Not sure if the below will help you.
I just put out an example with question for:
Feature Reference - Better Way?
In the following code I drill down from the layer to the Point.
In the below line I have "route" set as my attribute name for Point at
FeatureCollection creation.
Point p = (Point)sf.getAttribute("route");
You could use Point p = (Point)sf.getAttribute(0);
but I'm not sure how safe that is.
I assume you can swap out MultiLineString for Point on attribute extraction.
You may want to look at my example to see how i brought everything together.
Oliver
@SuppressWarnings("unchecked")
public static void getCoordinates(double cx, double cy) throws IOException {
MapLayer[] layers = map.getLayers();
for (int i=0; i<layers.length; i++){
FeatureSource<SimpleFeatureType, SimpleFeature> fs =
(FeatureSource<SimpleFeatureType, SimpleFeature>) layers[i].getFeatureSource();
FeatureCollection<SimpleFeatureType, SimpleFeature> fc =
fs.getFeatures();
Iterator<SimpleFeature> f = fc.iterator();
while (f.hasNext()){
SimpleFeature sf = (SimpleFeature)f.next();
Point p = (Point)sf.getAttribute("route");
double xi = p.getX();
double yi = p.getY();
if(checkFeatureReference(cx,cy,xi,yi)){
System.out.println("x: "+xi+" y: "+yi+" IN FEATURE REFERENCE
CIRCLE");
} else {
System.out.println("x: "+xi+" y: "+yi+" NOT IN FEATURE
REFERENCE CIRCLE");
}
}
}
}
-----Original Message-----
From: "Heise, Robert" <[email protected]>
Sent: Wednesday, November 25, 2009 4:23pm
To: "Michael Bedward" <[email protected]>
Cc: "[email protected]"
<[email protected]>
Subject: Re: [Geotools-gt2-users] Converting MultiLineString to Linestring
Thanks for the response.
If I am iterating over FeatureCollection, how do I get the MultiLineString from
SimpleFeature?
Thanks
Rob
-----Original Message-----
From: Michael Bedward [mailto:[email protected]]
Sent: Tuesday, November 24, 2009 6:29 PM
To: Heise, Robert
Cc: [email protected]
Subject: Re: [Geotools-gt2-users] Converting MultiLineString to Linestring
Hi Robert
MultiLineString mls = ...
int N = mls.getNumGeometries();
LineString lines[] = new LineString[ N ];
for ( int i = 0; i < N; i++ ) {
lines[ i ] = mls.getGeometryN( i );
}
Hope this helps,
Michael
This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed. If
you have received this email in error please notify the system manager. This
message contains confidential information and is intended only for the
individual named. If you are not the named addressee you should not
disseminate, distribute or copy this e-mail.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed. If
you have received this email in error please notify the system manager. This
message contains confidential information and is intended only for the
individual named. If you are not the named addressee you should not
disseminate, distribute or copy this e-mail.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users