No worries Michael. I am grateful to the effort and help I am getting!

I am still getting ClassCastException after trying your code. The only
difference that I made was that I removed the JFile object and replaced it
with a File object:

Exception in thread "main" java.lang.ClassCastException:
com.vividsolutions.jts.geom.MultiPolygon cannot be cast to
com.vividsolutions.jts.geom.LineString
    at
org.geotools.graph.build.line.LineStringGraphGenerator.add(LineStringGraphGenerator.java:54)
    at
org.geotools.graph.build.feature.FeatureGraphGenerator.add(FeatureGraphGenerator.java:58)
    at access.ShapeToGraph.main(ShapeToGraph.java:51)

Any clue this might be why?
Ahmed

On Mon, Mar 15, 2010 at 1:12 AM, Michael Bedward
<[email protected]>wrote:

> 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&#174; 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

Reply via email to