Adding geometry to a planar graph

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Adding geometry to a planar graph

Mark Coletti-2
I have a set of LineStrings from which I would like to create a
PlanarGraph.  Seems straightforward enough, but I cannot see in the
existing set of JTS classes any mechanism for doing so.  So I'm left
with handcrafting Edges and Nodes from LineStrings, which doesn't seem
to be working out too well:

       ArrayList edges = new ArrayList();

       for (int i = 0; i < geometries.numObjs; i++)
       {
           if ( geometries.get(i) instanceof LineString )
           {
               LineString lineString = (LineString) geometries.get(i);

               Edge edge = null;

               for (LinearIterator it = new LinearIterator(lineString);
                    it.hasNext(); it.next())
               {
                   graph_.addNode(it.getSegmentStart());
                   graph_.addNode(it.getSegmentEnd());

                   Coordinate [] edgeCoords =
{it.getSegmentStart(),it.getSegmentEnd()};

                   edge = new Edge(edgeCoords);

                   try
                   {
                       edges.add(edge);
                   }
                   catch (Exception e)
                   {
                       System.err.println("Unable to add edge: " + e);
                       break;
                   }

               }
           }
       }

       graph_.addEdges(edges);  // EXCEPTION THROWN HERE


I suspect I'm going about this all wrong, but there is no or little
high level documentation on planar nor geometry graphs.  Indeed many
of the member functions have no documentation.  E.g., the
GeometryGraph ctor takes an integer argument and there is no
corresponding explanation for this argument.

Anyone have suggestions on what I should do?

Cheers!

Mark
_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding geometry to a planar graph

Martin Davis
First of all, use PlanarGraph, not GeometryGraph.  The latter is really
only suitable for internal use.

Your best bet is to look at existing source code to see how to use
PlanarGraphs.  Have a look at the source in the
com.vividsolutions.jts.operation.polygonize pacakge.

You're no doubt right that the Javadoc for PlanarGraph needs work, and
I'm happy to add to it if you can provide some specific things that
could be improved.  But really the PlanarGraph API is a suite of classes
that all need to work together, and this situation is usually better
understood by examples or more general purpose doc than simply the
Javadoc (e.g. ever tried to learn Swing from the Javadoc?)

Martin

Mark Coletti wrote:

> I have a set of LineStrings from which I would like to create a
> PlanarGraph.  Seems straightforward enough, but I cannot see in the
> existing set of JTS classes any mechanism for doing so.  So I'm left
> with handcrafting Edges and Nodes from LineStrings, which doesn't seem
> to be working out too well:
>
>        ArrayList edges = new ArrayList();
>
>        for (int i = 0; i < geometries.numObjs; i++)
>        {
>            if ( geometries.get(i) instanceof LineString )
>            {
>                LineString lineString = (LineString) geometries.get(i);
>
>                Edge edge = null;
>
>                for (LinearIterator it = new LinearIterator(lineString);
>                     it.hasNext(); it.next())
>                {
>                    graph_.addNode(it.getSegmentStart());
>                    graph_.addNode(it.getSegmentEnd());
>
>                    Coordinate [] edgeCoords =
> {it.getSegmentStart(),it.getSegmentEnd()};
>
>                    edge = new Edge(edgeCoords);
>
>                    try
>                    {
>                        edges.add(edge);
>                    }
>                    catch (Exception e)
>                    {
>                        System.err.println("Unable to add edge: " + e);
>                        break;
>                    }
>
>                }
>            }
>        }
>
>        graph_.addEdges(edges);  // EXCEPTION THROWN HERE
>
>
> I suspect I'm going about this all wrong, but there is no or little
> high level documentation on planar nor geometry graphs.  Indeed many
> of the member functions have no documentation.  E.g., the
> GeometryGraph ctor takes an integer argument and there is no
> corresponding explanation for this argument.
>
> Anyone have suggestions on what I should do?
>
> Cheers!
>
> Mark
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>
>  

--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022

_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding geometry to a planar graph

Mark Coletti-3
On Thu, Aug 27, 2009 at 5:00 PM, Martin Davis<[hidden email]> wrote:
> First of all, use PlanarGraph, not GeometryGraph.  The latter is really only
> suitable for internal use.

Ah ha.  That would explain the weird undocumented GeometryGraph ctor.
I was pulling my hair out wondering why it wanted an integer argument.

