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.
Files changed (209) hide show
  1. checksums.yaml +8 -8
  2. data/lib/jsts-rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/javascript.util.js +33 -1
  4. data/vendor/assets/javascripts/jsts-original.js +164 -1573
  5. data/vendor/assets/javascripts/jsts.js +197 -0
  6. data/vendor/assets/javascripts/jsts/algorithm/Angle.js +387 -0
  7. data/vendor/assets/javascripts/jsts/algorithm/BoundaryNodeRule.js +67 -0
  8. data/vendor/assets/javascripts/jsts/algorithm/CGAlgorithms.js +596 -0
  9. data/vendor/assets/javascripts/jsts/algorithm/CentralEndpointIntersector.js +118 -0
  10. data/vendor/assets/javascripts/jsts/algorithm/CentroidArea.js +225 -0
  11. data/vendor/assets/javascripts/jsts/algorithm/CentroidLine.js +85 -0
  12. data/vendor/assets/javascripts/jsts/algorithm/CentroidPoint.js +77 -0
  13. data/vendor/assets/javascripts/jsts/algorithm/ConvexHull.js +409 -0
  14. data/vendor/assets/javascripts/jsts/algorithm/HCoordinate.js +234 -0
  15. data/vendor/assets/javascripts/jsts/algorithm/LineIntersector.js +502 -0
  16. data/vendor/assets/javascripts/jsts/algorithm/MCPointInRing.js +124 -0
  17. data/vendor/assets/javascripts/jsts/algorithm/PointLocator.js +247 -0
  18. data/vendor/assets/javascripts/jsts/algorithm/RayCrossingCounter.js +215 -0
  19. data/vendor/assets/javascripts/jsts/algorithm/RobustDeterminant.js +353 -0
  20. data/vendor/assets/javascripts/jsts/algorithm/RobustLineIntersector.js +477 -0
  21. data/vendor/assets/javascripts/jsts/algorithm/distance/DiscreteHausdorffDistance.js +228 -0
  22. data/vendor/assets/javascripts/jsts/algorithm/distance/DistanceToPoint.js +68 -0
  23. data/vendor/assets/javascripts/jsts/algorithm/distance/PointPairDistance.js +104 -0
  24. data/vendor/assets/javascripts/jsts/algorithm/locate/PointOnGeometryLocator.js +7 -0
  25. data/vendor/assets/javascripts/jsts/algorithm/locate/SimplePointInAreaLocator.js +102 -0
  26. data/vendor/assets/javascripts/jsts/geom/Coordinate.js +158 -0
  27. data/vendor/assets/javascripts/jsts/geom/CoordinateArrays.js +148 -0
  28. data/vendor/assets/javascripts/jsts/geom/CoordinateFilter.js +29 -0
  29. data/vendor/assets/javascripts/jsts/geom/CoordinateList.js +157 -0
  30. data/vendor/assets/javascripts/jsts/geom/CoordinateSequenceFilter.js +63 -0
  31. data/vendor/assets/javascripts/jsts/geom/Dimension.js +137 -0
  32. data/vendor/assets/javascripts/jsts/geom/Envelope.js +833 -0
  33. data/vendor/assets/javascripts/jsts/geom/Geometry.js +1535 -0
  34. data/vendor/assets/javascripts/jsts/geom/GeometryCollection.js +230 -0
  35. data/vendor/assets/javascripts/jsts/geom/GeometryComponentFilter.js +36 -0
  36. data/vendor/assets/javascripts/jsts/geom/GeometryFactory.js +263 -0
  37. data/vendor/assets/javascripts/jsts/geom/GeometryFilter.js +29 -0
  38. data/vendor/assets/javascripts/jsts/geom/IntersectionMatrix.js +650 -0
  39. data/vendor/assets/javascripts/jsts/geom/LineSegment.js +275 -0
  40. data/vendor/assets/javascripts/jsts/geom/LineString.js +299 -0
  41. data/vendor/assets/javascripts/jsts/geom/LinearRing.js +69 -0
  42. data/vendor/assets/javascripts/jsts/geom/Location.js +83 -0
  43. data/vendor/assets/javascripts/jsts/geom/MultiLineString.js +47 -0
  44. data/vendor/assets/javascripts/jsts/geom/MultiPoint.js +64 -0
  45. data/vendor/assets/javascripts/jsts/geom/MultiPolygon.js +64 -0
  46. data/vendor/assets/javascripts/jsts/geom/Point.js +197 -0
  47. data/vendor/assets/javascripts/jsts/geom/Polygon.js +263 -0
  48. data/vendor/assets/javascripts/jsts/geom/PrecisionModel.js +187 -0
  49. data/vendor/assets/javascripts/jsts/geom/Triangle.js +313 -0
  50. data/vendor/assets/javascripts/jsts/geom/util/GeometryCombiner.js +143 -0
  51. data/vendor/assets/javascripts/jsts/geom/util/GeometryExtracter.js +76 -0
  52. data/vendor/assets/javascripts/jsts/geom/util/GeometryTransformer.js +295 -0
  53. data/vendor/assets/javascripts/jsts/geom/util/LinearComponentExtracter.js +207 -0
  54. data/vendor/assets/javascripts/jsts/geom/util/PointExtracter.js +67 -0
  55. data/vendor/assets/javascripts/jsts/geom/util/PolygonExtracter.js +71 -0
  56. data/vendor/assets/javascripts/jsts/geomgraph/Depth.js +145 -0
  57. data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdge.js +270 -0
  58. data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdgeStar.js +388 -0
  59. data/vendor/assets/javascripts/jsts/geomgraph/Edge.js +291 -0
  60. data/vendor/assets/javascripts/jsts/geomgraph/EdgeEnd.js +188 -0
  61. data/vendor/assets/javascripts/jsts/geomgraph/EdgeEndStar.js +322 -0
  62. data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersection.js +122 -0
  63. data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersectionList.js +146 -0
  64. data/vendor/assets/javascripts/jsts/geomgraph/EdgeList.js +111 -0
  65. data/vendor/assets/javascripts/jsts/geomgraph/EdgeNodingValidator.js +76 -0
  66. data/vendor/assets/javascripts/jsts/geomgraph/EdgeRing.js +230 -0
  67. data/vendor/assets/javascripts/jsts/geomgraph/GeometryGraph.js +469 -0
  68. data/vendor/assets/javascripts/jsts/geomgraph/GraphComponent.js +181 -0
  69. data/vendor/assets/javascripts/jsts/geomgraph/Label.js +316 -0
  70. data/vendor/assets/javascripts/jsts/geomgraph/Node.js +105 -0
  71. data/vendor/assets/javascripts/jsts/geomgraph/NodeFactory.js +22 -0
  72. data/vendor/assets/javascripts/jsts/geomgraph/NodeMap.js +128 -0
  73. data/vendor/assets/javascripts/jsts/geomgraph/PlanarGraph.js +214 -0
  74. data/vendor/assets/javascripts/jsts/geomgraph/Position.js +63 -0
  75. data/vendor/assets/javascripts/jsts/geomgraph/Quadrant.js +143 -0
  76. data/vendor/assets/javascripts/jsts/geomgraph/TopologyLocation.js +251 -0
  77. data/vendor/assets/javascripts/jsts/geomgraph/index/EdgeSetIntersector.js +47 -0
  78. data/vendor/assets/javascripts/jsts/geomgraph/index/SegmentIntersector.js +298 -0
  79. data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleEdgeSetIntersector.js +107 -0
  80. data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleMCSweepLineIntersector.js +29 -0
  81. data/vendor/assets/javascripts/jsts/index/ArrayListVisitor.js +37 -0
  82. data/vendor/assets/javascripts/jsts/index/DoubleBits.js +132 -0
  83. data/vendor/assets/javascripts/jsts/index/IntervalSize.js +55 -0
  84. data/vendor/assets/javascripts/jsts/index/ItemVisitor.js +23 -0
  85. data/vendor/assets/javascripts/jsts/index/SpatialIndex.js +67 -0
  86. data/vendor/assets/javascripts/jsts/index/bintree/Bintree.js +224 -0
  87. data/vendor/assets/javascripts/jsts/index/bintree/Interval.js +160 -0
  88. data/vendor/assets/javascripts/jsts/index/bintree/Key.js +110 -0
  89. data/vendor/assets/javascripts/jsts/index/bintree/Node.js +204 -0
  90. data/vendor/assets/javascripts/jsts/index/bintree/NodeBase.js +220 -0
  91. data/vendor/assets/javascripts/jsts/index/bintree/Root.js +113 -0
  92. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChain.js +244 -0
  93. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainBuilder.js +106 -0
  94. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainOverlapAction.js +56 -0
  95. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainSelectAction.js +44 -0
  96. data/vendor/assets/javascripts/jsts/index/kdtree/KdNode.js +171 -0
  97. data/vendor/assets/javascripts/jsts/index/kdtree/KdTree.js +218 -0
  98. data/vendor/assets/javascripts/jsts/index/quadtree/Key.js +134 -0
  99. data/vendor/assets/javascripts/jsts/index/quadtree/Node.js +220 -0
  100. data/vendor/assets/javascripts/jsts/index/quadtree/NodeBase.js +330 -0
  101. data/vendor/assets/javascripts/jsts/index/quadtree/Quadtree.js +228 -0
  102. data/vendor/assets/javascripts/jsts/index/quadtree/Root.js +105 -0
  103. data/vendor/assets/javascripts/jsts/index/strtree/AbstractNode.js +107 -0
  104. data/vendor/assets/javascripts/jsts/index/strtree/AbstractSTRtree.js +594 -0
  105. data/vendor/assets/javascripts/jsts/index/strtree/Boundable.js +37 -0
  106. data/vendor/assets/javascripts/jsts/index/strtree/BoundablePair.js +0 -0
  107. data/vendor/assets/javascripts/jsts/index/strtree/Interval.js +94 -0
  108. data/vendor/assets/javascripts/jsts/index/strtree/ItemBoundable.js +60 -0
  109. data/vendor/assets/javascripts/jsts/index/strtree/SIRtree.js +122 -0
  110. data/vendor/assets/javascripts/jsts/index/strtree/STRtree.js +450 -0
  111. data/vendor/assets/javascripts/jsts/io/GeoJSONParser.js +471 -0
  112. data/vendor/assets/javascripts/jsts/io/GeoJSONReader.js +58 -0
  113. data/vendor/assets/javascripts/jsts/io/GeoJSONWriter.js +38 -0
  114. data/vendor/assets/javascripts/jsts/io/OpenLayersParser.js +245 -0
  115. data/vendor/assets/javascripts/jsts/io/WKTParser.js +421 -0
  116. data/vendor/assets/javascripts/jsts/io/WKTReader.js +68 -0
  117. data/vendor/assets/javascripts/jsts/io/WKTWriter.js +61 -0
  118. data/vendor/assets/javascripts/jsts/noding/BasicSegmentString.js +87 -0
  119. data/vendor/assets/javascripts/jsts/noding/FastNodingValidator.js +127 -0
  120. data/vendor/assets/javascripts/jsts/noding/InteriorIntersectionFinder.js +171 -0
  121. data/vendor/assets/javascripts/jsts/noding/IntersectionAdder.js +198 -0
  122. data/vendor/assets/javascripts/jsts/noding/IntersectionFinderAdder.js +79 -0
  123. data/vendor/assets/javascripts/jsts/noding/MCIndexNoder.js +147 -0
  124. data/vendor/assets/javascripts/jsts/noding/NodableSegmentString.js +35 -0
  125. data/vendor/assets/javascripts/jsts/noding/NodedSegmentString.js +235 -0
  126. data/vendor/assets/javascripts/jsts/noding/Noder.js +41 -0
  127. data/vendor/assets/javascripts/jsts/noding/NodingValidator.js +5 -0
  128. data/vendor/assets/javascripts/jsts/noding/Octant.js +84 -0
  129. data/vendor/assets/javascripts/jsts/noding/OrientedCoordinateArray.js +94 -0
  130. data/vendor/assets/javascripts/jsts/noding/ScaledNoder.js +105 -0
  131. data/vendor/assets/javascripts/jsts/noding/SegmentIntersector.js +45 -0
  132. data/vendor/assets/javascripts/jsts/noding/SegmentNode.js +70 -0
  133. data/vendor/assets/javascripts/jsts/noding/SegmentNodeList.js +262 -0
  134. data/vendor/assets/javascripts/jsts/noding/SegmentPointComparator.js +78 -0
  135. data/vendor/assets/javascripts/jsts/noding/SegmentString.js +61 -0
  136. data/vendor/assets/javascripts/jsts/noding/SinglePassNoder.js +51 -0
  137. data/vendor/assets/javascripts/jsts/noding/snapround/HotPixel.js +271 -0
  138. data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexPointSnapper.js +96 -0
  139. data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexSnapRounder.js +147 -0
  140. data/vendor/assets/javascripts/jsts/operation/BoundaryOp.js +166 -0
  141. data/vendor/assets/javascripts/jsts/operation/GeometryGraphOperation.js +90 -0
  142. data/vendor/assets/javascripts/jsts/operation/IsSimpleOp.js +293 -0
  143. data/vendor/assets/javascripts/jsts/operation/buffer/BufferBuilder.js +317 -0
  144. data/vendor/assets/javascripts/jsts/operation/buffer/BufferInputLineSimplifier.js +294 -0
  145. data/vendor/assets/javascripts/jsts/operation/buffer/BufferOp.js +340 -0
  146. data/vendor/assets/javascripts/jsts/operation/buffer/BufferParameters.js +328 -0
  147. data/vendor/assets/javascripts/jsts/operation/buffer/BufferSubgraph.js +296 -0
  148. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveBuilder.js +369 -0
  149. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveSetBuilder.js +301 -0
  150. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentGenerator.js +777 -0
  151. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentString.js +109 -0
  152. data/vendor/assets/javascripts/jsts/operation/buffer/RightmostEdgeFinder.js +164 -0
  153. data/vendor/assets/javascripts/jsts/operation/buffer/SubgraphDepthLocater.js +220 -0
  154. data/vendor/assets/javascripts/jsts/operation/distance/ConnectedElementLocationFilter.js +67 -0
  155. data/vendor/assets/javascripts/jsts/operation/distance/DistanceOp.js +506 -0
  156. data/vendor/assets/javascripts/jsts/operation/distance/GeometryLocation.js +102 -0
  157. data/vendor/assets/javascripts/jsts/operation/overlay/LineBuilder.js +194 -0
  158. data/vendor/assets/javascripts/jsts/operation/overlay/MaximalEdgeRing.js +72 -0
  159. data/vendor/assets/javascripts/jsts/operation/overlay/MinimalEdgeRing.js +33 -0
  160. data/vendor/assets/javascripts/jsts/operation/overlay/OverlayNodeFactory.js +26 -0
  161. data/vendor/assets/javascripts/jsts/operation/overlay/OverlayOp.js +584 -0
  162. data/vendor/assets/javascripts/jsts/operation/overlay/PointBuilder.js +103 -0
  163. data/vendor/assets/javascripts/jsts/operation/overlay/PolygonBuilder.js +282 -0
  164. data/vendor/assets/javascripts/jsts/operation/overlay/snap/GeometrySnapper.js +228 -0
  165. data/vendor/assets/javascripts/jsts/operation/overlay/snap/LineStringSnapper.js +228 -0
  166. data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapIfNeededOverlayOp.js +85 -0
  167. data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapOverlayOp.js +134 -0
  168. data/vendor/assets/javascripts/jsts/operation/polygonize/EdgeRing.js +259 -0
  169. data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeDirectedEdge.js +94 -0
  170. data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeEdge.js +31 -0
  171. data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeGraph.js +507 -0
  172. data/vendor/assets/javascripts/jsts/operation/polygonize/Polygonizer.js +259 -0
  173. data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBuilder.js +140 -0
  174. data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundle.js +183 -0
  175. data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundleStar.js +48 -0
  176. data/vendor/assets/javascripts/jsts/operation/relate/RelateComputer.js +444 -0
  177. data/vendor/assets/javascripts/jsts/operation/relate/RelateNode.js +46 -0
  178. data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeFactory.js +25 -0
  179. data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeGraph.js +118 -0
  180. data/vendor/assets/javascripts/jsts/operation/relate/RelateOp.js +75 -0
  181. data/vendor/assets/javascripts/jsts/operation/union/CascadedPolygonUnion.js +319 -0
  182. data/vendor/assets/javascripts/jsts/operation/union/PointGeometryUnion.js +118 -0
  183. data/vendor/assets/javascripts/jsts/operation/union/UnaryUnionOp.js +244 -0
  184. data/vendor/assets/javascripts/jsts/operation/union/UnionInteracting.js +156 -0
  185. data/vendor/assets/javascripts/jsts/operation/valid/ConnectedInteriorTester.js +259 -0
  186. data/vendor/assets/javascripts/jsts/operation/valid/ConsistentAreaTester.js +127 -0
  187. data/vendor/assets/javascripts/jsts/operation/valid/IndexedNestedRingTester.js +89 -0
  188. data/vendor/assets/javascripts/jsts/operation/valid/IsValidOp.js +619 -0
  189. data/vendor/assets/javascripts/jsts/operation/valid/TopologyValidationError.js +199 -0
  190. data/vendor/assets/javascripts/jsts/planargraph/DirectedEdge.js +232 -0
  191. data/vendor/assets/javascripts/jsts/planargraph/DirectedEdgeStar.js +168 -0
  192. data/vendor/assets/javascripts/jsts/planargraph/Edge.js +124 -0
  193. data/vendor/assets/javascripts/jsts/planargraph/GraphComponent.js +182 -0
  194. data/vendor/assets/javascripts/jsts/planargraph/Node.js +127 -0
  195. data/vendor/assets/javascripts/jsts/planargraph/NodeMap.js +76 -0
  196. data/vendor/assets/javascripts/jsts/planargraph/PlanarGraph.js +246 -0
  197. data/vendor/assets/javascripts/jsts/simplify/LineSegmentIndex.js +101 -0
  198. data/vendor/assets/javascripts/jsts/triangulate/DelaunayTriangulationBuilder.js +224 -0
  199. data/vendor/assets/javascripts/jsts/triangulate/IncrementalDelaunayTriangulator.js +111 -0
  200. data/vendor/assets/javascripts/jsts/triangulate/VoronoiDiagramBuilder.js +172 -0
  201. data/vendor/assets/javascripts/jsts/triangulate/quadedge/LastFoundQuadEdgeLocator.js +52 -0
  202. data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdge.js +437 -0
  203. data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdgeSubdivision.js +1064 -0
  204. data/vendor/assets/javascripts/jsts/triangulate/quadedge/TrianglePredicate.js +350 -0
  205. data/vendor/assets/javascripts/jsts/triangulate/quadedge/Vertex.js +496 -0
  206. data/vendor/assets/javascripts/jsts/util/Assert.js +80 -0
  207. data/vendor/assets/javascripts/jsts/util/AssertionFailedException.js +23 -0
  208. data/vendor/assets/javascripts/jsts/util/UniqueCoordinateArrayFilter.js +52 -0
  209. metadata +204 -1
