Hi,

After loading a shapefile (ESRI), I created a graph using a
DirectedLineStringGraphGenerator. The creation went fine but when using a
DijkstraShortestPathFinder.getPath() on it, I noticed that there was a
problem because it returned null. Apparently, the linestring graph generator
does not take internal intersections of
lines into account when building the graph. Hence, I decided to code a
routine to split the LineStrings at their intersection as advised there:
http://www.nabble.com/Re%3A-LineString-Graph-Traversal-p1489791.html

The problem is that My routine is taking "forever" to do the splitting.
Either, I'm doing it wrong or it is not optimized enough. After waiting for
10 minutes, it is still not finished (although, the shapefile is not that
big). Could someone have a look at my function and see what the problem is?

Thanks in advance,

Best regards,
Chris.
    private Vector<LineString> splitLines(Vector<LineString> lines) {
        for (int i = 0; i < lines.size() - 1; ++i) {
            LineString l1 = (LineString) lines.get(i);
            for (int j = i+1; j < lines.size(); ++j) {
                LineString l2 = (LineString) lines.get(j);
                Geometry gc = l1.intersection(l2);
                if (gc.getNumGeometries() > 0) {
                    // Intersection
                    Point p = (Point) gc.getGeometryN(0);
                    if (l2.getStartPoint() != p && l2.getEndPoint() != p) {
                        // Remove old line from table
                        lines.remove(j);
                        // Split into two lines
                        Coordinate[] c = new 
Coordinate[]{(l2.getStartPoint()).getCoordinate(), p.getCoordinate()};
                        lines.add(j, new LineString(new 
CoordinateArraySequence(c), new GeometryFactory()));
                        c = new Coordinate[]{p.getCoordinate(), 
(l2.getEndPoint()).getCoordinate()};
                        lines.add(j, new LineString(new 
CoordinateArraySequence(c), new GeometryFactory()));
                        ++j;
                        //System.out.println("Created 1 line");
                    }
                    if (l1.getStartPoint() != p && l1.getEndPoint() != p) {
                        // Remove old line from table
                        lines.remove(i);
                        // Split into two lines
                        Coordinate[] c = new 
Coordinate[]{(l1.getStartPoint()).getCoordinate(), p.getCoordinate()};
                        LineString new_l = new LineString(new 
CoordinateArraySequence(c), new GeometryFactory()); 
                        lines.add(i, new_l);
                        c = new Coordinate[]{p.getCoordinate(), 
(l1.getEndPoint()).getCoordinate()};
                        lines.add(i+1, new LineString(new 
CoordinateArraySequence(c), new GeometryFactory()));
                        ++j;
                        //System.out.println("Created 1 line");
                        l1 = (LineString) new_l;
                    }
                }
            }
        }
        return lines;
    }
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to