jsts-rails 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/jsts-rails/version.rb +1 -1
- data/vendor/assets/javascripts/javascript.util.js +33 -1
- data/vendor/assets/javascripts/jsts-original.js +164 -1573
- data/vendor/assets/javascripts/jsts.js +197 -0
- data/vendor/assets/javascripts/jsts/algorithm/Angle.js +387 -0
- data/vendor/assets/javascripts/jsts/algorithm/BoundaryNodeRule.js +67 -0
- data/vendor/assets/javascripts/jsts/algorithm/CGAlgorithms.js +596 -0
- data/vendor/assets/javascripts/jsts/algorithm/CentralEndpointIntersector.js +118 -0
- data/vendor/assets/javascripts/jsts/algorithm/CentroidArea.js +225 -0
- data/vendor/assets/javascripts/jsts/algorithm/CentroidLine.js +85 -0
- data/vendor/assets/javascripts/jsts/algorithm/CentroidPoint.js +77 -0
- data/vendor/assets/javascripts/jsts/algorithm/ConvexHull.js +409 -0
- data/vendor/assets/javascripts/jsts/algorithm/HCoordinate.js +234 -0
- data/vendor/assets/javascripts/jsts/algorithm/LineIntersector.js +502 -0
- data/vendor/assets/javascripts/jsts/algorithm/MCPointInRing.js +124 -0
- data/vendor/assets/javascripts/jsts/algorithm/PointLocator.js +247 -0
- data/vendor/assets/javascripts/jsts/algorithm/RayCrossingCounter.js +215 -0
- data/vendor/assets/javascripts/jsts/algorithm/RobustDeterminant.js +353 -0
- data/vendor/assets/javascripts/jsts/algorithm/RobustLineIntersector.js +477 -0
- data/vendor/assets/javascripts/jsts/algorithm/distance/DiscreteHausdorffDistance.js +228 -0
- data/vendor/assets/javascripts/jsts/algorithm/distance/DistanceToPoint.js +68 -0
- data/vendor/assets/javascripts/jsts/algorithm/distance/PointPairDistance.js +104 -0
- data/vendor/assets/javascripts/jsts/algorithm/locate/PointOnGeometryLocator.js +7 -0
- data/vendor/assets/javascripts/jsts/algorithm/locate/SimplePointInAreaLocator.js +102 -0
- data/vendor/assets/javascripts/jsts/geom/Coordinate.js +158 -0
- data/vendor/assets/javascripts/jsts/geom/CoordinateArrays.js +148 -0
- data/vendor/assets/javascripts/jsts/geom/CoordinateFilter.js +29 -0
- data/vendor/assets/javascripts/jsts/geom/CoordinateList.js +157 -0
- data/vendor/assets/javascripts/jsts/geom/CoordinateSequenceFilter.js +63 -0
- data/vendor/assets/javascripts/jsts/geom/Dimension.js +137 -0
- data/vendor/assets/javascripts/jsts/geom/Envelope.js +833 -0
- data/vendor/assets/javascripts/jsts/geom/Geometry.js +1535 -0
- data/vendor/assets/javascripts/jsts/geom/GeometryCollection.js +230 -0
- data/vendor/assets/javascripts/jsts/geom/GeometryComponentFilter.js +36 -0
- data/vendor/assets/javascripts/jsts/geom/GeometryFactory.js +263 -0
- data/vendor/assets/javascripts/jsts/geom/GeometryFilter.js +29 -0
- data/vendor/assets/javascripts/jsts/geom/IntersectionMatrix.js +650 -0
- data/vendor/assets/javascripts/jsts/geom/LineSegment.js +275 -0
- data/vendor/assets/javascripts/jsts/geom/LineString.js +299 -0
- data/vendor/assets/javascripts/jsts/geom/LinearRing.js +69 -0
- data/vendor/assets/javascripts/jsts/geom/Location.js +83 -0
- data/vendor/assets/javascripts/jsts/geom/MultiLineString.js +47 -0
- data/vendor/assets/javascripts/jsts/geom/MultiPoint.js +64 -0
- data/vendor/assets/javascripts/jsts/geom/MultiPolygon.js +64 -0
- data/vendor/assets/javascripts/jsts/geom/Point.js +197 -0
- data/vendor/assets/javascripts/jsts/geom/Polygon.js +263 -0
- data/vendor/assets/javascripts/jsts/geom/PrecisionModel.js +187 -0
- data/vendor/assets/javascripts/jsts/geom/Triangle.js +313 -0
- data/vendor/assets/javascripts/jsts/geom/util/GeometryCombiner.js +143 -0
- data/vendor/assets/javascripts/jsts/geom/util/GeometryExtracter.js +76 -0
- data/vendor/assets/javascripts/jsts/geom/util/GeometryTransformer.js +295 -0
- data/vendor/assets/javascripts/jsts/geom/util/LinearComponentExtracter.js +207 -0
- data/vendor/assets/javascripts/jsts/geom/util/PointExtracter.js +67 -0
- data/vendor/assets/javascripts/jsts/geom/util/PolygonExtracter.js +71 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Depth.js +145 -0
- data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdge.js +270 -0
- data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdgeStar.js +388 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Edge.js +291 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeEnd.js +188 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeEndStar.js +322 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersection.js +122 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersectionList.js +146 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeList.js +111 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeNodingValidator.js +76 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeRing.js +230 -0
- data/vendor/assets/javascripts/jsts/geomgraph/GeometryGraph.js +469 -0
- data/vendor/assets/javascripts/jsts/geomgraph/GraphComponent.js +181 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Label.js +316 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Node.js +105 -0
- data/vendor/assets/javascripts/jsts/geomgraph/NodeFactory.js +22 -0
- data/vendor/assets/javascripts/jsts/geomgraph/NodeMap.js +128 -0
- data/vendor/assets/javascripts/jsts/geomgraph/PlanarGraph.js +214 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Position.js +63 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Quadrant.js +143 -0
- data/vendor/assets/javascripts/jsts/geomgraph/TopologyLocation.js +251 -0
- data/vendor/assets/javascripts/jsts/geomgraph/index/EdgeSetIntersector.js +47 -0
- data/vendor/assets/javascripts/jsts/geomgraph/index/SegmentIntersector.js +298 -0
- data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleEdgeSetIntersector.js +107 -0
- data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleMCSweepLineIntersector.js +29 -0
- data/vendor/assets/javascripts/jsts/index/ArrayListVisitor.js +37 -0
- data/vendor/assets/javascripts/jsts/index/DoubleBits.js +132 -0
- data/vendor/assets/javascripts/jsts/index/IntervalSize.js +55 -0
- data/vendor/assets/javascripts/jsts/index/ItemVisitor.js +23 -0
- data/vendor/assets/javascripts/jsts/index/SpatialIndex.js +67 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Bintree.js +224 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Interval.js +160 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Key.js +110 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Node.js +204 -0
- data/vendor/assets/javascripts/jsts/index/bintree/NodeBase.js +220 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Root.js +113 -0
- data/vendor/assets/javascripts/jsts/index/chain/MonotoneChain.js +244 -0
- data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainBuilder.js +106 -0
- data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainOverlapAction.js +56 -0
- data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainSelectAction.js +44 -0
- data/vendor/assets/javascripts/jsts/index/kdtree/KdNode.js +171 -0
- data/vendor/assets/javascripts/jsts/index/kdtree/KdTree.js +218 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/Key.js +134 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/Node.js +220 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/NodeBase.js +330 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/Quadtree.js +228 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/Root.js +105 -0
- data/vendor/assets/javascripts/jsts/index/strtree/AbstractNode.js +107 -0
- data/vendor/assets/javascripts/jsts/index/strtree/AbstractSTRtree.js +594 -0
- data/vendor/assets/javascripts/jsts/index/strtree/Boundable.js +37 -0
- data/vendor/assets/javascripts/jsts/index/strtree/BoundablePair.js +0 -0
- data/vendor/assets/javascripts/jsts/index/strtree/Interval.js +94 -0
- data/vendor/assets/javascripts/jsts/index/strtree/ItemBoundable.js +60 -0
- data/vendor/assets/javascripts/jsts/index/strtree/SIRtree.js +122 -0
- data/vendor/assets/javascripts/jsts/index/strtree/STRtree.js +450 -0
- data/vendor/assets/javascripts/jsts/io/GeoJSONParser.js +471 -0
- data/vendor/assets/javascripts/jsts/io/GeoJSONReader.js +58 -0
- data/vendor/assets/javascripts/jsts/io/GeoJSONWriter.js +38 -0
- data/vendor/assets/javascripts/jsts/io/OpenLayersParser.js +245 -0
- data/vendor/assets/javascripts/jsts/io/WKTParser.js +421 -0
- data/vendor/assets/javascripts/jsts/io/WKTReader.js +68 -0
- data/vendor/assets/javascripts/jsts/io/WKTWriter.js +61 -0
- data/vendor/assets/javascripts/jsts/noding/BasicSegmentString.js +87 -0
- data/vendor/assets/javascripts/jsts/noding/FastNodingValidator.js +127 -0
- data/vendor/assets/javascripts/jsts/noding/InteriorIntersectionFinder.js +171 -0
- data/vendor/assets/javascripts/jsts/noding/IntersectionAdder.js +198 -0
- data/vendor/assets/javascripts/jsts/noding/IntersectionFinderAdder.js +79 -0
- data/vendor/assets/javascripts/jsts/noding/MCIndexNoder.js +147 -0
- data/vendor/assets/javascripts/jsts/noding/NodableSegmentString.js +35 -0
- data/vendor/assets/javascripts/jsts/noding/NodedSegmentString.js +235 -0
- data/vendor/assets/javascripts/jsts/noding/Noder.js +41 -0
- data/vendor/assets/javascripts/jsts/noding/NodingValidator.js +5 -0
- data/vendor/assets/javascripts/jsts/noding/Octant.js +84 -0
- data/vendor/assets/javascripts/jsts/noding/OrientedCoordinateArray.js +94 -0
- data/vendor/assets/javascripts/jsts/noding/ScaledNoder.js +105 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentIntersector.js +45 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentNode.js +70 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentNodeList.js +262 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentPointComparator.js +78 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentString.js +61 -0
- data/vendor/assets/javascripts/jsts/noding/SinglePassNoder.js +51 -0
- data/vendor/assets/javascripts/jsts/noding/snapround/HotPixel.js +271 -0
- data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexPointSnapper.js +96 -0
- data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexSnapRounder.js +147 -0
- data/vendor/assets/javascripts/jsts/operation/BoundaryOp.js +166 -0
- data/vendor/assets/javascripts/jsts/operation/GeometryGraphOperation.js +90 -0
- data/vendor/assets/javascripts/jsts/operation/IsSimpleOp.js +293 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferBuilder.js +317 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferInputLineSimplifier.js +294 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferOp.js +340 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferParameters.js +328 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferSubgraph.js +296 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveBuilder.js +369 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveSetBuilder.js +301 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentGenerator.js +777 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentString.js +109 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/RightmostEdgeFinder.js +164 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/SubgraphDepthLocater.js +220 -0
- data/vendor/assets/javascripts/jsts/operation/distance/ConnectedElementLocationFilter.js +67 -0
- data/vendor/assets/javascripts/jsts/operation/distance/DistanceOp.js +506 -0
- data/vendor/assets/javascripts/jsts/operation/distance/GeometryLocation.js +102 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/LineBuilder.js +194 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/MaximalEdgeRing.js +72 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/MinimalEdgeRing.js +33 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/OverlayNodeFactory.js +26 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/OverlayOp.js +584 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/PointBuilder.js +103 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/PolygonBuilder.js +282 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/snap/GeometrySnapper.js +228 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/snap/LineStringSnapper.js +228 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapIfNeededOverlayOp.js +85 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapOverlayOp.js +134 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/EdgeRing.js +259 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeDirectedEdge.js +94 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeEdge.js +31 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeGraph.js +507 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/Polygonizer.js +259 -0
- data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBuilder.js +140 -0
- data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundle.js +183 -0
- data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundleStar.js +48 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateComputer.js +444 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateNode.js +46 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeFactory.js +25 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeGraph.js +118 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateOp.js +75 -0
- data/vendor/assets/javascripts/jsts/operation/union/CascadedPolygonUnion.js +319 -0
- data/vendor/assets/javascripts/jsts/operation/union/PointGeometryUnion.js +118 -0
- data/vendor/assets/javascripts/jsts/operation/union/UnaryUnionOp.js +244 -0
- data/vendor/assets/javascripts/jsts/operation/union/UnionInteracting.js +156 -0
- data/vendor/assets/javascripts/jsts/operation/valid/ConnectedInteriorTester.js +259 -0
- data/vendor/assets/javascripts/jsts/operation/valid/ConsistentAreaTester.js +127 -0
- data/vendor/assets/javascripts/jsts/operation/valid/IndexedNestedRingTester.js +89 -0
- data/vendor/assets/javascripts/jsts/operation/valid/IsValidOp.js +619 -0
- data/vendor/assets/javascripts/jsts/operation/valid/TopologyValidationError.js +199 -0
- data/vendor/assets/javascripts/jsts/planargraph/DirectedEdge.js +232 -0
- data/vendor/assets/javascripts/jsts/planargraph/DirectedEdgeStar.js +168 -0
- data/vendor/assets/javascripts/jsts/planargraph/Edge.js +124 -0
- data/vendor/assets/javascripts/jsts/planargraph/GraphComponent.js +182 -0
- data/vendor/assets/javascripts/jsts/planargraph/Node.js +127 -0
- data/vendor/assets/javascripts/jsts/planargraph/NodeMap.js +76 -0
- data/vendor/assets/javascripts/jsts/planargraph/PlanarGraph.js +246 -0
- data/vendor/assets/javascripts/jsts/simplify/LineSegmentIndex.js +101 -0
- data/vendor/assets/javascripts/jsts/triangulate/DelaunayTriangulationBuilder.js +224 -0
- data/vendor/assets/javascripts/jsts/triangulate/IncrementalDelaunayTriangulator.js +111 -0
- data/vendor/assets/javascripts/jsts/triangulate/VoronoiDiagramBuilder.js +172 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/LastFoundQuadEdgeLocator.js +52 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdge.js +437 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdgeSubdivision.js +1064 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/TrianglePredicate.js +350 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/Vertex.js +496 -0
- data/vendor/assets/javascripts/jsts/util/Assert.js +80 -0
- data/vendor/assets/javascripts/jsts/util/AssertionFailedException.js +23 -0
- data/vendor/assets/javascripts/jsts/util/UniqueCoordinateArrayFilter.js +52 -0
- metadata +204 -1
@@ -0,0 +1,259 @@
|
|
1
|
+
/* Copyright (c) 2011 by The Authors.
|
2
|
+
* Published under the LGPL 2.1 license.
|
3
|
+
* See /license-notice.txt for the full text of the license notice.
|
4
|
+
* See /license.txt for the full text of the license.
|
5
|
+
*/
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Port source:
|
9
|
+
* /jts/jts/java/src/com/vividsolutions/jts/operation/polygonize/Polygonizer.java
|
10
|
+
* Revision: 6
|
11
|
+
*/
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @requires jsts/geom/GeometryComponentFilter.js
|
15
|
+
* @requires jsts/geom/LineString.js
|
16
|
+
* @requires jsts/operation/polygonize/EdgeRing.js
|
17
|
+
* @requires jsts/operation/polygonize/PolygonizeGraph.js
|
18
|
+
*/
|
19
|
+
|
20
|
+
(function() {
|
21
|
+
|
22
|
+
var ArrayList = javascript.util.ArrayList;
|
23
|
+
var GeometryComponentFilter = jsts.geom.GeometryComponentFilter;
|
24
|
+
var LineString = jsts.geom.LineString;
|
25
|
+
var EdgeRing = jsts.operation.polygonize.EdgeRing;
|
26
|
+
var PolygonizeGraph = jsts.operation.polygonize.PolygonizeGraph;
|
27
|
+
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Polygonizes a set of {@link Geometry}s which contain linework that
|
31
|
+
* represents the edges of a planar graph. All types of Geometry are accepted
|
32
|
+
* as input; the constituent linework is extracted as the edges to be
|
33
|
+
* polygonized. The processed edges must be correctly noded; that is, they
|
34
|
+
* must only meet at their endpoints. The Polygonizer will run on incorrectly
|
35
|
+
* noded input but will not form polygons from non-noded edges, and will
|
36
|
+
* report them as errors.
|
37
|
+
* <p>
|
38
|
+
* The Polygonizer reports the follow kinds of errors:
|
39
|
+
* <ul>
|
40
|
+
* <li><b>Dangles</b> - edges which have one or both ends which are not
|
41
|
+
* incident on another edge endpoint
|
42
|
+
* <li><b>Cut Edges</b> - edges which are connected at both ends but which
|
43
|
+
* do not form part of polygon
|
44
|
+
* <li><b>Invalid Ring Lines</b> - edges which form rings which are invalid
|
45
|
+
* (e.g. the component lines contain a self-intersection)
|
46
|
+
* </ul>
|
47
|
+
*
|
48
|
+
* Create a polygonizer with the same {@link GeometryFactory} as the input
|
49
|
+
* {@link Geometry}s
|
50
|
+
*/
|
51
|
+
var Polygonizer = function() {
|
52
|
+
var that = this;
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Adds every linear element in a {@link Geometry} into the polygonizer graph.
|
56
|
+
*/
|
57
|
+
var LineStringAdder = function() {
|
58
|
+
|
59
|
+
};
|
60
|
+
|
61
|
+
LineStringAdder.prototype = new GeometryComponentFilter();
|
62
|
+
|
63
|
+
LineStringAdder.prototype.filter = function(g) {
|
64
|
+
if (g instanceof LineString)
|
65
|
+
that.add(g);
|
66
|
+
};
|
67
|
+
|
68
|
+
this.lineStringAdder = new LineStringAdder();
|
69
|
+
this.dangles = new ArrayList();
|
70
|
+
this.cutEdges = new ArrayList();
|
71
|
+
this.invalidRingLines = new ArrayList();
|
72
|
+
};
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
// default factory
|
77
|
+
Polygonizer.prototype.lineStringAdder = null;
|
78
|
+
|
79
|
+
Polygonizer.prototype.graph = null;
|
80
|
+
// initialize with empty collections, in case nothing is computed
|
81
|
+
Polygonizer.prototype.dangles = null;
|
82
|
+
Polygonizer.prototype.cutEdges = null;
|
83
|
+
Polygonizer.prototype.invalidRingLines = null;
|
84
|
+
|
85
|
+
Polygonizer.prototype.holeList = null;
|
86
|
+
Polygonizer.prototype.shellList = null;
|
87
|
+
Polygonizer.prototype.polyList = null;
|
88
|
+
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Adds a collection of geometries to the edges to be polygonized. May be
|
92
|
+
* called multiple times. Any dimension of Geometry may be added; the
|
93
|
+
* constituent linework will be extracted and used.
|
94
|
+
*
|
95
|
+
* @param geomList
|
96
|
+
* a list of {@link Geometry} s with linework to be polygonized.
|
97
|
+
*/
|
98
|
+
Polygonizer.prototype.add = function(geomList) {
|
99
|
+
if (geomList instanceof jsts.geom.LineString) {
|
100
|
+
return this.add3(geomList);
|
101
|
+
} else if (geomList instanceof jsts.geom.Geometry) {
|
102
|
+
return this.add2(geomList);
|
103
|
+
}
|
104
|
+
|
105
|
+
for (var i = geomList.iterator(); i.hasNext();) {
|
106
|
+
var geometry = i.next();
|
107
|
+
this.add2(geometry);
|
108
|
+
}
|
109
|
+
};
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Add a {@link Geometry} to the edges to be polygonized. May be called
|
113
|
+
* multiple times. Any dimension of Geometry may be added; the constituent
|
114
|
+
* linework will be extracted and used
|
115
|
+
*
|
116
|
+
* @param g
|
117
|
+
* a {@link Geometry} with linework to be polygonized.
|
118
|
+
*/
|
119
|
+
Polygonizer.prototype.add2 = function(g) {
|
120
|
+
g.apply(this.lineStringAdder);
|
121
|
+
};
|
122
|
+
|
123
|
+
/**
|
124
|
+
* Adds a linestring to the graph of polygon edges.
|
125
|
+
*
|
126
|
+
* @param line
|
127
|
+
* the {@link LineString} to add.
|
128
|
+
*/
|
129
|
+
Polygonizer.prototype.add3 = function(line) {
|
130
|
+
// create a new graph using the factory from the input Geometry
|
131
|
+
if (this.graph == null)
|
132
|
+
this.graph = new PolygonizeGraph(line.getFactory());
|
133
|
+
this.graph.addEdge(line);
|
134
|
+
};
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Gets the list of polygons formed by the polygonization.
|
138
|
+
*
|
139
|
+
* @return a collection of {@link Polygon} s.
|
140
|
+
*/
|
141
|
+
Polygonizer.prototype.getPolygons = function() {
|
142
|
+
this.polygonize();
|
143
|
+
return this.polyList;
|
144
|
+
};
|
145
|
+
|
146
|
+
/**
|
147
|
+
* Gets the list of dangling lines found during polygonization.
|
148
|
+
*
|
149
|
+
* @return a collection of the input {@link LineString} s which are dangles.
|
150
|
+
*/
|
151
|
+
Polygonizer.prototype.getDangles = function() {
|
152
|
+
this.polygonize();
|
153
|
+
return this.dangles;
|
154
|
+
};
|
155
|
+
|
156
|
+
/**
|
157
|
+
* Gets the list of cut edges found during polygonization.
|
158
|
+
*
|
159
|
+
* @return a collection of the input {@link LineString} s which are cut edges.
|
160
|
+
*/
|
161
|
+
Polygonizer.prototype.getCutEdges = function() {
|
162
|
+
this.polygonize();
|
163
|
+
return this.cutEdges;
|
164
|
+
};
|
165
|
+
|
166
|
+
/**
|
167
|
+
* Gets the list of lines forming invalid rings found during polygonization.
|
168
|
+
*
|
169
|
+
* @return a collection of the input {@link LineString} s which form invalid
|
170
|
+
* rings.
|
171
|
+
*/
|
172
|
+
Polygonizer.prototype.getInvalidRingLines = function() {
|
173
|
+
this.polygonize();
|
174
|
+
return this.invalidRingLines;
|
175
|
+
};
|
176
|
+
|
177
|
+
/**
|
178
|
+
* Performs the polygonization, if it has not already been carried out.
|
179
|
+
*/
|
180
|
+
Polygonizer.prototype.polygonize = function() {
|
181
|
+
// check if already computed
|
182
|
+
if (this.polyList != null)
|
183
|
+
return;
|
184
|
+
this.polyList = new ArrayList();
|
185
|
+
|
186
|
+
// if no geometries were supplied it's possible that graph is null
|
187
|
+
if (this.graph == null)
|
188
|
+
return;
|
189
|
+
|
190
|
+
this.dangles = this.graph.deleteDangles();
|
191
|
+
this.cutEdges = this.graph.deleteCutEdges();
|
192
|
+
var edgeRingList = this.graph.getEdgeRings();
|
193
|
+
|
194
|
+
var validEdgeRingList = new ArrayList();
|
195
|
+
this.invalidRingLines = new ArrayList();
|
196
|
+
this.findValidRings(edgeRingList, validEdgeRingList, this.invalidRingLines);
|
197
|
+
|
198
|
+
this.findShellsAndHoles(validEdgeRingList);
|
199
|
+
Polygonizer.assignHolesToShells(this.holeList, this.shellList);
|
200
|
+
|
201
|
+
this.polyList = new ArrayList();
|
202
|
+
for (var i = this.shellList.iterator(); i.hasNext();) {
|
203
|
+
var er = i.next();
|
204
|
+
this.polyList.add(er.getPolygon());
|
205
|
+
}
|
206
|
+
};
|
207
|
+
|
208
|
+
/**
|
209
|
+
* @private
|
210
|
+
*/
|
211
|
+
Polygonizer.prototype.findValidRings = function(edgeRingList,
|
212
|
+
validEdgeRingList, invalidRingList) {
|
213
|
+
for (var i = edgeRingList.iterator(); i.hasNext();) {
|
214
|
+
var er = i.next();
|
215
|
+
if (er.isValid())
|
216
|
+
validEdgeRingList.add(er);
|
217
|
+
else
|
218
|
+
invalidRingList.add(er.getLineString());
|
219
|
+
}
|
220
|
+
};
|
221
|
+
|
222
|
+
/**
|
223
|
+
* @private
|
224
|
+
*/
|
225
|
+
Polygonizer.prototype.findShellsAndHoles = function(edgeRingList) {
|
226
|
+
this.holeList = new ArrayList();
|
227
|
+
this.shellList = new ArrayList();
|
228
|
+
for (var i = edgeRingList.iterator(); i.hasNext();) {
|
229
|
+
var er = i.next();
|
230
|
+
if (er.isHole())
|
231
|
+
this.holeList.add(er);
|
232
|
+
else
|
233
|
+
this.shellList.add(er);
|
234
|
+
}
|
235
|
+
};
|
236
|
+
|
237
|
+
/**
|
238
|
+
* @private
|
239
|
+
*/
|
240
|
+
Polygonizer.assignHolesToShells = function(holeList, shellList) {
|
241
|
+
for (var i = holeList.iterator(); i.hasNext();) {
|
242
|
+
var holeER = i.next();
|
243
|
+
Polygonizer.assignHoleToShell(holeER, shellList);
|
244
|
+
}
|
245
|
+
};
|
246
|
+
|
247
|
+
/**
|
248
|
+
* @private
|
249
|
+
*/
|
250
|
+
Polygonizer.assignHoleToShell = function(holeER, shellList) {
|
251
|
+
var shell = EdgeRing.findEdgeRingContaining(holeER, shellList);
|
252
|
+
if (shell != null)
|
253
|
+
shell.addHole(holeER.getRing());
|
254
|
+
};
|
255
|
+
|
256
|
+
|
257
|
+
jsts.operation.polygonize.Polygonizer = Polygonizer;
|
258
|
+
|
259
|
+
})();
|
@@ -0,0 +1,140 @@
|
|
1
|
+
/* Copyright (c) 2011 by The Authors.
|
2
|
+
* Published under the LGPL 2.1 license.
|
3
|
+
* See /license-notice.txt for the full text of the license notice.
|
4
|
+
* See /license.txt for the full text of the license.
|
5
|
+
*/
|
6
|
+
|
7
|
+
(function() {
|
8
|
+
|
9
|
+
/**
|
10
|
+
* @requires jsts/util/Assert.js
|
11
|
+
*/
|
12
|
+
|
13
|
+
var ArrayList = javascript.util.ArrayList;
|
14
|
+
|
15
|
+
|
16
|
+
/**
|
17
|
+
* An EdgeEndBuilder creates EdgeEnds for all the "split edges" created by the
|
18
|
+
* intersections determined for an Edge.
|
19
|
+
*
|
20
|
+
* Computes the {@link EdgeEnd}s which arise from a noded {@link Edge}.
|
21
|
+
*
|
22
|
+
* @constructor
|
23
|
+
*/
|
24
|
+
jsts.operation.relate.EdgeEndBuilder = function() {
|
25
|
+
|
26
|
+
};
|
27
|
+
|
28
|
+
|
29
|
+
jsts.operation.relate.EdgeEndBuilder.prototype.computeEdgeEnds = function(edges) {
|
30
|
+
if (arguments.length == 2) {
|
31
|
+
this.computeEdgeEnds2.apply(this, arguments);
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
|
35
|
+
var l = new ArrayList();
|
36
|
+
for (var i = edges; i.hasNext();) {
|
37
|
+
var e = i.next();
|
38
|
+
this.computeEdgeEnds2(e, l);
|
39
|
+
}
|
40
|
+
return l;
|
41
|
+
};
|
42
|
+
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Creates stub edges for all the intersections in this Edge (if any) and
|
46
|
+
* inserts them into the graph.
|
47
|
+
*/
|
48
|
+
jsts.operation.relate.EdgeEndBuilder.prototype.computeEdgeEnds2 = function(edge, l) {
|
49
|
+
var eiList = edge.getEdgeIntersectionList();
|
50
|
+
// ensure that the list has entries for the first and last point of the edge
|
51
|
+
eiList.addEndpoints();
|
52
|
+
|
53
|
+
var it = eiList.iterator();
|
54
|
+
var eiPrev = null;
|
55
|
+
var eiCurr = null;
|
56
|
+
// no intersections, so there is nothing to do
|
57
|
+
if (!it.hasNext())
|
58
|
+
return;
|
59
|
+
var eiNext = it.next();
|
60
|
+
do {
|
61
|
+
eiPrev = eiCurr;
|
62
|
+
eiCurr = eiNext;
|
63
|
+
eiNext = null;
|
64
|
+
if (it.hasNext())
|
65
|
+
eiNext = it.next();
|
66
|
+
|
67
|
+
if (eiCurr !== null) {
|
68
|
+
this.createEdgeEndForPrev(edge, l, eiCurr, eiPrev);
|
69
|
+
this.createEdgeEndForNext(edge, l, eiCurr, eiNext);
|
70
|
+
}
|
71
|
+
|
72
|
+
} while (eiCurr !== null);
|
73
|
+
};
|
74
|
+
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Create a EdgeStub for the edge before the intersection eiCurr. The previous
|
78
|
+
* intersection is provided in case it is the endpoint for the stub edge.
|
79
|
+
* Otherwise, the previous point from the parent edge will be the endpoint.
|
80
|
+
* <br>
|
81
|
+
* eiCurr will always be an EdgeIntersection, but eiPrev may be null.
|
82
|
+
*
|
83
|
+
* @private
|
84
|
+
*/
|
85
|
+
jsts.operation.relate.EdgeEndBuilder.prototype.createEdgeEndForPrev = function(edge, l, eiCurr,
|
86
|
+
eiPrev) {
|
87
|
+
|
88
|
+
var iPrev = eiCurr.segmentIndex;
|
89
|
+
if (eiCurr.dist === 0.0) {
|
90
|
+
// if at the start of the edge there is no previous edge
|
91
|
+
if (iPrev === 0)
|
92
|
+
return;
|
93
|
+
iPrev--;
|
94
|
+
}
|
95
|
+
var pPrev = edge.getCoordinate(iPrev);
|
96
|
+
// if prev intersection is past the previous vertex, use it instead
|
97
|
+
if (eiPrev !== null && eiPrev.segmentIndex >= iPrev)
|
98
|
+
pPrev = eiPrev.coord;
|
99
|
+
|
100
|
+
var label = new jsts.geomgraph.Label(edge.getLabel());
|
101
|
+
// since edgeStub is oriented opposite to it's parent edge, have to flip
|
102
|
+
// sides
|
103
|
+
// for edge label
|
104
|
+
label.flip();
|
105
|
+
var e = new jsts.geomgraph.EdgeEnd(edge, eiCurr.coord, pPrev, label);
|
106
|
+
// e.print(System.out); System.out.println();
|
107
|
+
l.add(e);
|
108
|
+
};
|
109
|
+
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Create a StubEdge for the edge after the intersection eiCurr. The next
|
113
|
+
* intersection is provided in case it is the endpoint for the stub edge.
|
114
|
+
* Otherwise, the next point from the parent edge will be the endpoint. <br>
|
115
|
+
* eiCurr will always be an EdgeIntersection, but eiNext may be null.
|
116
|
+
*
|
117
|
+
* @private
|
118
|
+
*/
|
119
|
+
jsts.operation.relate.EdgeEndBuilder.prototype.createEdgeEndForNext = function(edge, l, eiCurr,
|
120
|
+
eiNext) {
|
121
|
+
|
122
|
+
var iNext = eiCurr.segmentIndex + 1;
|
123
|
+
// if there is no next edge there is nothing to do
|
124
|
+
if (iNext >= edge.getNumPoints() && eiNext === null)
|
125
|
+
return;
|
126
|
+
|
127
|
+
var pNext = edge.getCoordinate(iNext);
|
128
|
+
|
129
|
+
// if the next intersection is in the same segment as the current, use it as
|
130
|
+
// the endpoint
|
131
|
+
if (eiNext !== null && eiNext.segmentIndex === eiCurr.segmentIndex)
|
132
|
+
pNext = eiNext.coord;
|
133
|
+
|
134
|
+
var e = new jsts.geomgraph.EdgeEnd(edge, eiCurr.coord, pNext,
|
135
|
+
new jsts.geomgraph.Label(edge.getLabel()));
|
136
|
+
l.add(e);
|
137
|
+
};
|
138
|
+
|
139
|
+
|
140
|
+
})();
|
@@ -0,0 +1,183 @@
|
|
1
|
+
/* Copyright (c) 2011 by The Authors.
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @requires jsts/geomgraph/EdgeEnd.js
|
5
|
+
*/
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
/**
|
10
|
+
* A collection of {@link EdgeEnd}s which obey the following invariant:
|
11
|
+
* They originate at the same node and have the same direction.
|
12
|
+
*
|
13
|
+
* @augments {jsts.geomgraph.EdgeEnd}
|
14
|
+
* @constructor
|
15
|
+
*/
|
16
|
+
jsts.operation.relate.EdgeEndBundle = function() {
|
17
|
+
this.edgeEnds = [];
|
18
|
+
|
19
|
+
var e = arguments[0] instanceof jsts.geomgraph.EdgeEnd ? arguments[0] : arguments[1];
|
20
|
+
|
21
|
+
var edge = e.getEdge();
|
22
|
+
var coord = e.getCoordinate();
|
23
|
+
var dirCoord = e.getDirectedCoordinate();
|
24
|
+
var label = new jsts.geomgraph.Label(e.getLabel());
|
25
|
+
|
26
|
+
jsts.geomgraph.EdgeEnd.call(this, edge, coord,
|
27
|
+
dirCoord, label);
|
28
|
+
|
29
|
+
this.insert(e);
|
30
|
+
};
|
31
|
+
|
32
|
+
jsts.operation.relate.EdgeEndBundle.prototype = new jsts.geomgraph.EdgeEnd();
|
33
|
+
|
34
|
+
|
35
|
+
/**
|
36
|
+
* @private
|
37
|
+
*/
|
38
|
+
jsts.operation.relate.EdgeEndBundle.prototype.edgeEnds = null;
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
jsts.operation.relate.EdgeEndBundle.prototype.getLabel = function() {
|
43
|
+
return this.label;
|
44
|
+
};
|
45
|
+
jsts.operation.relate.EdgeEndBundle.prototype.getEdgeEnds = function() {
|
46
|
+
return this.edgeEnds;
|
47
|
+
};
|
48
|
+
|
49
|
+
jsts.operation.relate.EdgeEndBundle.prototype.insert = function(e) {
|
50
|
+
// Assert: start point is the same
|
51
|
+
// Assert: direction is the same
|
52
|
+
this.edgeEnds.push(e);
|
53
|
+
};
|
54
|
+
|
55
|
+
|
56
|
+
/**
|
57
|
+
* This computes the overall edge label for the set of edges in this
|
58
|
+
* EdgeStubBundle. It essentially merges the ON and side labels for each edge.
|
59
|
+
* These labels must be compatible
|
60
|
+
*/
|
61
|
+
jsts.operation.relate.EdgeEndBundle.prototype.computeLabel = function(
|
62
|
+
boundaryNodeRule) {
|
63
|
+
// create the label. If any of the edges belong to areas,
|
64
|
+
// the label must be an area label
|
65
|
+
var isArea = false;
|
66
|
+
for (var i = 0; i < this.edgeEnds.length; i++) {
|
67
|
+
var e = this.edgeEnds[i];
|
68
|
+
if (e.getLabel().isArea())
|
69
|
+
isArea = true;
|
70
|
+
}
|
71
|
+
if (isArea)
|
72
|
+
this.label = new jsts.geomgraph.Label(jsts.geom.Location.NONE, jsts.geom.Location.NONE,
|
73
|
+
jsts.geom.Location.NONE);
|
74
|
+
else
|
75
|
+
this.label = new jsts.geomgraph.Label(jsts.geom.Location.NONE);
|
76
|
+
|
77
|
+
// compute the On label, and the side labels if present
|
78
|
+
for (var i = 0; i < 2; i++) {
|
79
|
+
this.computeLabelOn(i, boundaryNodeRule);
|
80
|
+
if (isArea)
|
81
|
+
this.computeLabelSides(i);
|
82
|
+
}
|
83
|
+
};
|
84
|
+
|
85
|
+
|
86
|
+
/**
|
87
|
+
* Compute the overall ON location for the list of EdgeStubs. (This is
|
88
|
+
* essentially equivalent to computing the self-overlay of a single Geometry)
|
89
|
+
* edgeStubs can be either on the boundary (eg Polygon edge) OR in the interior
|
90
|
+
* (e.g. segment of a LineString) of their parent Geometry. In addition,
|
91
|
+
* GeometryCollections use a {@link BoundaryNodeRule} to determine whether a
|
92
|
+
* segment is on the boundary or not. Finally, in GeometryCollections it can
|
93
|
+
* occur that an edge is both on the boundary and in the interior (e.g. a
|
94
|
+
* LineString segment lying on top of a Polygon edge.) In this case the Boundary
|
95
|
+
* is given precendence. <br>
|
96
|
+
* These observations result in the following rules for computing the ON
|
97
|
+
* location:
|
98
|
+
* <ul>
|
99
|
+
* <li> if there are an odd number of Bdy edges, the attribute is Bdy
|
100
|
+
* <li> if there are an even number >= 2 of Bdy edges, the attribute is Int
|
101
|
+
* <li> if there are any Int edges, the attribute is Int
|
102
|
+
* <li> otherwise, the attribute is NULL.
|
103
|
+
* </ul>
|
104
|
+
*
|
105
|
+
* @private
|
106
|
+
*/
|
107
|
+
jsts.operation.relate.EdgeEndBundle.prototype.computeLabelOn = function(
|
108
|
+
geomIndex, boundaryNodeRule) {
|
109
|
+
// compute the ON location value
|
110
|
+
var boundaryCount = 0;
|
111
|
+
var foundInterior = false;
|
112
|
+
|
113
|
+
for (var i = 0; i < this.edgeEnds.length; i++) {
|
114
|
+
var e = this.edgeEnds[i];
|
115
|
+
var loc = e.getLabel().getLocation(geomIndex);
|
116
|
+
if (loc == jsts.geom.Location.BOUNDARY)
|
117
|
+
boundaryCount++;
|
118
|
+
if (loc == jsts.geom.Location.INTERIOR)
|
119
|
+
foundInterior = true;
|
120
|
+
}
|
121
|
+
var loc = jsts.geom.Location.NONE;
|
122
|
+
if (foundInterior)
|
123
|
+
loc = jsts.geom.Location.INTERIOR;
|
124
|
+
if (boundaryCount > 0) {
|
125
|
+
loc = jsts.geomgraph.GeometryGraph.determineBoundary(boundaryNodeRule,
|
126
|
+
boundaryCount);
|
127
|
+
}
|
128
|
+
this.label.setLocation(geomIndex, loc);
|
129
|
+
|
130
|
+
};
|
131
|
+
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Compute the labelling for each side
|
135
|
+
*
|
136
|
+
* @private
|
137
|
+
*/
|
138
|
+
jsts.operation.relate.EdgeEndBundle.prototype.computeLabelSides = function(
|
139
|
+
geomIndex) {
|
140
|
+
this.computeLabelSide(geomIndex, jsts.geomgraph.Position.LEFT);
|
141
|
+
this.computeLabelSide(geomIndex, jsts.geomgraph.Position.RIGHT);
|
142
|
+
};
|
143
|
+
|
144
|
+
|
145
|
+
/**
|
146
|
+
* To compute the summary label for a side, the algorithm is: FOR all edges IF
|
147
|
+
* any edge's location is INTERIOR for the side, side location = INTERIOR ELSE
|
148
|
+
* IF there is at least one EXTERIOR attribute, side location = EXTERIOR ELSE
|
149
|
+
* side location = NULL <br>
|
150
|
+
* Note that it is possible for two sides to have apparently contradictory
|
151
|
+
* information i.e. one edge side may indicate that it is in the interior of a
|
152
|
+
* geometry, while another edge side may indicate the exterior of the same
|
153
|
+
* geometry. This is not an incompatibility - GeometryCollections may contain
|
154
|
+
* two Polygons that touch along an edge. This is the reason for
|
155
|
+
* Interior-primacy rule above - it results in the summary label having the
|
156
|
+
* Geometry interior on <b>both</b> sides.
|
157
|
+
*
|
158
|
+
* @private
|
159
|
+
*/
|
160
|
+
jsts.operation.relate.EdgeEndBundle.prototype.computeLabelSide = function(
|
161
|
+
geomIndex, side) {
|
162
|
+
for (var i = 0; i < this.edgeEnds.length; i++) {
|
163
|
+
var e = this.edgeEnds[i];
|
164
|
+
if (e.getLabel().isArea()) {
|
165
|
+
var loc = e.getLabel().getLocation(geomIndex, side);
|
166
|
+
if (loc === jsts.geom.Location.INTERIOR) {
|
167
|
+
this.label.setLocation(geomIndex, side, jsts.geom.Location.INTERIOR);
|
168
|
+
return;
|
169
|
+
} else if (loc === jsts.geom.Location.EXTERIOR)
|
170
|
+
this.label.setLocation(geomIndex, side, jsts.geom.Location.EXTERIOR);
|
171
|
+
}
|
172
|
+
}
|
173
|
+
};
|
174
|
+
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Update the IM with the contribution for the computed label for the EdgeStubs.
|
178
|
+
*
|
179
|
+
* @private
|
180
|
+
*/
|
181
|
+
jsts.operation.relate.EdgeEndBundle.prototype.updateIM = function(im) {
|
182
|
+
jsts.geomgraph.Edge.updateIM(this.label, im);
|
183
|
+
};
|