> Your best bet is to look at existing source code to see how to use
> PlanarGraphs.  Have a look at the source in the
> com.vividsolutions.jts.operation.polygonize pacakge.

I suppose part of the problem here is that I have a jar file and not
much source.  This is all the source I have:

./src/com/vividsolutions/jts/JTSVersion.java
./src/com/vividsolutions/jtsexample/operation/polygonize/PolygonizeExample.java
./src/com/vividsolutions/jtsexample/operation/linemerge/LineMergeExample.java
./src/com/vividsolutions/jtsexample/operation/distance/ClosestPointExample.java
./src/com/vividsolutions/jtsexample/precision/EnhancedPrecisionOpExample.java
./src/com/vividsolutions/jtsexample/geom/ExtendedCoordinateSequenceFactory.java
./src/com/vividsolutions/jtsexample/geom/BasicExample.java
./src/com/vividsolutions/jtsexample/geom/ExtendedCoordinateSequence.java
./src/com/vividsolutions/jtsexample/geom/SimpleMethodsExample.java
./src/com/vividsolutions/jtsexample/geom/ExtendedCoordinateExample.java
./src/com/vividsolutions/jtsexample/geom/PrecisionModelExample.java
./src/com/vividsolutions/jtsexample/geom/ConstructionExample.java
./src/com/vividsolutions/jtsexample/geom/ExtendedCoordinate.java
./src/com/vividsolutions/jtsexample/technique/LineStringSelfIntersections.java
./src/com/vividsolutions/jtsexample/technique/PolygonUnionUsingBuffer.java
./src/com/vividsolutions/jtsexample/linearref/LinearRefExample.java
./jtsio/src/com/vividsolutions/jts/io/oracle/OraWriter.java
./jtsio/src/com/vividsolutions/jts/io/oracle/OraReader.java
./jtsio/src/com/vividsolutions/jts/io/oracle/Constants.java
./jtsio/src/com/vividsolutions/jts/io/gml2/GeometryStrategies.java
./jtsio/src/com/vividsolutions/jts/io/gml2/GMLWriter.java
./jtsio/src/com/vividsolutions/jts/io/gml2/GMLHandler.java
./jtsio/src/com/vividsolutions/jts/io/gml2/GMLConstants.java
./jtsio/src/com/vividsolutions/jts/io/gml2/GMLReader.java
./jtsio/test/com/vividsolutions/jts/io/oracle/ConnectedTestCase.java
./jtsio/test/com/vividsolutions/jts/io/oracle/StaticPolygonTest.java
./jtsio/test/com/vividsolutions/jts/io/oracle/StaticMultiPointTest.java
./jtsio/test/com/vividsolutions/jts/io/oracle/StaticPointTest.java
./jtsio/test/com/vividsolutions/jts/io/oracle/StaticMultiLineStringTest.java
./jtsio/test/com/vividsolutions/jts/io/oracle/StaticMultiPolygonTest.java
./jtsio/test/com/vividsolutions/jts/io/oracle/StaticLineStringTest.java
./jtsio/test/com/vividsolutions/jts/io/gml2/GMLReaderTestCase.java
./jtsio/test/com/vividsolutions/jts/io/gml2/StaticPolygonTest.java
./jtsio/test/com/vividsolutions/jts/io/gml2/StaticMultiPointTest.java
./jtsio/test/com/vividsolutions/jts/io/gml2/StaticPointTest.java
./jtsio/test/com/vividsolutions/jts/io/gml2/StaticMultiLineStringTest.java
./jtsio/test/com/vividsolutions/jts/io/gml2/WritingTestCase.java
./jtsio/test/com/vividsolutions/jts/io/gml2/StaticMultiPolygonTest.java
./jtsio/test/com/vividsolutions/jts/io/gml2/StaticLineStringTest.java
./jtsio/test/com/vividsolutions/jts/generator/PointGenerator.java
./jtsio/test/com/vividsolutions/jts/generator/PolygonGenerator.java
./jtsio/test/com/vividsolutions/jts/generator/LineStringGenerator.java
./jtsio/test/com/vividsolutions/jts/generator/GeometryGenerator.java
./jtsio/test/com/vividsolutions/jts/generator/GridGenerator.java
./jtsio/test/com/vividsolutions/jts/generator/MultiGenerator.java

