Thanks Michael!
I used some of the examples in the first link you provided but I am getting
a ClassCastException. I am not sure which Feature class to import since the
code was only a snippet and didn't have import statements.
Following is my java class, which is simply a main method in a class that
does the work. You can easily run it on your local machine and replicate the
error using any test shape file of your choice.
Please let me know if you can help me with this.
Thanks very much!
Ahmed
package access;
import org.geotools.factory.GeoTools;
import org.geotools.feature.Feature;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.feature.simple.SimpleFeatureImpl;
import org.geotools.filter.text.cql2.CQL;
import org.geotools.graph.build.feature.FeatureGraphGenerator;
import org.geotools.graph.build.line.LineStringGraphGenerator;
import org.geotools.graph.structure.Graph;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.geotools.data.DataAccess;
import org.geotools.data.FeatureSource;
import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.map.DefaultMapContext;
import org.geotools.map.MapContext;
import org.geotools.swing.JMapFrame;
import org.geotools.swing.data.JFileDataStoreChooser;
import org.opengis.feature.Attribute;
//import org.opengis.feature.Feature;
import org.opengis.feature.Property;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.Filter;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.Point;
public class ShapeToGraph {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
File shapeFile = new File("data/my-shape-region-map.shp");
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
Iterator iter = fCollection.iterator();
while(iter.hasNext()){
Feature feature = (Feature)iter.next();
featureGen.add( feature );
}
Graph g = featureGen.getGraph();
System.out.println(g.getNodes().size());
}
}
On Sat, Mar 13, 2010 at 9:57 PM, Michael Bedward
<[email protected]>wrote:
> Hi Ahmed,
>
> Have a look at the gt-graph module...
>
> http://docs.codehaus.org/display/GEOTDOC/Graphs
>
> You'll also find messages from other users about this module in the
> list archives:
> http://n2.nabble.com/geotools-gt2-users-f1936685.html
>
> Michael
>
------------------------------------------------------------------------------
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