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,143 @@
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
+ * Combines {@link Geometry}s
9
+ * to produce a {@link GeometryCollection} of the most appropriate type.
10
+ * Input geometries which are already collections
11
+ * will have their elements extracted first.
12
+ * No validation of the result geometry is performed.
13
+ * (The only case where invalidity is possible is where {@link Polygonal} geometries
14
+ * are combined and result in a self-intersection).
15
+ *
16
+ * @see GeometryFactory#buildGeometry
17
+ */
18
+
19
+
20
+
21
+ /**
22
+ * Creates a new combiner for a collection of geometries
23
+ *
24
+ * @param {Array} geoms the geometries to combine.
25
+ * @constructor
26
+ */
27
+ jsts.geom.util.GeometryCombiner = function(geoms) {
28
+ this.geomFactory = jsts.geom.util.GeometryCombiner.extractFactory(geoms);
29
+ this.inputGeoms = geoms;
30
+ };
31
+
32
+
33
+ /**
34
+ * Combines a collection of geometries.
35
+ *
36
+ * @param {ArrayList} geoms the geometries to combine.
37
+ * @return {Geometry} the combined geometry.
38
+ * @public
39
+ */
40
+ jsts.geom.util.GeometryCombiner.combine = function(geoms) {
41
+ if (arguments.length>1) return this.combine2.apply(this, arguments);
42
+ var combiner = new jsts.geom.util.GeometryCombiner(geoms);
43
+ return combiner.combine();
44
+ };
45
+
46
+
47
+ /**
48
+ * Combines two or three geometries.
49
+ *
50
+ * @param {Geometry} g0 a geometry to combine.
51
+ * @param {Geometry} g1 a geometry to combine.
52
+ * @param {Geometry=} [g2] a geometry to combine.
53
+ * @return {Geometry} the combined geometry.
54
+ * @public
55
+ */
56
+ jsts.geom.util.GeometryCombiner.combine2 = function() {
57
+ var arrayList = new javascript.util.ArrayList();
58
+ Array.prototype.slice.call(arguments).forEach(function(a) {
59
+ arrayList.add(a);
60
+ });
61
+ var combiner = new jsts.geom.util.GeometryCombiner(arrayList);
62
+ return combiner.combine();
63
+ };
64
+
65
+
66
+ /**
67
+ * @type {GeometryFactory}
68
+ * @private
69
+ */
70
+ jsts.geom.util.GeometryCombiner.prototype.geomFactory = null;
71
+
72
+
73
+ /**
74
+ * @type {boolean}
75
+ * @private
76
+ */
77
+ jsts.geom.util.GeometryCombiner.prototype.skipEmpty = false;
78
+
79
+
80
+ /**
81
+ * @type {Array}
82
+ * @private
83
+ */
84
+ jsts.geom.util.GeometryCombiner.prototype.inputGeoms;
85
+
86
+
87
+ /**
88
+ * Extracts the GeometryFactory used by the geometries in a collection
89
+ *
90
+ * @param {Array} geoms
91
+ * @return {jsts.geom.GeometryFactory} a GeometryFactory.
92
+ * @public
93
+ */
94
+ jsts.geom.util.GeometryCombiner.extractFactory = function(geoms) {
95
+ if (geoms.isEmpty()) return null;
96
+ return geoms.iterator().next().getFactory();
97
+ };
98
+
99
+
100
+ /**
101
+ * Computes the combination of the input geometries
102
+ * to produce the most appropriate {@link Geometry} or {@link GeometryCollection}
103
+ *
104
+ * @return {jsts.geom.Geometry} a Geometry which is the combination of the inputs.
105
+ * @public
106
+ */
107
+ jsts.geom.util.GeometryCombiner.prototype.combine = function() {
108
+ var elems = new javascript.util.ArrayList(), i;
109
+ for (i = this.inputGeoms.iterator(); i.hasNext(); ) {
110
+ var g = i.next();
111
+ this.extractElements(g, elems);
112
+ }
113
+
114
+ if (elems.size() === 0) {
115
+ if (this.geomFactory !== null) {
116
+ // return an empty GC
117
+ return geomFactory.createGeometryCollection(null);
118
+ }
119
+ return null;
120
+ }
121
+ // return the "simplest possible" geometry
122
+ return this.geomFactory.buildGeometry(elems);
123
+ };
124
+
125
+
126
+ /**
127
+ * @param {jsts.geom.Geometry} geom
128
+ * @param {Array} elems
129
+ * @private
130
+ */
131
+ jsts.geom.util.GeometryCombiner.prototype.extractElements = function(geom, elems) {
132
+ if (geom === null) {
133
+ return;
134
+ }
135
+
136
+ for (var i = 0; i < geom.getNumGeometries(); i++) {
137
+ var elemGeom = geom.getGeometryN(i);
138
+ if (this.skipEmpty && elemGeom.isEmpty()) {
139
+ continue;
140
+ }
141
+ elems.add(elemGeom);
142
+ }
143
+ };
@@ -0,0 +1,76 @@
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
+ * @requires jsts/geom/GeometryFilter.js
9
+ */
10
+
11
+
12
+
13
+ /**
14
+ * Constructs a filter with a list in which to store the elements found.
15
+ *
16
+ * @param clz the class of the components to extract (null means all types).
17
+ * @param {[]} comps the list to extract into.
18
+ * @extends {jsts.geom.GeometryFilter}
19
+ * @constructor
20
+ */
21
+ jsts.geom.util.GeometryExtracter = function(clz, comps) {
22
+ this.clz = clz;
23
+ this.comps = comps;
24
+ };
25
+
26
+ jsts.geom.util.GeometryExtracter.prototype = new jsts.geom.GeometryFilter();
27
+
28
+
29
+ /**
30
+ * @private
31
+ */
32
+ jsts.geom.util.GeometryExtracter.prototype.clz = null;
33
+
34
+
35
+ /**
36
+ * @private
37
+ * @type {javascript.util.List}
38
+ */
39
+ jsts.geom.util.GeometryExtracter.prototype.comps = null;
40
+
41
+
42
+ /**
43
+ * Extracts the components of type <tt>clz</tt> from a {@link Geometry}
44
+ * and adds them to the provided {@link List} if provided.
45
+ *
46
+ * @param {Geometry} geom the geometry from which to extract.
47
+ * @param {Object} clz
48
+ * @param {javascript.util.ArrayList} [list] the list to add the extracted elements to.
49
+ *
50
+ * @return {javascript.util.ArrayList}
51
+ */
52
+ jsts.geom.util.GeometryExtracter.extract = function(geom, clz, list) {
53
+ list = list || new javascript.util.ArrayList();
54
+ if (geom instanceof clz) {
55
+ list.add(geom);
56
+ }
57
+ else if (geom instanceof jsts.geom.GeometryCollection ||
58
+ geom instanceof jsts.geom.MultiPoint ||
59
+ geom instanceof jsts.geom.MultiLineString ||
60
+ geom instanceof jsts.geom.MultiPolygon) {
61
+ geom.apply(new jsts.geom.util.GeometryExtracter(clz, list));
62
+ }
63
+ //skip non-LineString elemental geometries
64
+
65
+ return list;
66
+ };
67
+
68
+
69
+ /**
70
+ * @param {Geometry} geom
71
+ */
72
+ jsts.geom.util.GeometryExtracter.prototype.filter = function(geom) {
73
+ if (this.clz === null || geom instanceof this.clz) {
74
+ this.comps.add(geom);
75
+ }
76
+ };
@@ -0,0 +1,295 @@
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/geom/util/GeometryTransformer.java
10
+ * Revision: 381
11
+ */
12
+
13
+ /**
14
+ * A framework for processes which transform an input {@link Geometry} into an
15
+ * output {@link Geometry}, possibly changing its structure and type(s). This
16
+ * class is a framework for implementing subclasses which perform
17
+ * transformations on various different Geometry subclasses. It provides an easy
18
+ * way of applying specific transformations to given geometry types, while
19
+ * allowing unhandled types to be simply copied. Also, the framework ensures
20
+ * that if subcomponents change type the parent geometries types change
21
+ * appropriately to maintain valid structure. Subclasses will override whichever
22
+ * <code>transformX</code> methods they need to to handle particular Geometry
23
+ * types.
24
+ * <p>
25
+ * A typically usage would be a transformation class that transforms
26
+ * <tt>Polygons</tt> into <tt>Polygons</tt>, <tt>LineStrings</tt> or
27
+ * <tt>Points</tt>, depending on the geometry of the input (For instance, a
28
+ * simplification operation). This class would likely need to override the
29
+ * {@link #transformMultiPolygon(MultiPolygon, Geometry)transformMultiPolygon}
30
+ * method to ensure that if input Polygons change type the result is a
31
+ * <tt>GeometryCollection</tt>, not a <tt>MultiPolygon</tt>.
32
+ * <p>
33
+ * The default behaviour of this class is simply to recursively transform each
34
+ * Geometry component into an identical object by deep copying down to the level
35
+ * of, but not including, coordinates.
36
+ * <p>
37
+ * All <code>transformX</code> methods may return <code>null</code>, to
38
+ * avoid creating empty or invalid geometry objects. This will be handled
39
+ * correctly by the transformer. <code>transform<i>XXX</i></code> methods
40
+ * should always return valid geometry - if they cannot do this they should
41
+ * return <code>null</code> (for instance, it may not be possible for a
42
+ * transformLineString implementation to return at least two points - in this
43
+ * case, it should return <code>null</code>). The
44
+ * {@link #transform(Geometry)transform} method itself will always return a
45
+ * non-null Geometry object (but this may be empty).
46
+ *
47
+ * @see GeometryEditor
48
+ */
49
+
50
+ (function() {
51
+
52
+ var ArrayList = javascript.util.ArrayList;
53
+
54
+ var GeometryTransformer = function() {
55
+
56
+ };
57
+
58
+
59
+ GeometryTransformer.prototype.inputGeom = null;
60
+
61
+ GeometryTransformer.prototype.factory = null;
62
+
63
+ // these could eventually be exposed to clients
64
+ /**
65
+ * <code>true</code> if empty geometries should not be included in the
66
+ * result
67
+ */
68
+ GeometryTransformer.prototype.pruneEmptyGeometry = true;
69
+
70
+ /**
71
+ * <code>true</code> if a homogenous collection result from a
72
+ * {@link GeometryCollection} should still be a general GeometryCollection
73
+ */
74
+ GeometryTransformer.prototype.preserveGeometryCollectionType = true;
75
+
76
+ /**
77
+ * <code>true</code> if the output from a collection argument should still
78
+ * be a collection
79
+ */
80
+ GeometryTransformer.prototype.preserveCollections = false;
81
+
82
+ /**
83
+ * <code>true</code> if the type of the input should be preserved
84
+ */
85
+ GeometryTransformer.prototype.reserveType = false;
86
+
87
+ /**
88
+ * Utility function to make input geometry available
89
+ *
90
+ * @return the input geometry.
91
+ */
92
+ GeometryTransformer.prototype.getInputGeometry = function() {
93
+ return this.inputGeom;
94
+ };
95
+
96
+ GeometryTransformer.prototype.transform = function(inputGeom) {
97
+ this.inputGeom = inputGeom;
98
+ this.factory = inputGeom.getFactory();
99
+
100
+ if (inputGeom instanceof jsts.geom.Point)
101
+ return this.transformPoint(inputGeom, null);
102
+ if (inputGeom instanceof jsts.geom.MultiPoint)
103
+ return this.transformMultiPoint(inputGeom, null);
104
+ if (inputGeom instanceof jsts.geom.LinearRing)
105
+ return this.transformLinearRing(inputGeom, null);
106
+ if (inputGeom instanceof jsts.geom.LineString)
107
+ return this.transformLineString(inputGeom, null);
108
+ if (inputGeom instanceof jsts.geom.MultiLineString)
109
+ return this.transformMultiLineString(inputGeom, null);
110
+ if (inputGeom instanceof jsts.geom.Polygon)
111
+ return this.transformPolygon(inputGeom, null);
112
+ if (inputGeom instanceof jsts.geom.MultiPolygon)
113
+ return this.transformMultiPolygon(inputGeom, null);
114
+ if (inputGeom instanceof jsts.geom.GeometryCollection)
115
+ return this.transformGeometryCollection(inputGeom, null);
116
+
117
+ throw new jsts.error.IllegalArgumentException('Unknown Geometry subtype: ' +
118
+ inputGeom.getClass().getName());
119
+ };
120
+
121
+ /**
122
+ * Convenience method which provides standard way of creating a
123
+ * {@link CoordinateSequence}
124
+ *
125
+ * @param coords
126
+ * the coordinate array to copy.
127
+ * @return a coordinate sequence for the array.
128
+ */
129
+ GeometryTransformer.prototype.createCoordinateSequence = function(coords) {
130
+ return this.factory.getCoordinateSequenceFactory().create(coords);
131
+ };
132
+
133
+ /**
134
+ * Convenience method which provides statndard way of copying
135
+ * {@link CoordinateSequence}s
136
+ *
137
+ * @param seq
138
+ * the sequence to copy.
139
+ * @return a deep copy of the sequence.
140
+ */
141
+ GeometryTransformer.prototype.copy = function(seq) {
142
+ return seq.clone();
143
+ };
144
+
145
+ /**
146
+ * Transforms a {@link CoordinateSequence}. This method should always return
147
+ * a valid coordinate list for the desired result type. (E.g. a coordinate
148
+ * list for a LineString must have 0 or at least 2 points). If this is not
149
+ * possible, return an empty sequence - this will be pruned out.
150
+ *
151
+ * @param coords
152
+ * the coordinates to transform.
153
+ * @param parent
154
+ * the parent geometry.
155
+ * @return the transformed coordinates.
156
+ */
157
+ GeometryTransformer.prototype.transformCoordinates = function(coords, parent) {
158
+ return this.copy(coords);
159
+ };
160
+
161
+ GeometryTransformer.prototype.transformPoint = function(geom, parent) {
162
+ return this.factory.createPoint(this.transformCoordinates(geom
163
+ .getCoordinateSequence(), geom));
164
+ };
165
+
166
+ GeometryTransformer.prototype.transformMultiPoint = function(geom, parent) {
167
+ var transGeomList = new ArrayList();
168
+ for (var i = 0; i < geom.getNumGeometries(); i++) {
169
+ var transformGeom = this.transformPoint(geom.getGeometryN(i), geom);
170
+ if (transformGeom == null)
171
+ continue;
172
+ if (transformGeom.isEmpty())
173
+ continue;
174
+ transGeomList.add(transformGeom);
175
+ }
176
+ return this.factory.buildGeometry(transGeomList);
177
+ };
178
+
179
+ /**
180
+ * Transforms a LinearRing. The transformation of a LinearRing may result in a
181
+ * coordinate sequence which does not form a structurally valid ring (i.e. a
182
+ * degnerate ring of 3 or fewer points). In this case a LineString is
183
+ * returned. Subclasses may wish to override this method and check for this
184
+ * situation (e.g. a subclass may choose to eliminate degenerate linear rings)
185
+ *
186
+ * @param geom
187
+ * the ring to simplify.
188
+ * @param parent
189
+ * the parent geometry.
190
+ * @return a LinearRing if the transformation resulted in a structurally valid
191
+ * ring.
192
+ * @return a LineString if the transformation caused the LinearRing to
193
+ * collapse to 3 or fewer points.
194
+ */
195
+ GeometryTransformer.prototype.transformLinearRing = function(geom, parent) {
196
+ var seq = this.transformCoordinates(geom.getCoordinateSequence(), geom);
197
+ var seqSize = seq.length;
198
+ // ensure a valid LinearRing
199
+ if (seqSize > 0 && seqSize < 4 && !this.preserveType)
200
+ return this.factory.createLineString(seq);
201
+ return this.factory.createLinearRing(seq);
202
+
203
+ };
204
+
205
+ /**
206
+ * Transforms a {@link LineString} geometry.
207
+ *
208
+ * @param geom
209
+ * @param parent
210
+ * @return
211
+ */
212
+ GeometryTransformer.prototype.transformLineString = function(geom, parent) {
213
+ // should check for 1-point sequences and downgrade them to points
214
+ return this.factory.createLineString(this.transformCoordinates(geom
215
+ .getCoordinateSequence(), geom));
216
+ };
217
+
218
+ GeometryTransformer.prototype.transformMultiLineString = function(geom,
219
+ parent) {
220
+ var transGeomList = new ArrayList();
221
+ for (var i = 0; i < geom.getNumGeometries(); i++) {
222
+ var transformGeom = this.transformLineString(geom.getGeometryN(i), geom);
223
+ if (transformGeom == null)
224
+ continue;
225
+ if (transformGeom.isEmpty())
226
+ continue;
227
+ transGeomList.add(transformGeom);
228
+ }
229
+ return this.factory.buildGeometry(transGeomList);
230
+ };
231
+
232
+ GeometryTransformer.prototype.transformPolygon = function(geom, parent) {
233
+ var isAllValidLinearRings = true;
234
+ var shell = this.transformLinearRing(geom.getExteriorRing(), geom);
235
+
236
+ if (shell == null || !(shell instanceof jsts.geom.LinearRing) ||
237
+ shell.isEmpty())
238
+ isAllValidLinearRings = false;
239
+
240
+ var holes = new ArrayList();
241
+ for (var i = 0; i < geom.getNumInteriorRing(); i++) {
242
+ var hole = this.transformLinearRing(geom.getInteriorRingN(i), geom);
243
+ if (hole == null || hole.isEmpty()) {
244
+ continue;
245
+ }
246
+ if (!(hole instanceof jsts.geom.LinearRing))
247
+ isAllValidLinearRings = false;
248
+
249
+ holes.add(hole);
250
+ }
251
+
252
+ if (isAllValidLinearRings)
253
+ return this.factory.createPolygon(shell, holes.toArray());
254
+ else {
255
+ var components = new ArrayList();
256
+ if (shell != null)
257
+ components.add(shell);
258
+ components.addAll(holes);
259
+ return this.factory.buildGeometry(components);
260
+ }
261
+ };
262
+
263
+ GeometryTransformer.prototype.transformMultiPolygon = function(geom, parent) {
264
+ var transGeomList = new ArrayList();
265
+ for (var i = 0; i < geom.getNumGeometries(); i++) {
266
+ var transformGeom = this.transformPolygon(geom.getGeometryN(i), geom);
267
+ if (transformGeom == null)
268
+ continue;
269
+ if (transformGeom.isEmpty())
270
+ continue;
271
+ transGeomList.add(transformGeom);
272
+ }
273
+ return this.factory.buildGeometry(transGeomList);
274
+ };
275
+
276
+ GeometryTransformer.prototype.transformGeometryCollection = function(geom,
277
+ parent) {
278
+ var transGeomList = new ArrayList();
279
+ for (var i = 0; i < geom.getNumGeometries(); i++) {
280
+ var transformGeom = this.transform(geom.getGeometryN(i));
281
+ if (transformGeom == null)
282
+ continue;
283
+ if (this.pruneEmptyGeometry && transformGeom.isEmpty())
284
+ continue;
285
+ transGeomList.add(transformGeom);
286
+ }
287
+ if (this.preserveGeometryCollectionType)
288
+ return this.factory.createGeometryCollection(GeometryFactory
289
+ .toGeometryArray(transGeomList));
290
+ return this.factory.buildGeometry(transGeomList);
291
+ };
292
+
293
+ jsts.geom.util.GeometryTransformer = GeometryTransformer;
294
+
295
+ })();