@@ -0,0 +1,118 @@
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
+ * Computes the union of a {@link Puntal} geometry with
8
+ * another arbitrary {@link Geometry}.
9
+ * Does not copy any component geometries.
10
+ *
11
+ * @requires jsts/algorithm/PointLocator.js
12
+ *
13
+ */
14
+
15
+
16
+
17
+ //TODO: How do we treat Puntal?
18
+ /**
19
+ * @param {jsts.geom.Puntal} pointGeom
20
+ * @param {jsts.geom.Geometry} otherGeom
21
+ * @constructor
22
+ */
23
+ jsts.operation.union.PointGeometryUnion = function(pointGeom, otherGeom) {
24
+ this.pointGeom = pointGeom;
25
+ this.otherGeom = otherGeom;
26
+ this.geomFact = otherGeom.getFactory();
27
+ };
28
+
29
+
30
+ /**
31
+ * @param {jsts.geom.Puntal} pointGeom
32
+ * @param {jsts.geom.Geometry} otherGeom
33
+ * @return {jsts.geom.Geometry}
34
+ *
35
+ * @public
36
+ */
37
+ jsts.operation.union.PointGeometryUnion.union = function(pointGeom, otherGeom) {
38
+ var unioner = new jsts.operation.union.PointGeometryUnion(pointGeom, otherGeom);
39
+ return unioner.union();
40
+ };
41
+
42
+
43
+ /**
44
+ * @type {jsts.geom.Geometry}
45
+ * @private
46
+ */
47
+ jsts.operation.union.PointGeometryUnion.prototype.pointGeom = null;
48
+
49
+
50
+ /**
51
+ * @type {jsts.geom.Geometry}
52
+ * @private
53
+ */
54
+ jsts.operation.union.PointGeometryUnion.prototype.otherGeom = null;
55
+
56
+
57
+ /**
58
+ * @type {jsts.geom.GeometryFactory}
59
+ * @private
60
+ */
61
+ jsts.operation.union.PointGeometryUnion.prototype.geomFact = null;
62
+
63
+
64
+ /**
65
+ *
66
+ * @return {jsts.geom.Geometry}
67
+ */
68
+ jsts.operation.union.PointGeometryUnion.prototype.union = function() {
69
+ var locator = new jsts.algorithm.PointLocator();
70
+ // use a set to eliminate duplicates, as required for union
71
+ // Should be a tree set. So we have to check for uniqueness and sort it.
72
+ var exteriorCoords = [];
73
+
74
+ for (var i = 0, l = this.pointGeom.getNumGeometries(); i < l; i++) {
75
+ var point = this.pointGeom.getGeometryN(i);
76
+ var coord = point.getCoordinate();
77
+ var loc = locator.locate(coord, this.otherGeom);
78
+
79
+ if (loc === jsts.geom.Location.EXTERIOR) {
80
+
81
+ // TreeSet: check for uniqueness
82
+ var include = true;
83
+ for (var j = exteriorCoords.length; i--;) {
84
+ if (exteriorCoords[j].equals(coord)) {
85
+ include = false;
86
+ break;
87
+ }
88
+ }
89
+
90
+ if (include) {
91
+ exteriorCoords.push(coord);
92
+ }
93
+ }
94
+ }
95
+
96
+ //TreeSet: sort ascending
97
+ exteriorCoords.sort(function(x, y) {
98
+ return x.compareTo(y);
99
+ });
100
+
101
+ //if no points are in exterior, return the other geom
102
+ if (exteriorCoords.length === 0) {
103
+ return this.otherGeom;
104
+ }
105
+
106
+ //make a puntal geometry of appropriate size
107
+ var ptComp = null;
108
+ var coords = jsts.geom.CoordinateArrays.toCoordinateArray(exteriorCoords);
109
+ if (coords.length === 1) {
110
+ ptComp = this.geomFact.createPoint(coords[0]);
111
+ }
112
+ else {
113
+ ptComp = this.geomFact.createMultiPoint(coords);
114
+ }
115
+
116
+ //add point component to the other geometry
117
+ return jsts.geom.util.GeometryCombiner.combine(ptComp, this.otherGeom);
118
+ };
@@ -0,0 +1,244 @@
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/geom/util/GeometryExtracter.js
11
+ * @requires jsts/operation/union/CascadedPolygonUnion.js
12
+ * @requires jsts/operation/union/PointGeometryUnion.js
13
+ * @requires jsts/operation/overlay/OverlayOp.js
14
+ * @requires jsts/operation/overlay/snap/SnapIfNeededOverlayOp.js
15
+ */
16
+
17
+ var GeometryExtracter = jsts.geom.util.GeometryExtracter;
18
+ var CascadedPolygonUnion = jsts.operation.union.CascadedPolygonUnion;
19
+ var PointGeometryUnion = jsts.operation.union.PointGeometryUnion;
20
+ var OverlayOp = jsts.operation.overlay.OverlayOp;
21
+ var SnapIfNeededOverlayOp = jsts.operation.overlay.snap.SnapIfNeededOverlayOp;
22
+ var ArrayList = javascript.util.ArrayList;
23
+
24
+ /**
25
+ * Unions a collection of Geometry or a single Geometry (which may be a
26
+ * collection) together. By using this special-purpose operation over a
27
+ * collection of geometries it is possible to take advantage of various
28
+ * optimizations to improve performance. Heterogeneous
29
+ * {@link GeometryCollection}s are fully supported.
30
+ * <p>
31
+ * The result obeys the following contract:
32
+ * <ul>
33
+ * <li>Unioning a set of overlapping {@link Polygons}s has the effect of
34
+ * merging the areas (i.e. the same effect as iteratively unioning all
35
+ * individual polygons together).
36
+ *
37
+ * <li>Unioning a set of {@link LineString}s has the effect of <b>fully noding</b>
38
+ * and <b>dissolving</b> the input linework. In this context "fully noded"
39
+ * means that there will be a node or endpoint in the output for every endpoint
40
+ * or line segment crossing in the input. "Dissolved" means that any duplicate
41
+ * (e.g. coincident) line segments or portions of line segments will be reduced
42
+ * to a single line segment in the output. This is consistent with the semantics
43
+ * of the {@link Geometry#union(Geometry)} operation. If <b>merged</b> linework
44
+ * is required, the {@link LineMerger} class can be used.
45
+ *
46
+ * <li>Unioning a set of {@link Points}s has the effect of merging al
47
+ * identical points (producing a set with no duplicates).
48
+ * </ul>
49
+ *
50
+ * <tt>UnaryUnion</tt> always operates on the individual components of
51
+ * MultiGeometries. So it is possible to use it to "clean" invalid
52
+ * self-intersecting MultiPolygons (although the polygon components must all
53
+ * still be individually valid.)
54
+ *
55
+ */
56
+
57
+ /**
58
+ *
59
+ * @param {jsts.geom.Geometry|Array.
60
+ * <jsts.geom.Geometry>} geoms a Geometry or Geometry collection.
61
+ * @param {jsts.geom.GeometryFactory}
62
+ * [geomFact] a GeometryFactory.
63
+ * @constructor
64
+ */
65
+ jsts.operation.union.UnaryUnionOp = function(geoms, geomFact) {
66
+ this.polygons = new ArrayList();
67
+ this.lines = new ArrayList();
68
+ this.points = new ArrayList();
69
+
70
+ if (geomFact) {
71
+ this.geomFact = geomFact;
72
+ }
73
+
74
+ this.extract(geoms);
75
+ };
76
+
77
+
78
+ /**
79
+ *
80
+ * @param {jsts.geom.Geometry|Array.
81
+ * <jsts.geom.Geometry>} geoms a Geometry or Geometry collection.
82
+ * @param {jsts.geom.GeometryFactory}
83
+ * [gemFact] a GeometryFactory.
84
+ * @return {jsts.geom.Geometry}
85
+ */
86
+ jsts.operation.union.UnaryUnionOp.union = function(geoms, geomFact) {
87
+ var op = new jsts.operation.union.UnaryUnionOp(geoms, geomFact);
88
+ return op.union();
89
+ };
90
+
91
+
92
+ /**
93
+ * @type {Array.<jsts.geom.Polygon>}
94
+ * @private
95
+ */
96
+ jsts.operation.union.UnaryUnionOp.prototype.polygons = null;
97
+
98
+
99
+ /**
100
+ * @type {Array.<jsts.geom.Line>}
101
+ * @private
102
+ */
103
+ jsts.operation.union.UnaryUnionOp.prototype.lines = null;
104
+
105
+
106
+ /**
107
+ * @type {Array.<jsts.geom.Point>}
108
+ * @private
109
+ */
110
+ jsts.operation.union.UnaryUnionOp.prototype.points = null;
111
+
112
+
113
+ /**
114
+ * @type {jsts.geom.GeometryFactory}
115
+ * @private
116
+ */
117
+ jsts.operation.union.UnaryUnionOp.prototype.geomFact = null;
118
+
119
+
120
+ /**
121
+ * @param {jsts.geom.Geometry|Array.
122
+ * <jsts.geom.Geometry>} geoms a Geometry or Geometry collection.
123
+ * @private
124
+ */
125
+ jsts.operation.union.UnaryUnionOp.prototype.extract = function(geoms) {
126
+ if (geoms instanceof ArrayList) {
127
+ for (var i = geoms.iterator(); i.hasNext();) {
128
+ var geom = i.next();
129
+ this.extract(geom);
130
+ }
131
+ } else {
132
+ if (this.geomFact === null) {
133
+ this.geomFact = geoms.getFactory();
134
+ }
135
+ GeometryExtracter.extract(geoms, jsts.geom.Polygon,
136
+ this.polygons);
137
+ GeometryExtracter.extract(geoms, jsts.geom.LineString,
138
+ this.lines);
139
+ GeometryExtracter.extract(geoms, jsts.geom.Point,
140
+ this.points);
141
+ }
142
+ };
143
+
144
+
145
+ /**
146
+ * Gets the union of the input geometries. If no input geometries were
147
+ * provided, a POINT EMPTY is returned.
148
+ *
149
+ * @return {jsts.geom.Geometry|jsts.geom.GeometryCollection} a Geometry containing the union or an empty GEOMETRYCOLLECTION if no
150
+ * geometries were provided in the input.
151
+ */
152
+ jsts.operation.union.UnaryUnionOp.prototype.union = function() {
153
+ if (this.geomFact === null) {
154
+ return null;
155
+ }
156
+
157
+ /**
158
+ * For points and lines, only a single union operation is required, since
159
+ * the OGC model allowings self-intersecting MultiPoint and
160
+ * MultiLineStrings. This is not the case for polygons, so Cascaded Union is
161
+ * required.
162
+ */
163
+
164
+ var unionPoints = null;
165
+ if (this.points.size() > 0) {
166
+ var ptGeom = this.geomFact.buildGeometry(this.points);
167
+ unionPoints = this.unionNoOpt(ptGeom);
168
+ }
169
+
170
+ var unionLines = null;
171
+ if (this.lines.size() > 0) {
172
+ var lineGeom = this.geomFact.buildGeometry(this.lines);
173
+ unionLines = this.unionNoOpt(lineGeom);
174
+ }
175
+
176
+ var unionPolygons = null;
177
+ if (this.polygons.size() > 0) {
178
+ unionPolygons = CascadedPolygonUnion.union(this.polygons);
179
+ }
180
+
181
+ /**
182
+ * Performing two unions is somewhat inefficient, but is mitigated by
183
+ * unioning lines and points first
184
+ */
185
+
186
+ var unionLA = this.unionWithNull(unionLines, unionPolygons);
187
+ var union = null;
188
+ if (unionPoints === null) {
189
+ union = unionLA;
190
+ } else if (unionLA === null) {
191
+ union = unionPoints;
192
+ } else {
193
+ union = PointGeometryUnion(unionPoints, unionLA);
194
+ }
195
+
196
+ if (union === null) {
197
+ return this.geomFact.createGeometryCollection(null);
198
+ }
199
+
200
+ return union;
201
+ };
202
+
203
+
204
+ /**
205
+ * Computes the union of two geometries, either of both of which may be null.
206
+ *
207
+ * @param {jsts.geom.Geometry}
208
+ * g0 a Geometry.
209
+ * @param {jsts.geom.Geometry}
210
+ * g1 a Geometry.
211
+ * @return {?jsts.geom.Geometry} the union of the input(s), returns null if
212
+ * both inputs are null.
213
+ * @private
214
+ */
215
+ jsts.operation.union.UnaryUnionOp.prototype.unionWithNull = function(g0, g1) {
216
+ if (g0 === null && g1 === null) {
217
+ return null;
218
+ }
219
+ if (g1 === null) {
220
+ return g0;
221
+ }
222
+ if (g0 === null) {
223
+ return g1;
224
+ }
225
+ return g0.union(g1);
226
+ };
227
+
228
+
229
+ /**
230
+ * Computes a unary union with no extra optimization, and no short-circuiting.
231
+ * Due to the way the overlay operations are implemented, this is still
232
+ * efficient in the case of linear and puntal geometries.
233
+ *
234
+ * @param {Geometry}
235
+ * g0
236
+ * @return the union of the input geometry.
237
+ * @private
238
+ */
239
+ jsts.operation.union.UnaryUnionOp.prototype.unionNoOpt = function(g0) {
240
+ var empty = this.geomFact.createPoint(null);
241
+ return SnapIfNeededOverlayOp.overlayOp(g0, empty, OverlayOp.UNION);
242
+ };
243
+
244
+ }());
@@ -0,0 +1,156 @@
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
+ * Experimental code to union MultiPolygons
9
+ * with processing limited to the elements which actually interact.
10
+ *
11
+ * Not currently used, since it doesn't seem to offer much of a performance advantage.
12
+ *
13
+ */
14
+
15
+
16
+
17
+ /**
18
+ * @param {jsts.geom.Geometry} g0
19
+ * @param {jsts.geom.Geometry} g1
20
+ * @constructor
21
+ */
22
+ jsts.operation.union.UnionInteracting = function(g0, g1) {
23
+ this.g0 = g0;
24
+ this.g1 = g1;
25
+ this.geomFactory = g0.getFactory();
26
+ this.interacts0 = [];
27
+ this.interacts1 = [];
28
+ };
29
+
30
+
31
+ /**
32
+ * @param {jsts.geom.Geometry} g0
33
+ * @param {jsts.geom.Geometry} g1
34
+ * @return {jsts.geom.Geometry}
35
+ */
36
+ jsts.operation.union.UnionInteracting.union = function(g0, g1) {
37
+ var uue = new jsts.operation.union.UnionInteracting(g0, g1);
38
+ return uue.union();
39
+ };
40
+
41
+
42
+ /**
43
+ * @type {jsts.geom.GeometryFactory}
44
+ */
45
+ jsts.operation.union.UnionInteracting.prototype.geomFactory = null;
46
+
47
+
48
+ /**
49
+ * @type {jsts.geom.Geometry}
50
+ */
51
+ jsts.operation.union.UnionInteracting.prototype.g0 = null;
52
+
53
+
54
+ /**
55
+ * @type {jsts.geom.Geometry}
56
+ */
57
+ jsts.operation.union.UnionInteracting.prototype.g1 = null;
58
+
59
+
60
+ /**
61
+ * @type {Array.<boolean>}
62
+ */
63
+ jsts.operation.union.UnionInteracting.prototype.interacts0 = null;
64
+
65
+
66
+ /**
67
+ * @type {Array.<boolean>}
68
+ */
69
+ jsts.operation.union.UnionInteracting.prototype.interacts1 = null;
70
+
71
+
72
+ /**
73
+ * @return {jsts.geom.Geometry}
74
+ */
75
+ jsts.operation.union.UnionInteracting.prototype.union = function() {
76
+ this.computeInteracting();
77
+
78
+ //check for all interacting or none interacting!
79
+ var int0 = this.extractElements(this.g0, this.interacts0, true);
80
+ var int1 = this.extractElements(this.g1, this.interacts1, true);
81
+
82
+ //TODO: Guess we don't need this here
83
+ if (int0.isEmpty() || int1.isEmpty()) {
84
+ // console.log("found empty!");
85
+ }
86
+
87
+ var union = in0.union(int1);
88
+
89
+ var disjoint0 = this.extractElements(this.g0, this.interacts0, false);
90
+ var disjoint1 = this.extractElements(this.g1, this.interacts1, false);
91
+
92
+ var overallUnion = jsts.geom.util.GeometryCombiner.combine(union, disjoint0, disjoint1);
93
+
94
+ return overallUnion;
95
+ };
96
+
97
+
98
+ /**
99
+ * @param {jsts.geom.Geometry} g0
100
+ * @param {jsts.geom.Geometry} g1
101
+ * @return {jsts.geom.Geometry}
102
+ * @private
103
+ */
104
+ jsts.operation.union.UnionInteracting.prototype.bufferUnion = function(g0, g1) {
105
+ var factory = g0.getFactory();
106
+ var gColl = factory.createGeometryCollection([g0, g1]);
107
+ var unionAll = gColl.buffer(0.0);
108
+ return unionAll;
109
+ };
110
+
111
+
112
+ /**
113
+ * @param {jsts.geom.Geometry} [elem0].
114
+ * @return {?boolean}
115
+ * @private
116
+ */
117
+ jsts.operation.union.UnionInteracting.prototype.computeInteracting = function(elem0) {
118
+ if (!elem0) {
119
+ for (var i = 0, l = this.g0.getNumGeometries(); i < l; i++) {
120
+ var elem = this.g0.getGeometryN(i);
121
+ this.interacts0[i] = this.computeInteracting(elem);
122
+ }
123
+ }
124
+ else {
125
+ var interactsWithAny = false;
126
+ for (var i = 0, l = g1.getNumGeometries(); i < l; i++) {
127
+ var elem1 = this.g1.getGeometryN(i);
128
+ var interacts = elem1.getEnvelopeInternal().intersects(elem0.getEnvelopeInternal());
129
+ if (interacts) {
130
+ this.interacts1[i] = true;
131
+ interactsWithAny = true;
132
+ }
133
+ }
134
+ return interactsWithAny;
135
+ }
136
+ };
137
+
138
+
139
+ /**
140
+ * @param {jsts.geom.Geometry} geom
141
+ * @param {Array.<boolean>} interacts
142
+ * @param {boolean} isInteracting
143
+ * @return {jsts.geom.Geometry}
144
+ * @private
145
+ */
146
+ jsts.operation.union.UnionInteracting.prototype.extractElements = function(geom, interacts, isInteracting) {
147
+ var extractedGeoms = [];
148
+ for (var i = 0, l = geom.getNumGeometries(); i < l; i++) {
149
+ var elem = geom.getGeometryN(i);
150
+ if (interacts[i] === isInteracting) {
151
+ extractedGeoms.push(elem);
152
+ }
153
+ }
154
+ return this.geomFactory.buildGeometry(extractedGeoms);
155
+ };
156
+