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,68 @@
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
+
9
+ /**
10
+ * Converts a geometry in Well-Known Text format to a {@link Geometry}.
11
+ * <p>
12
+ * <code>WKTReader</code> supports extracting <code>Geometry</code> objects
13
+ * from either {@link Reader}s or {@link String}s. This allows it to function
14
+ * as a parser to read <code>Geometry</code> objects from text blocks embedded
15
+ * in other data formats (e.g. XML).
16
+ * <P>
17
+ * <p>
18
+ * A <code>WKTReader</code> is parameterized by a <code>GeometryFactory</code>,
19
+ * to allow it to create <code>Geometry</code> objects of the appropriate
20
+ * implementation. In particular, the <code>GeometryFactory</code> determines
21
+ * the <code>PrecisionModel</code> and <code>SRID</code> that is used.
22
+ * <P>
23
+ *
24
+ * @constructor
25
+ */
26
+ jsts.io.WKTReader = function(geometryFactory) {
27
+ this.geometryFactory = geometryFactory || new jsts.geom.GeometryFactory();
28
+ this.precisionModel = this.geometryFactory.getPrecisionModel();
29
+ this.parser = new jsts.io.WKTParser(this.geometryFactory);
30
+ };
31
+
32
+
33
+ /**
34
+ * Reads a Well-Known Text representation of a {@link Geometry}
35
+ *
36
+ * @param {string}
37
+ * wkt a <Geometry Tagged Text> string (see the OpenGIS Simple Features
38
+ * Specification).
39
+ * @return {jsts.geom.Geometry} a <code>Geometry</code> read from
40
+ * <code>string.</code>
41
+ */
42
+ jsts.io.WKTReader.prototype.read = function(wkt) {
43
+ var geometry = this.parser.read(wkt);
44
+
45
+ // TODO: port and use GeometryPrecisionReducer, this is a hack
46
+ if (this.precisionModel.getType() === jsts.geom.PrecisionModel.FIXED) {
47
+ this.reducePrecision(geometry);
48
+ }
49
+
50
+ return geometry;
51
+ };
52
+
53
+ //NOTE: this is a hack
54
+ jsts.io.WKTReader.prototype.reducePrecision = function(geometry) {
55
+ var i, len;
56
+
57
+ if (geometry.coordinate) {
58
+ this.precisionModel.makePrecise(geometry.coordinate);
59
+ } else if (geometry.points) {
60
+ for (i = 0, len = geometry.points.length; i < len; i++) {
61
+ this.precisionModel.makePrecise(geometry.points[i]);
62
+ }
63
+ } else if (geometry.geometries) {
64
+ for (i = 0, len = geometry.geometries.length; i < len; i++) {
65
+ this.reducePrecision(geometry.geometries[i]);
66
+ }
67
+ }
68
+ };
@@ -0,0 +1,61 @@
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
+
9
+ /**
10
+ * Writes the Well-Known Text representation of a {@link Geometry}. The
11
+ * Well-Known Text format is defined in the <A
12
+ * HREF="http://www.opengis.org/techno/specs.htm"> OGC Simple Features
13
+ * Specification for SQL</A>.
14
+ * <p>
15
+ * The <code>WKTWriter</code> outputs coordinates rounded to the precision
16
+ * model. Only the maximum number of decimal places necessary to represent the
17
+ * ordinates to the required precision will be output.
18
+ * <p>
19
+ * The SFS WKT spec does not define a special tag for {@link LinearRing}s.
20
+ * Under the spec, rings are output as <code>LINESTRING</code>s.
21
+ *
22
+ * @see WKTReader
23
+ * @constructor
24
+ */
25
+ jsts.io.WKTWriter = function() {
26
+ this.parser = new jsts.io.WKTParser(this.geometryFactory);
27
+ };
28
+
29
+
30
+ /**
31
+ * Converts a <code>Geometry</code> to its Well-known Text representation.
32
+ *
33
+ * @param {jsts.geom.Geometry}
34
+ * geometry a <code>Geometry</code> to process.
35
+ * @return {string} a <Geometry Tagged Text> string (see the OpenGIS Simple
36
+ * Features Specification).
37
+ */
38
+ jsts.io.WKTWriter.prototype.write = function(geometry) {
39
+ var wkt = this.parser.write(geometry);
40
+
41
+ return wkt;
42
+ };
43
+
44
+ /**
45
+ * Generates the WKT for a <tt>LINESTRING</tt> specified by two
46
+ * {@link Coordinate}s.
47
+ *
48
+ * @param p0
49
+ * the first coordinate.
50
+ * @param p1
51
+ * the second coordinate.
52
+ *
53
+ * @return the WKT.
54
+ */
55
+ jsts.io.WKTWriter.toLineString = function(p0, p1) {
56
+ if (arguments.length !== 2) {
57
+ throw new jsts.error.NotImplementedError();
58
+ }
59
+
60
+ return 'LINESTRING ( ' + p0.x + ' ' + p0.y + ', ' + p1.x + ' ' + p1.y + ' )';
61
+ };
@@ -0,0 +1,87 @@
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
+ * Represents a list of contiguous line segments, and supports noding the
11
+ * segments. The line segments are represented by an array of
12
+ * {@link Coordinate}s. Intended to optimize the noding of contiguous
13
+ * segments by reducing the number of allocated objects. SegmentStrings can
14
+ * carry a context object, which is useful for preserving topological or
15
+ * parentage information. All noded substrings are initialized with the same
16
+ * context object.
17
+ *
18
+ * Creates a new segment string from a list of vertices.
19
+ *
20
+ * @param pts
21
+ * the vertices of the segment string.
22
+ * @param data
23
+ * the user-defined data of this segment string (may be null).
24
+ * @constructor
25
+ */
26
+ jsts.noding.BasicSegmentString = function(pts, data) {
27
+ this.pts = pts;
28
+ this.data = data;
29
+ };
30
+ jsts.noding.BasicSegmentString.prototype = new jsts.noding.SegmentString();
31
+
32
+
33
+ jsts.noding.BasicSegmentString.prototype.pts = null;
34
+ jsts.noding.BasicSegmentString.prototype.data = null;
35
+
36
+
37
+ /**
38
+ * Gets the user-defined data for this segment string.
39
+ *
40
+ * @return the user-defined data.
41
+ */
42
+ jsts.noding.BasicSegmentString.prototype.getData = function() {
43
+ return this.data;
44
+ }
45
+
46
+ /**
47
+ * Sets the user-defined data for this segment string.
48
+ *
49
+ * @param data
50
+ * an Object containing user-defined data.
51
+ */
52
+ jsts.noding.BasicSegmentString.prototype.setData = function(data) {
53
+ this.data = data;
54
+ };
55
+
56
+ jsts.noding.BasicSegmentString.prototype.size = function() {
57
+ return this.pts.length;
58
+ };
59
+
60
+ jsts.noding.BasicSegmentString.prototype.getCoordinate = function(i) {
61
+ return this.pts[i];
62
+ };
63
+
64
+ jsts.noding.BasicSegmentString.prototype.getCoordinates = function() {
65
+ return this.pts;
66
+ };
67
+
68
+ jsts.noding.BasicSegmentString.prototype.isClosed = function() {
69
+ return this.pts[0].equals(this.pts[this.pts.length - 1]);
70
+ };
71
+
72
+ /**
73
+ * Gets the octant of the segment starting at vertex <code>index</code>.
74
+ *
75
+ * @param index
76
+ * the index of the vertex starting the segment. Must not be the last
77
+ * index in the vertex list.
78
+ * @return the octant of the segment at the vertex.
79
+ */
80
+ jsts.noding.BasicSegmentString.prototype.getSegmentOctant = function(index) {
81
+ if (index == this.pts.length - 1)
82
+ return -1;
83
+ return jsts.noding.Octant.octant(this.getCoordinate(index), this
84
+ .getCoordinate(index + 1));
85
+ };
86
+
87
+ })();
@@ -0,0 +1,127 @@
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/algorithm/RobustLineIntersector.js
11
+ * @requires jsts/noding/InteriorIntersectionFinder.js
12
+ * @requires jsts/noding/MCIndexNoder.js
13
+ */
14
+
15
+ var RobustLineIntersector = jsts.algorithm.RobustLineIntersector;
16
+ var InteriorIntersectionFinder = jsts.noding.InteriorIntersectionFinder;
17
+ var MCIndexNoder = jsts.noding.MCIndexNoder;
18
+
19
+ /**
20
+ * Validates that a collection of {@link SegmentString}s is correctly noded.
21
+ * Indexing is used to improve performance. In the most common use case,
22
+ * validation stops after a single non-noded intersection is detected. Does
23
+ * NOT check a-b-a collapse situations. Also does not check for
24
+ * endpoint-interior vertex intersections. This should not be a problem, since
25
+ * the noders should be able to compute intersections between vertices
26
+ * correctly.
27
+ * <p>
28
+ * The client may either test the {@link #isValid} condition, or request that
29
+ * a suitable {@link TopologyException} be thrown.
30
+ *
31
+ * Creates a new noding validator for a given set of linework.
32
+ *
33
+ * @param segStrings
34
+ * a collection of {@link SegmentString} s.
35
+ */
36
+ jsts.noding.FastNodingValidator = function(segStrings) {
37
+ this.li = new RobustLineIntersector();
38
+
39
+ this.segStrings = segStrings;
40
+ };
41
+
42
+ jsts.noding.FastNodingValidator.prototype.li = null;
43
+
44
+ jsts.noding.FastNodingValidator.prototype.segStrings = null;
45
+ jsts.noding.FastNodingValidator.prototype.findAllIntersections = false;
46
+ jsts.noding.FastNodingValidator.prototype.segInt = null;
47
+ jsts.noding.FastNodingValidator.prototype._isValid = true;
48
+
49
+ jsts.noding.FastNodingValidator.prototype.setFindAllIntersections = function(
50
+ findAllIntersections) {
51
+ this.findAllIntersections = findAllIntersections;
52
+ };
53
+
54
+ jsts.noding.FastNodingValidator.prototype.getIntersections = function() {
55
+ return segInt.getIntersections();
56
+ };
57
+
58
+ /**
59
+ * Checks for an intersection and reports if one is found.
60
+ *
61
+ * @return true if the arrangement contains an interior intersection.
62
+ */
63
+ jsts.noding.FastNodingValidator.prototype.isValid = function() {
64
+ this.execute();
65
+ return this._isValid;
66
+ };
67
+
68
+ /**
69
+ * Returns an error message indicating the segments containing the
70
+ * intersection.
71
+ *
72
+ * @return an error message documenting the intersection location.
73
+ */
74
+ jsts.noding.FastNodingValidator.prototype.getErrorMessage = function() {
75
+ if (this._isValid)
76
+ return 'no intersections found';
77
+
78
+ var intSegs = this.segInt.getIntersectionSegments();
79
+ return 'found non-noded intersection between ' +
80
+ jsts.io.WKTWriter.toLineString(intSegs[0], intSegs[1]) + ' and ' +
81
+ jsts.io.WKTWriter.toLineString(intSegs[2], intSegs[3]);
82
+ };
83
+
84
+ /**
85
+ * Checks for an intersection and throws a TopologyException if one is found.
86
+ *
87
+ * @throws TopologyException
88
+ * if an intersection is found
89
+ */
90
+ jsts.noding.FastNodingValidator.prototype.checkValid = function() {
91
+ this.execute();
92
+ if (!this._isValid)
93
+ throw new jsts.error.TopologyError(this.getErrorMessage(), this.segInt
94
+ .getInteriorIntersection());
95
+ };
96
+
97
+ /**
98
+ * @private
99
+ */
100
+ jsts.noding.FastNodingValidator.prototype.execute = function() {
101
+ if (this.segInt != null)
102
+ return;
103
+ this.checkInteriorIntersections();
104
+ };
105
+
106
+ /**
107
+ * @private
108
+ */
109
+ jsts.noding.FastNodingValidator.prototype.checkInteriorIntersections = function() {
110
+ /**
111
+ * MD - It may even be reliable to simply check whether end segments (of
112
+ * SegmentStrings) have an interior intersection, since noding should have
113
+ * split any true interior intersections already.
114
+ */
115
+ this._isValid = true;
116
+ this.segInt = new InteriorIntersectionFinder(this.li);
117
+ this.segInt.setFindAllIntersections(this.findAllIntersections);
118
+ var noder = new MCIndexNoder();
119
+ noder.setSegmentIntersector(this.segInt);
120
+ noder.computeNodes(this.segStrings);
121
+ if (this.segInt.hasIntersection()) {
122
+ this._isValid = false;
123
+ return;
124
+ }
125
+ };
126
+
127
+ })();
@@ -0,0 +1,171 @@
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/noding/SegmentIntersector.js
11
+ */
12
+
13
+ var SegmentIntersector = jsts.noding.SegmentIntersector;
14
+ var ArrayList = javascript.util.ArrayList;
15
+
16
+ /**
17
+ * Finds an interior intersection in a set of {@link SegmentString}s, if one
18
+ * exists. Only the first intersection found is reported.
19
+ *
20
+ * Creates an intersection finder which finds an interior intersection if one
21
+ * exists
22
+ *
23
+ * @param li
24
+ * the LineIntersector to use.
25
+ * @constructor
26
+ */
27
+ jsts.noding.InteriorIntersectionFinder = function(li) {
28
+ this.li = li;
29
+ this.intersections = new ArrayList();
30
+ this.interiorIntersection = null;
31
+ };
32
+
33
+ jsts.noding.InteriorIntersectionFinder.prototype = new SegmentIntersector();
34
+ jsts.noding.InteriorIntersectionFinder.constructor = jsts.noding.InteriorIntersectionFinder;
35
+
36
+ jsts.noding.InteriorIntersectionFinder.prototype.findAllIntersections = false;
37
+ jsts.noding.InteriorIntersectionFinder.prototype.isCheckEndSegmentsOnly = false;
38
+ jsts.noding.InteriorIntersectionFinder.prototype.li = null;
39
+ jsts.noding.InteriorIntersectionFinder.prototype.interiorIntersection = null;
40
+ jsts.noding.InteriorIntersectionFinder.prototype.intSegments = null;
41
+ jsts.noding.InteriorIntersectionFinder.prototype.intersections = null;
42
+
43
+
44
+ jsts.noding.InteriorIntersectionFinder.prototype.setFindAllIntersections = function(
45
+ findAllIntersections) {
46
+ this.findAllIntersections = findAllIntersections;
47
+ };
48
+
49
+ jsts.noding.InteriorIntersectionFinder.prototype.getIntersections = function() {
50
+ return intersections;
51
+ };
52
+
53
+ /**
54
+ * Sets whether only end segments should be tested for interior intersection.
55
+ * This is a performance optimization that may be used if the segments have
56
+ * been previously noded by an appropriate algorithm. It may be known that any
57
+ * potential noding failures will occur only in end segments.
58
+ *
59
+ * @param isCheckEndSegmentsOnly
60
+ * whether to test only end segments.
61
+ */
62
+ jsts.noding.InteriorIntersectionFinder.prototype.setCheckEndSegmentsOnly = function(
63
+ isCheckEndSegmentsOnly) {
64
+ this.isCheckEndSegmentsOnly = isCheckEndSegmentsOnly;
65
+ }
66
+
67
+ /**
68
+ * Tests whether an intersection was found.
69
+ *
70
+ * @return true if an intersection was found.
71
+ */
72
+ jsts.noding.InteriorIntersectionFinder.prototype.hasIntersection = function() {
73
+ return this.interiorIntersection != null;
74
+ };
75
+
76
+ /**
77
+ * Gets the computed location of the intersection. Due to round-off, the
78
+ * location may not be exact.
79
+ *
80
+ * @return the coordinate for the intersection location.
81
+ */
82
+ jsts.noding.InteriorIntersectionFinder.prototype.getInteriorIntersection = function() {
83
+ return this.interiorIntersection;
84
+ };
85
+
86
+ /**
87
+ * Gets the endpoints of the intersecting segments.
88
+ *
89
+ * @return an array of the segment endpoints (p00, p01, p10, p11).
90
+ */
91
+ jsts.noding.InteriorIntersectionFinder.prototype.getIntersectionSegments = function() {
92
+ return this.intSegments;
93
+ };
94
+
95
+ /**
96
+ * This method is called by clients of the {@link SegmentIntersector} class to
97
+ * process intersections for two segments of the {@link SegmentString}s being
98
+ * intersected. Note that some clients (such as {@link MonotoneChain}s) may
99
+ * optimize away this call for segment pairs which they have determined do not
100
+ * intersect (e.g. by an disjoint envelope test).
101
+ */
102
+ jsts.noding.InteriorIntersectionFinder.prototype.processIntersections = function(
103
+ e0, segIndex0, e1, segIndex1) {
104
+ // short-circuit if intersection already found
105
+ if (this.hasIntersection())
106
+ return;
107
+
108
+ // don't bother intersecting a segment with itself
109
+ if (e0 == e1 && segIndex0 == segIndex1)
110
+ return;
111
+
112
+ /**
113
+ * If enabled, only test end segments (on either segString).
114
+ *
115
+ */
116
+ if (this.isCheckEndSegmentsOnly) {
117
+ var isEndSegPresent = this.isEndSegment(e0, segIndex0) ||
118
+ isEndSegment(e1, segIndex1);
119
+ if (!isEndSegPresent)
120
+ return;
121
+ }
122
+
123
+ var p00 = e0.getCoordinates()[segIndex0];
124
+ var p01 = e0.getCoordinates()[segIndex0 + 1];
125
+ var p10 = e1.getCoordinates()[segIndex1];
126
+ var p11 = e1.getCoordinates()[segIndex1 + 1];
127
+
128
+ this.li.computeIntersection(p00, p01, p10, p11);
129
+ // if (li.hasIntersection() && li.isProper()) Debug.println(li);
130
+
131
+ if (this.li.hasIntersection()) {
132
+ if (this.li.isInteriorIntersection()) {
133
+ this.intSegments = [];
134
+ this.intSegments[0] = p00;
135
+ this.intSegments[1] = p01;
136
+ this.intSegments[2] = p10;
137
+ this.intSegments[3] = p11;
138
+
139
+ this.interiorIntersection = this.li.getIntersection(0);
140
+ this.intersections.add(this.interiorIntersection);
141
+ }
142
+ }
143
+ };
144
+
145
+ /**
146
+ * Tests whether a segment in a {@link SegmentString} is an end segment.
147
+ * (either the first or last).
148
+ *
149
+ * @param segStr
150
+ * a segment string.
151
+ * @param index
152
+ * the index of a segment in the segment string.
153
+ * @return true if the segment is an end segment.
154
+ * @private
155
+ */
156
+ jsts.noding.InteriorIntersectionFinder.prototype.isEndSegment = function(
157
+ segStr, index) {
158
+ if (index == 0)
159
+ return true;
160
+ if (index >= segStr.size() - 2)
161
+ return true;
162
+ return false;
163
+ };
164
+
165
+ jsts.noding.InteriorIntersectionFinder.prototype.isDone = function() {
166
+ if (this.findAllIntersections)
167
+ return false;
168
+ return this.interiorIntersection != null;
169
+ };
170
+
171
+ })();