I'm not sure where I got my JTS stuff, so maybe I just blundered into
an ancient download page.  Can you could point me to a better source
for getting the source?

> You're no doubt right that the Javadoc for PlanarGraph needs work, and I'm
> happy to add to it if you can provide some specific things that could be
> improved.

No problem, I'll be happy to do so.

>  But really the PlanarGraph API is a suite of classes that all
> need to work together, and this situation is usually better understood by
> examples or more general purpose doc than simply the Javadoc (e.g. ever
> tried to learn Swing from the Javadoc?)

Well, I *did* try to get guidance from reading the ancillary
documentation, but didn't have much joy there.  However, it may be
that I as looking at stale documentation or missed some other relevant
JTS document.  Or I could have just missed a relevant section of the
documents I have.  These are the documents I read that were included
in the distro I downloaded:

JTS Developer Guide.pdf  (ver. 1.4)
JTS Technical Specs.pdf (ver. 1.4)
JTS TestBuilder & TestRunner User Guide.pdf (ver. 1.2)

Are these the latest versions?  Are there other JTS documents?

Cheers!

Mark
_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding geometry to a planar graph

Martin Davis
See http://tsusiatsoftware.net/jts/main.html for a link to the download
site on Sourceforge.  The most current download archive will have all
the source in it.

The docs you list are all there is, and they're pretty old
unfortunately.  The Javadoc is much more current, however.

Mark Coletti wrote:

