mbedward wrote:
> 
> I'm not sure if this is relevant to your problem (I haven't used the
> graph code in geotools) but to split your LineStrings at intersections
> you could try the following JTS trick (courtesy of Martin Davis's
> presentation at 2007 FOSS4G conference
> 
> Collection lines = ...  // your line strings
> Geometry mls = geomFactory.buildGeometry(lines);  // create a
> MultiLineString
> Point mlsPt = geomFactory.createPoint(mls.getCoordinate());  // get an
> arbitrary point on a line
> Geometry nodedLines = mls.union(pt);  // union the MultiLineString
> with the point
> 
> This has the (almost magical) effect of noding all of the line
> intersections.
> 
Thanks Michael! Here's the method I built out of your reply:
    private List<LineString> splitMLines(Vector<MultiLineString> mlines) {
        GeometryFactory geomFactory = new GeometryFactory();
        List<LineString> lines = new Vector<LineString>();
        
        int imax = mlines.size();
        for (int i = 0; i < imax; ++i) {
                MultiLineString mls = mlines.get(i);
                for (int j = 0;j <= mls.getNumGeometries()-1;j++) {
                        // get an arbitrary point on a line
                        Point mlsPt = 
geomFactory.createPoint(mls.getCoordinate());
                        // union the MultiLineString with the point 
                        Geometry nodedLines = mls.union(mlsPt);
                        if (nodedLines instanceof MultiLineString) {
                                for (int z = 0;z <= 
mls.getNumGeometries()-1;z++) {
                                        LineString ls = (LineString) 
mls.getGeometryN(z);
                                        lines.add(ls);
                                }
                        }
                        else if (nodedLines instanceof LineString){
                                lines.add((LineString) nodedLines);
                        }
                        else System.out.println("Error! Type is: " +
nodedLines.getGeometryType());
                }
        }
                return lines;
        }

But it gives me 167 partitions and that way the graph that is not well
connected. Did I do something wrong?
-- 
View this message in context: 
http://n2.nabble.com/Building-a-connected-graph-with-OSM-data---Splitting-LineStrings-at-their-intersections-tp3086758p3131785.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Are you an open source citizen? Join us for the Open Source Bridge conference!
Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250.
Need another reason to go? 24-hour hacker lounge. Register today!
http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to