root / trunk / libraries / libTopology / src / com / vividsolutions / jcs / conflate / roads / model / ProperIntersectionFinder.java @ 22873
History | View | Annotate | Download (3.33 KB)
1 |
package com.vividsolutions.jcs.conflate.roads.model; |
---|---|
2 |
import java.util.Collection; |
3 |
import com.vividsolutions.jcs.conflate.roads.ConflationSession; |
4 |
import com.vividsolutions.jcs.geom.LineStringUtil; |
5 |
import com.vividsolutions.jcs.jump.FUTURE_CollectionUtil; |
6 |
import com.vividsolutions.jts.geom.Coordinate; |
7 |
import com.vividsolutions.jts.geom.Geometry; |
8 |
import com.vividsolutions.jts.geom.IntersectionMatrix; |
9 |
import com.vividsolutions.jts.geom.LineString; |
10 |
import com.vividsolutions.jts.util.Assert; |
11 |
import com.vividsolutions.jump.util.Block; |
12 |
import com.vividsolutions.jump.util.CollectionUtil; |
13 |
public class ProperIntersectionFinder { |
14 |
private static boolean properlyIntersect(LineString a, LineString b) { |
15 |
IntersectionMatrix matrix = a.relate(b); |
16 |
if (matrix.matches("T********")) { |
17 |
return true; |
18 |
} |
19 |
if (matrix.matches("FF*F*****")) { |
20 |
return false; |
21 |
} |
22 |
//Might be a cul-de-sac [Jon Aquino 12/3/2003]
|
23 |
Geometry intersection = a.intersection(b); |
24 |
Assert.isTrue(intersection.getDimension() == 0);
|
25 |
Coordinate[] coordinates = intersection.getCoordinates();
|
26 |
for (int i = 0; i < coordinates.length; i++) { |
27 |
if (coordinates[i].equals(LineStringUtil.first(a))
|
28 |
&& coordinates[i].equals(LineStringUtil.first(b))) { |
29 |
continue;
|
30 |
} |
31 |
if (coordinates[i].equals(LineStringUtil.first(a))
|
32 |
&& coordinates[i].equals(LineStringUtil.last(b))) { |
33 |
continue;
|
34 |
} |
35 |
if (coordinates[i].equals(LineStringUtil.last(a))
|
36 |
&& coordinates[i].equals(LineStringUtil.first(b))) { |
37 |
continue;
|
38 |
} |
39 |
if (coordinates[i].equals(LineStringUtil.last(a))
|
40 |
&& coordinates[i].equals(LineStringUtil.last(b))) { |
41 |
continue;
|
42 |
} |
43 |
return true; |
44 |
} |
45 |
return false; |
46 |
} |
47 |
public static Collection properlyIntersectingIncludedRoadSegments( |
48 |
SourceRoadSegment roadSegment) { |
49 |
return ProperIntersectionFinder.properlyIntersectingRoadSegments(
|
50 |
roadSegment, new Block() {
|
51 |
public Object yield(Object candidate) { |
52 |
return Boolean.valueOf(((SourceRoadSegment) candidate) |
53 |
.getState().indicates(SourceState.INCLUDED)); |
54 |
} |
55 |
}); |
56 |
} |
57 |
public static Collection properlyIntersectingRoadSegments( |
58 |
final SourceRoadSegment roadSegment, final Block criterion) { |
59 |
return properlyIntersectingRoadSegments(roadSegment.getApparentLine(),
|
60 |
roadSegment.getNetwork().getSession(), new Block() {
|
61 |
public Object yield(Object candidate) { |
62 |
return Boolean.valueOf(candidate != roadSegment |
63 |
&& ((Boolean) criterion.yield(candidate))
|
64 |
.booleanValue()); |
65 |
} |
66 |
}); |
67 |
} |
68 |
public static Collection properlyIntersectingRoadSegments(LineString line, |
69 |
ConflationSession session, Block criterion) { |
70 |
return FUTURE_CollectionUtil.concatenate(
|
71 |
properlyIntersectingRoadSegments(line, session |
72 |
.getSourceNetwork(0), criterion),
|
73 |
properlyIntersectingRoadSegments(line, session |
74 |
.getSourceNetwork(1), criterion));
|
75 |
} |
76 |
private static Collection properlyIntersectingRoadSegments( |
77 |
final LineString line, RoadNetwork network, final Block criterion) { |
78 |
return CollectionUtil.select(
|
79 |
network.roadSegmentsApparentlyIntersecting(line |
80 |
.getEnvelopeInternal()), new Block() {
|
81 |
public Object yield(Object arg) { |
82 |
SourceRoadSegment candidate = (SourceRoadSegment) arg; |
83 |
return Boolean.valueOf(((Boolean) criterion |
84 |
.yield(candidate)).booleanValue() |
85 |
&& properlyIntersect(line, candidate |
86 |
.getApparentLine())); |
87 |
} |
88 |
}); |
89 |
} |
90 |
} |