Hello,
I am working on a project that builds up a graph and due to some errors i
am trying to visualize it.
The code looks like this and apparently it is not working because i get
this error "java.lang.ArrayIndexOutOfBoundsException: Can handle 1
attributes only, index is 1" on line featureBuilder.add(line);
networkGraph = featureGen.getGraph();
MapContent content= new MapContent();
content.setTitle("Graph map");
StyleBuilder styleBuilder = new StyleBuilder();
Style style =
styleBuilder.createStyle(styleBuilder.createPointSymbolizer());
SimpleFeatureTypeBuilder tbuild = new
SimpleFeatureTypeBuilder();
tbuild.setCRS(DefaultGeographicCRS.WGS84);
tbuild.setName("Line");
tbuild.add("Line", LineString.class);
SimpleFeatureType type = tbuild.buildFeatureType();
SimpleFeatureBuilder featureBuilder = new
SimpleFeatureBuilder(type);
GeometryFactory geometryFactory =
JTSFactoryFinder.getGeometryFactory(null);
Collection<org.geotools.graph.structure.Edge> edges =
networkGraph.getEdges();
for(org.geotools.graph.structure.Edge edge:edges){
Point nA = (Point) edge.getNodeA().getObject();
Point nB = (Point) edge.getNodeB().getObject();
Coordinate c1 = new Coordinate(nA.getX(), nA.getY());
Coordinate c2 = new Coordinate(nB.getX(), nB.getY());
Coordinate[] coords = new Coordinate[] {c1, c2};
com.vividsolutions.jts.geom.LineString line =
geometryFactory.createLineString(coords);
featureBuilder.add(line);
//System.out.println( nA.getX()+ " "+nA.getY());
}
SimpleFeature feature = featureBuilder.buildFeature(null);
DefaultFeatureCollection collection =new
DefaultFeatureCollection();
collection.add(feature);
content.addLayer(new FeatureLayer(collection,
(org.geotools.styling.Style) style));
JMapFrame.showMap(content);
I am still trying to get used to geotools, sorry if the question sounds
stupid.
Looking forward to your reply.
------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos. Get
unparalleled scalability from the best Selenium testing platform available.
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users