> On Thu, Aug 27, 2009 at 5:00 PM, Martin Davis<[hidden email]> wrote:
>  
>> First of all, use PlanarGraph, not GeometryGraph.  The latter is really only
>> suitable for internal use.
>>    
>
> Ah ha.  That would explain the weird undocumented GeometryGraph ctor.
> I was pulling my hair out wondering why it wanted an integer argument.
>
>  
>> Your best bet is to look at existing source code to see how to use
>> PlanarGraphs.  Have a look at the source in the
>> com.vividsolutions.jts.operation.polygonize pacakge.
>>    
>
> I suppose part of the problem here is that I have a jar file and not
> much source.  This is all the source I have:
>
> ./src/com/vividsolutions/jts/JTSVersion.java
> ./src/com/vividsolutions/jtsexample/operation/polygonize/PolygonizeExample.java
> ./src/com/vividsolutions/jtsexample/operation/linemerge/LineMergeExample.java
> ./src/com/vividsolutions/jtsexample/operation/distance/ClosestPointExample.java
> ./src/com/vividsolutions/jtsexample/precision/EnhancedPrecisionOpExample.java
> ./src/com/vividsolutions/jtsexample/geom/ExtendedCoordinateSequenceFactory.java
> ./src/com/vividsolutions/jtsexample/geom/BasicExample.java
> ./src/com/vividsolutions/jtsexample/geom/ExtendedCoordinateSequence.java
> ./src/com/vividsolutions/jtsexample/geom/SimpleMethodsExample.java
> ./src/com/vividsolutions/jtsexample/geom/ExtendedCoordinateExample.java
> ./src/com/vividsolutions/jtsexample/geom/PrecisionModelExample.java
> ./src/com/vividsolutions/jtsexample/geom/ConstructionExample.java
> ./src/com/vividsolutions/jtsexample/geom/ExtendedCoordinate.java
> ./src/com/vividsolutions/jtsexample/technique/LineStringSelfIntersections.java
> ./src/com/vividsolutions/jtsexample/technique/PolygonUnionUsingBuffer.java
> ./src/com/vividsolutions/jtsexample/linearref/LinearRefExample.java
> ./jtsio/src/com/vividsolutions/jts/io/oracle/OraWriter.java
> ./jtsio/src/com/vividsolutions/jts/io/oracle/OraReader.java
> ./jtsio/src/com/vividsolutions/jts/io/oracle/Constants.java
> ./jtsio/src/com/vividsolutions/jts/io/gml2/GeometryStrategies.java
> ./jtsio/src/com/vividsolutions/jts/io/gml2/GMLWriter.java
> ./jtsio/src/com/vividsolutions/jts/io/gml2/GMLHandler.java
> ./jtsio/src/com/vividsolutions/jts/io/gml2/GMLConstants.java
> ./jtsio/src/com/vividsolutions/jts/io/gml2/GMLReader.java
> ./jtsio/test/com/vividsolutions/jts/io/oracle/ConnectedTestCase.java
> ./jtsio/test/com/vividsolutions/jts/io/oracle/StaticPolygonTest.java
> ./jtsio/test/com/vividsolutions/jts/io/oracle/StaticMultiPointTest.java
> ./jtsio/test/com/vividsolutions/jts/io/oracle/StaticPointTest.java
> ./jtsio/test/com/vividsolutions/jts/io/oracle/StaticMultiLineStringTest.java
> ./jtsio/test/com/vividsolutions/jts/io/oracle/StaticMultiPolygonTest.java
> ./jtsio/test/com/vividsolutions/jts/io/oracle/StaticLineStringTest.java
> ./jtsio/test/com/vividsolutions/jts/io/gml2/GMLReaderTestCase.java
> ./jtsio/test/com/vividsolutions/jts/io/gml2/StaticPolygonTest.java
> ./jtsio/test/com/vividsolutions/jts/io/gml2/StaticMultiPointTest.java
> ./jtsio/test/com/vividsolutions/jts/io/gml2/StaticPointTest.java
> ./jtsio/test/com/vividsolutions/jts/io/gml2/StaticMultiLineStringTest.java
> ./jtsio/test/com/vividsolutions/jts/io/gml2/WritingTestCase.java
> ./jtsio/test/com/vividsolutions/jts/io/gml2/StaticMultiPolygonTest.java
> ./jtsio/test/com/vividsolutions/jts/io/gml2/StaticLineStringTest.java
> ./jtsio/test/com/vividsolutions/jts/generator/PointGenerator.java
> ./jtsio/test/com/vividsolutions/jts/generator/PolygonGenerator.java
> ./jtsio/test/com/vividsolutions/jts/generator/LineStringGenerator.java
> ./jtsio/test/com/vividsolutions/jts/generator/GeometryGenerator.java
> ./jtsio/test/com/vividsolutions/jts/generator/GridGenerator.java
> ./jtsio/test/com/vividsolutions/jts/generator/MultiGenerator.java
>
> I'm not sure where I got my JTS stuff, so maybe I just blundered into
> an ancient download page.  Can you could point me to a better source
> for getting the source?
>
>  
>> You're no doubt right that the Javadoc for PlanarGraph needs work, and I'm
>> happy to add to it if you can provide some specific things that could be
>> improved.
>>    
>
> No problem, I'll be happy to do so.
>
>  
>>  But really the PlanarGraph API is a suite of classes that all
>> need to work together, and this situation is usually better understood by
>> examples or more general purpose doc than simply the Javadoc (e.g. ever
>> tried to learn Swing from the Javadoc?)
>>    
>
> Well, I *did* try to get guidance from reading the ancillary
> documentation, but didn't have much joy there.  However, it may be
> that I as looking at stale documentation or missed some other relevant
> JTS document.  Or I could have just missed a relevant section of the
> documents I have.  These are the documents I read that were included
> in the distro I downloaded:
>
> JTS Developer Guide.pdf  (ver. 1.4)
> JTS Technical Specs.pdf (ver. 1.4)
> JTS TestBuilder & TestRunner User Guide.pdf (ver. 1.2)
>
> Are these the latest versions?  Are there other JTS documents?
>
> Cheers!
>
> Mark
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>
>  

--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022

_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding geometry to a planar graph

Mark Coletti-3
On Thu, Aug 27, 2009 at 6:09 PM, Martin Davis<[hidden email]> wrote:
> See http://tsusiatsoftware.net/jts/main.html for a link to the download site
> on Sourceforge.  The most current download archive will have all the source
> in it.

I checked out the source from CVS, which should hopefully be the
latest.  Thanks for the pointer to the polygonizer as that is very
similar to what I want to do.

Essentially I have a set of LineStrings that represent a road network.
 I want to convert that to a planar graph so that I can guide an agent
through the network; i.e., have it navigate along LineStrings and then
use the network to select the next path in the route.  It looks like
I'll have to write up a LineString equivalent of the polygonizer from
scratch as I do not see that that functionality already exists in JTS.
 (Admittedly I might have missed such in my first pass through the CVS
incarnation of the source.)

Cheers,

Mark
_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Loading...