Sorry, it is me again but I'm still stuck with the same problem: I
tried the following
Coordinate[] c = new
Coordinate[]{(l1.getStartPoint()).getCoordinate(), p.getCoordinate()};
LineString l1a = new LineString(new CoordinateArraySequence(c), new
GeometryFactory(new PrecisionModel(
PrecisionModel.maximumPreciseValue), 4326));
l1_sub.add(l1a);
if(!l1.covers(l1a))
System.out.println("Error: a");
But this did not improve anything (Still prints Error: a). Hence, in
the following of my routine, I trying to see which sub_part of l1 is
having an intersection with l2, it happens (more than 1000 times for
my shapefile) that I can find any l1 sub_part intersecting l2.
To detect the intersection, I'm using the following code:
int k = 0;
while (k < l1_sub.size() && !((LineString) l1_sub.get(k)).intersects(l2)) {
++k;
}
if(k >= l1_sub.size()) {
System.out.println("error");
}
I hope someone can help me with this, because of this, my graph is
not perfectly connected and this is kinda annoying. This is the last
problem in my project... thanks in advance.
P.S: I forgot to mention in my previous mail that p in the
intersection point between l1 and another linestring l2.
>
> On Jan 15, 2008 2:12 AM, Chris < [EMAIL PROTECTED]> wrote:
>
> > Could you tell me what is wrong with this part of code?
> >
> > Coordinate[] c = new Coordinate[]{(l1.getStartPoint()).getCoordinate(),
> > p.getCoordinate()};
> > LineString l1a = new LineString(new CoordinateArraySequence(c), new
> > GeometryFactory());
> > l1_sub.add(l1a);
> > if(!l1.covers(l1a))
> > System.out.println("Error: a");
> >
> > It displays "Error: a". Because of this, it happens that none of the
> > subparts of l1 intersects with l2 :(
> >
> >
> > Regards,
> > Chris.
>
private static Vector<LineString> splitLines(Vector<LineString> lines) {
Quadtree index = new Quadtree();
// Fill Spatial Index
for (int i = 0; i < lines.size(); ++i) {
LineString l = (LineString) lines.get(i);
index.insert(l.getEnvelopeInternal(), l);
}
// Detect intersection and cut the lines
Vector<LineString> l1_sub = new Vector<LineString>();
int imax = lines.size();
for (int i = 0; i < imax; ++i) {
LineString l1 = (LineString) lines.get(i);
List close_lines = index.query(l1.getEnvelopeInternal());
for (int j = 0; j < close_lines.size(); ++j) {
LineString l2 = (LineString) close_lines.get(j);
Geometry gc = l1.intersection(l2);
if (gc.getNumGeometries() > 0) {
// Intersection
Point p;
try {
p = (Point) gc.getGeometryN(0);
} catch (Exception e) {
continue;
}
if
(!l2.getStartPoint().getCoordinate().equals2D(p.getCoordinate()) &&
!l2.getEndPoint().getCoordinate().equals2D(p.getCoordinate())) {
Coordinate[] c = new
Coordinate[]{(l2.getStartPoint()).getCoordinate(), p.getCoordinate()};
LineString l2a = new LineString(new
CoordinateArraySequence(c), new GeometryFactory(new
PrecisionModel(PrecisionModel.maximumPreciseValue), 4326));
c = new Coordinate[]{p.getCoordinate(),
(l2.getEndPoint()).getCoordinate()};
LineString l2b = new LineString(new
CoordinateArraySequence(c), new GeometryFactory(new
PrecisionModel(PrecisionModel.maximumPreciseValue), 4326));
// Update spatial index
index.remove(l2.getEnvelopeInternal(), l2);
index.insert(l2a.getEnvelopeInternal(), l2a);
index.insert(l2b.getEnvelopeInternal(), l2b);
}
if (l1_sub.size() == 0) {
if
(!l1.getStartPoint().getCoordinate().equals2D(p.getCoordinate()) &&
!l1.getEndPoint().getCoordinate().equals2D(p.getCoordinate())) {
Coordinate[] c = new
Coordinate[]{(l1.getStartPoint()).getCoordinate(), p.getCoordinate()};
LineString l1a = new LineString(new
CoordinateArraySequence(c), new GeometryFactory(new
PrecisionModel(PrecisionModel.maximumPreciseValue), 4326));
l1_sub.add(l1a);
c = new Coordinate[]{p.getCoordinate(),
(l1.getEndPoint()).getCoordinate()};
LineString l1b = new LineString(new
CoordinateArraySequence(c), new GeometryFactory(new
PrecisionModel(PrecisionModel.maximumPreciseValue), 4326));
l1_sub.add(l1b);
}
} else {
// l1 was already cut out
int k = 0;
while (k < l1_sub.size() && !((LineString)
l1_sub.get(k)).intersects(l2)) {
++k;
}
if(k >= l1_sub.size()) {
// XXX: This is happening more than a thousand
times for my shapefile
System.out.println("error");
continue;
}
LineString l1part = (LineString) l1_sub.get(k);
if
(!l1part.getStartPoint().getCoordinate().equals2D(p.getCoordinate()) &&
!l1part.getEndPoint().getCoordinate().equals2D(p.getCoordinate())) {
l1_sub.remove(l1part);
Coordinate[] c = new
Coordinate[]{(l1part.getStartPoint()).getCoordinate(), p.getCoordinate()};
LineString l1a = new LineString(new
CoordinateArraySequence(c), new GeometryFactory(new
PrecisionModel(PrecisionModel.maximumPreciseValue), 4326));
l1_sub.add(l1a);
c = new Coordinate[]{p.getCoordinate(),
(l1part.getEndPoint()).getCoordinate()};
LineString l1b = new LineString(new
CoordinateArraySequence(c), new GeometryFactory(new
PrecisionModel(PrecisionModel.maximumPreciseValue), 4326));
l1_sub.add(l1b);
}
}
}
}
// Update l1 in spatial index
index.remove(l1.getEnvelopeInternal(), l1);
for (int k = 0; k < l1_sub.size(); ++k) {
LineString l = (LineString) l1_sub.get(k);
index.insert(l.getEnvelopeInternal(), l);
}
l1_sub.clear();
}
return new Vector<LineString>(index.queryAll());
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users