Just an update followng my previous reply.
The edge.getObject actaully returns the underlying SimpleFeature.

so I just did this:

                SimpleFeature sf = (SimpleFeature) e.getObject();
                Geometry geom =(Geometry)sf.getDefaultGeometry();
                double length = geom.getLength();

just using the generic Geometry, as I was lazy ;)

This should also allow access to the other attributes (untested)

Thanks for help,
Martin




On 9/1/2010 5:20 PM, Justin Deoliveira wrote:
Hi Martin,

Yeah you should be able to get at the underlying LineString by calling e.getObject(). Something like:

DijkstraIterator.EdgeWeigter weighter =new DijkstraIterator.EdgeWeighter() {
   public  double  getWeight(Edge e) {
      LineString l = (LineString) e.getObject();
      return l.getLength();
   }
}

However the linestring has no notion of units. That will depend on whatever coordinate system your data is in.

On Wed, Sep 1, 2010 at 10:55 AM, Martin Tomko <[email protected] <mailto:[email protected]>> wrote:

    Dear All,
    I am using the Graph api to construct a graph based on lineStrings -
    that works perfectly. I would like to do a shortest path computation
    based on geographical distance, and need to implement a Weighter.

    the docs show this snippet:

    DijkstraIterator.EdgeWeigter weighter =new
     DijkstraIterator.EdgeWeighter() {
       public  double  getWeight(Edge e) {
          return  1.0;//constant
       }
    }

    which results in a constant weight for an edge of 1.

    How do I get the actual length of an edge, in the original
    feature's units...

    I need the values also for other purposes, so really neend to
    access the edge length property.
    Is it possible?
    Thanks
    Martin



    
------------------------------------------------------------------------------
    This SF.net Dev2Dev email is sponsored by:

    Show off your parallel programming skills.
    Enter the Intel(R) Threading Challenge 2010.
    http://p.sf.net/sfu/intel-thread-sfd
    _______________________________________________
    Geotools-gt2-users mailing list
    [email protected]
    <mailto:[email protected]>
    https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users




--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.



--
Martin Tomko
Postdoctoral Research Assistant

Geographic Information Systems Division
Department of Geography
University of Zurich - Irchel
Winterthurerstr. 190
CH-8057 Zurich, Switzerland

email:  [email protected]
site:   http://www.geo.uzh.ch/~mtomko
mob:    +41-788 629 558
tel:    +41-44-6355256
fax:    +41-44-6356848

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to