|
From: Oliver G. <ol...@dr...> - 2009-10-22 16:11:46
|
Hi,
I'm continuing my efforts with forced coordinate display by integrating LineString.
In a prior example I did multiple coordinate display for Points.
What I’m wondering is if there is anything more effective/better/flexible I can do then below for displaying a series of coordinates via LineString.
One line specifically that I wonder if could be done better is the following:
final SimpleFeatureType TYPE = DataUtilities.createType("Location", "location:LineString,name:String");
Any input would be greatly appreciated. :-)
Oliver
=======
Below is my main source for forced coordinate LineString display. Based on input from all you and alteration I will eventually put a full example on the forum.
public static void main(String[] args) throws Exception {
final SimpleFeatureType TYPE = DataUtilities.createType("Location", "location:LineString,name:String");
FeatureCollection collection = FeatureCollections.newCollection();
double lon[] = {20.22, 30.33, 40.44};
double lat[] = {20.22, 30.33, 40.44};
String name="test";
ArrayList cords = new ArrayList();
for(int i=0;i<=2;i++){
cords.add(new Coordinate(lon[i],lat[i]));
}
GeometryFactory factory = JTSFactoryFinder.getGeometryFactory(null);
CoordinateArrays ca = new CoordinateArrays();
Coordinate[] cord = ca.toCoordinateArray(cords);
LineString lineString = factory.createLineString(cord);
SimpleFeature feature = SimpleFeatureBuilder.build( TYPE, new Object[]{lineString, name}, null );
collection.add( feature );
FeatureSource featureSource = DataUtilities.source(collection);
MapContext map = new DefaultMapContext();
map.setTitle("Quickstart");
map.addLayer(featureSource, null);
// Now display the map
JMapFrame.showMap(map);
}
|