Hi Oliver,
I've meddled with your example a bit so that it generates one than one
feature and uses SimpleFeatureTypeBuilder (as shown in the CSV 2 SHP
Lab example at the bottom of the code).
public class Foo
static final CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
static final int MAX_NAME_LENGTH = 20;
public static void main(String[] args) 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();
double x[][] = {{10, 20, 30, 40, 50}, {10, 20, 30, 40, 50}};
double y[][] = {{10, 20, 10, 20, 10}, {20, 30, 20, 30, 20}};
String[] names = {"foo", "bar"};
GeometryFactory factory = JTSFactoryFinder.getGeometryFactory(null);
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
ArrayList<Coordinate> coordList = new ArrayList<Coordinate>();
for (int line = 0; line < x.length; line++) {
for (int i = 0; i < x[line].length; i++) {
coordList.add(new Coordinate(x[line][i], y[line][i]));
}
Coordinate[] coords = CoordinateArrays.toCoordinateArray(coordList);
LineString lineString = factory.createLineString(coords);
featureBuilder.add(lineString);
featureBuilder.add(names[line]);
collection.add(featureBuilder.buildFeature(null));
coordList.clear();
}
MapContext map = new DefaultMapContext();
map.setTitle("My beautiful lines");
map.addLayer(collection, null);
// Now display the map
JMapFrame.showMap(map);
}
}
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users