Hello
Please i m using the class linegraphbuilder to build a graph from a shapefile. this is the code i used:
LineGraphBuilder lgb = new LineGraphBuilder();
FeatureSource fs = this.frame.mapPane.getMapContext().getLayer(0).getFeatureSource();
FeatureResults fr = fs.getFeatures();
FeatureCollection fc = fr.collection();
FeatureIterator f = fc.features();
//envelope - The bounding box that encloses the unvalidated data
Envelope envelope = fc.getBounds();
while (f.hasNext())
{
Feature ft = f.next();
if (envelope.contains(ft.getBounds())) {
lgb.add(ft);
}
}
org.geotools.graph.Graph g = lgb.build();
but what i read in the documentation is that add() function work with feature with linestring geometry, however the feature that are extracted from the shapefile are of type MultilineString
So is there a way to solve this problem or i can not use at all the class linegraphbuilder
thanks in advance
Object[] valObj = fc.toArray();//FeatureCollection read from .SHP
Feature valFeat;
newFC = FeatureCollections.newCollection();
AttributeType[] types = new AttributeType[1];
types[0] = AttributeTypeFactory.newAttributeType("Lines", LineString.class);
FeatureType pointType = FeatureTypeFactory.newFeatureType(types, "Lines");
for(int i=0;i<valObj.length;i++){
valFeat = (Feature)valObj[i];
WKTReader reader = new WKTReader();
LineString ls = (LineString)new GeometryFactory().createLineString(valFeat.getDefaultGeometry().getCoordinates());
feature = pointType.create(new Object[]{ls});
newFC.add(feature);
}
//context.addLayer(newFC,<some style>);
hope it works for you !!!