Hi Ahmed,
Yes, sounds like it's time to update that wiki page and add an example
app for the graph module. Sorry for the confusion but with only a
small number of developers the docs tend to lag behind the code
sometimes :-)
I've modified your code and it runs successfully here. Please try it
now and see if it works for you.
Michael
import java.io.File;
import java.io.IOException;
import org.geotools.data.FeatureSource;
import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.graph.build.feature.FeatureGraphGenerator;
import org.geotools.graph.build.line.LineStringGraphGenerator;
import org.geotools.graph.structure.Graph;
import org.geotools.swing.data.JFileDataStoreChooser;
import org.opengis.feature.Feature;
public class ShapeToGraph {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
File shapeFile = JFileDataStoreChooser.showOpenFile("shp", null);
FileDataStore store = null;
FeatureSource featureSource = null;
// get a feature collection somehow
FeatureCollection fCollection = null;
try {
store = FileDataStoreFinder.getDataStore(shapeFile);
featureSource = store.getFeatureSource();
fCollection = featureSource.getFeatures();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//create a linear graph generate
LineStringGraphGenerator lineStringGen = new LineStringGraphGenerator();
//wrap it in a feature graph generator
FeatureGraphGenerator featureGen = new FeatureGraphGenerator(
lineStringGen );
//throw all the features into the graph generator
FeatureIterator iter = fCollection.features();
while(iter.hasNext()){
Feature feature = iter.next();
featureGen.add( feature );
}
Graph g = featureGen.getGraph();
System.out.println(g.getNodes().size());
}
}
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users