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,471 @@
1
+ /* Copyright (c) 2011, 2012 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
+ * Class for reading and writing Well-Known Text.
9
+ *
10
+ * NOTE: Adapted from OpenLayers 2.11 implementation.
11
+ */
12
+
13
+ (function() {
14
+ /**
15
+ * Create a new parser for GeoJSON
16
+ *
17
+ * @param {GeometryFactory}
18
+ * geometryFactory
19
+ * @return An instance of GeoJsonParser.
20
+ */
21
+ jsts.io.GeoJSONParser = function(geometryFactory) {
22
+ this.geometryFactory = geometryFactory || new jsts.geom.GeometryFactory();
23
+ this.geometryTypes = ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon'];
24
+ };
25
+
26
+ /**
27
+ * Deserialize a GeoJSON object and return the Geometry or Feature(Collection) with JSTS Geometries
28
+ *
29
+ * @param {}
30
+ * A GeoJSON object.
31
+ * @return {} A Geometry instance or object representing a Feature(Collection) with Geometry instances.
32
+ */
33
+ jsts.io.GeoJSONParser.prototype.read = function(json) {
34
+ var obj;
35
+ if (typeof json === 'string') {
36
+ obj = JSON.parse(json);
37
+ } else {
38
+ obj = json;
39
+ }
40
+
41
+ var type = obj.type;
42
+
43
+ if (!this.parse[type]) {
44
+ throw new Error('Unknown GeoJSON type: ' + obj.type);
45
+ }
46
+
47
+ if (this.geometryTypes.indexOf(type) != -1) {
48
+ return this.parse[type].apply(this, [obj.coordinates]);
49
+ } else if (type === 'GeometryCollection') {
50
+ return this.parse[type].apply(this, [obj.geometries]);
51
+ }
52
+
53
+ // feature or feature collection
54
+ return this.parse[type].apply(this, [obj]);
55
+ };
56
+
57
+ jsts.io.GeoJSONParser.prototype.parse = {
58
+ /**
59
+ * Parse a GeoJSON Feature object
60
+ *
61
+ * @param {Object}
62
+ * obj Object to parse.
63
+ *
64
+ * @return {Object} Feature with geometry/bbox converted to JSTS Geometries.
65
+ */
66
+ 'Feature': function(obj) {
67
+ var feature = {};
68
+
69
+ // copy features
70
+ for (var key in obj) {
71
+ feature[key] = obj[key];
72
+ }
73
+
74
+ // parse geometry
75
+ if (obj.geometry) {
76
+ var type = obj.geometry.type;
77
+ if (!this.parse[type]) {
78
+ throw new Error('Unknown GeoJSON type: ' + obj.type);
79
+ }
80
+ feature.geometry = this.read(obj.geometry);
81
+ }
82
+
83
+ // bbox
84
+ if (obj.bbox) {
85
+ feature.bbox = this.parse.bbox.apply(this, [obj.bbox]);
86
+ }
87
+
88
+ return feature;
89
+ },
90
+
91
+ /**
92
+ * Parse a GeoJSON FeatureCollection object
93
+ *
94
+ * @param {Object}
95
+ * obj Object to parse.
96
+ *
97
+ * @return {Object} FeatureCollection with geometry/bbox converted to JSTS Geometries.
98
+ */
99
+ 'FeatureCollection': function(obj) {
100
+ var featureCollection = {};
101
+
102
+ if (obj.features) {
103
+ featureCollection.features = [];
104
+
105
+ for (var i = 0; i < obj.features.length; ++i) {
106
+ featureCollection.features.push(this.read(obj.features[i]));
107
+ }
108
+ }
109
+
110
+ if (obj.bbox) {
111
+ featureCollection.bbox = this.parse.bbox.apply(this, [obj.bbox]);
112
+ }
113
+
114
+ return featureCollection;
115
+ },
116
+
117
+
118
+ /**
119
+ * Convert the ordinates in an array to an array of jsts.geom.Coordinates
120
+ *
121
+ * @param {Array}
122
+ * array Array with {Number}s.
123
+ *
124
+ * @return {Array} Array with jsts.geom.Coordinates.
125
+ */
126
+ 'coordinates': function(array) {
127
+ var coordinates = [];
128
+
129
+ for (var i = 0; i < array.length; ++i) {
130
+ var sub = array[i];
131
+ coordinates.push(new jsts.geom.Coordinate(sub[0], sub[1]));
132
+ }
133
+
134
+ return coordinates;
135
+ },
136
+
137
+ /**
138
+ * Convert the bbox to a jsts.geom.LinearRing
139
+ *
140
+ * @param {Array}
141
+ * array Array with [xMin, yMin, xMax, yMax].
142
+ *
143
+ * @return {Array} Array with jsts.geom.Coordinates.
144
+ */
145
+ 'bbox': function(array) {
146
+ return this.geometryFactory.createLinearRing([
147
+ new jsts.geom.Coordinate(array[0], array[1]),
148
+ new jsts.geom.Coordinate(array[2], array[1]),
149
+ new jsts.geom.Coordinate(array[2], array[3]),
150
+ new jsts.geom.Coordinate(array[0], array[3]),
151
+ new jsts.geom.Coordinate(array[0], array[1])
152
+ ]);
153
+ },
154
+
155
+
156
+ /**
157
+ * Convert an Array with ordinates to a jsts.geom.Point
158
+ *
159
+ * @param {Array}
160
+ * array Array with ordinates.
161
+ *
162
+ * @return {jsts.geom.Point} Point.
163
+ */
164
+ 'Point': function(array) {
165
+ var coordinate = new jsts.geom.Coordinate(array[0], array[1]);
166
+ return this.geometryFactory.createPoint(coordinate);
167
+ },
168
+
169
+ /**
170
+ * Convert an Array with coordinates to a jsts.geom.MultiPoint
171
+ *
172
+ * @param {Array}
173
+ * array Array with coordinates.
174
+ *
175
+ * @return {jsts.geom.MultiPoint} MultiPoint.
176
+ */
177
+ 'MultiPoint': function(array) {
178
+ var points = [];
179
+
180
+ for (var i = 0; i < array.length; ++i) {
181
+ points.push(this.parse.Point.apply(this, [array[i]]));
182
+ }
183
+
184
+ return this.geometryFactory.createMultiPoint(points);
185
+ },
186
+
187
+ /**
188
+ * Convert an Array with coordinates to a jsts.geom.LineString
189
+ *
190
+ * @param {Array}
191
+ * array Array with coordinates.
192
+ *
193
+ * @return {jsts.geom.LineString} LineString.
194
+ */
195
+ 'LineString': function(array) {
196
+ var coordinates = this.parse.coordinates.apply(this, [array]);
197
+ return this.geometryFactory.createLineString(coordinates);
198
+ },
199
+
200
+ /**
201
+ * Convert an Array with coordinates to a jsts.geom.MultiLineString
202
+ *
203
+ * @param {Array}
204
+ * array Array with coordinates.
205
+ *
206
+ * @return {jsts.geom.MultiLineString} MultiLineString.
207
+ */
208
+ 'MultiLineString': function(array) {
209
+ var lineStrings = [];
210
+
211
+ for (var i = 0; i < array.length; ++i) {
212
+ lineStrings.push(this.parse.LineString.apply(this, [array[i]]));
213
+ }
214
+
215
+ return this.geometryFactory.createMultiLineString(lineStrings);
216
+ },
217
+
218
+ /**
219
+ * Convert an Array to a jsts.geom.Polygon
220
+ *
221
+ * @param {Array}
222
+ * array Array with shell and holes.
223
+ *
224
+ * @return {jsts.geom.Polygon} Polygon.
225
+ */
226
+ 'Polygon': function(array) {
227
+ // shell
228
+ var shellCoordinates = this.parse.coordinates.apply(this, [array[0]]);
229
+ var shell = this.geometryFactory.createLinearRing(shellCoordinates);
230
+
231
+ // holes
232
+ var holes = [];
233
+ for (var i = 1; i < array.length; ++i) {
234
+ var hole = array[i];
235
+ var coordinates = this.parse.coordinates.apply(this, [hole]);
236
+ var linearRing = this.geometryFactory.createLinearRing(coordinates);
237
+ holes.push(linearRing);
238
+ }
239
+
240
+ return this.geometryFactory.createPolygon(shell, holes);
241
+ },
242
+
243
+ /**
244
+ * Convert an Array to a jsts.geom.MultiPolygon
245
+ *
246
+ * @param {Array}
247
+ * array Array of arrays with shell and rings.
248
+ *
249
+ * @return {jsts.geom.MultiPolygon} MultiPolygon.
250
+ */
251
+ 'MultiPolygon': function(array) {
252
+ var polygons = [];
253
+
254
+ for (var i = 0; i < array.length; ++i) {
255
+ var polygon = array[i];
256
+ polygons.push(this.parse.Polygon.apply(this, [polygon]));
257
+ }
258
+
259
+ return this.geometryFactory.createMultiPolygon(polygons);
260
+ },
261
+
262
+ /**
263
+ * Convert an Array to a jsts.geom.GeometryCollection
264
+ *
265
+ * @param {Array}
266
+ * array Array of GeoJSON geometries.
267
+ *
268
+ * @return {jsts.geom.GeometryCollection} GeometryCollection.
269
+ */
270
+ 'GeometryCollection': function(array) {
271
+ var geometries = [];
272
+
273
+ for (var i = 0; i < array.length; ++i) {
274
+ var geometry = array[i];
275
+ geometries.push(this.read(geometry));
276
+ }
277
+
278
+ return this.geometryFactory.createGeometryCollection(geometries);
279
+ }
280
+ };
281
+
282
+ /**
283
+ * Serialize a Geometry object into GeoJSON
284
+ *
285
+ * @param {jsts.geom.geometry}
286
+ * geometry A Geometry or array of Geometries.
287
+ * @return {Object} A GeoJSON object represting the input Geometry/Geometries.
288
+ */
289
+ jsts.io.GeoJSONParser.prototype.write = function(geometry) {
290
+ var type = geometry.CLASS_NAME.slice(10);
291
+
292
+ if (!this.extract[type]) {
293
+ throw new Error('Geometry is not supported');
294
+ }
295
+
296
+ return this.extract[type].apply(this, [geometry]);
297
+ };
298
+
299
+ jsts.io.GeoJSONParser.prototype.extract = {
300
+ /**
301
+ * Convert a jsts.geom.Coordinate to an Array
302
+ *
303
+ * @param {jsts.geom.Coordinate}
304
+ * coordinate Coordinate to convert.
305
+ *
306
+ * @return {Array} Array of ordinates.
307
+ */
308
+ 'coordinate': function(coordinate) {
309
+ return [coordinate.x, coordinate.y];
310
+ },
311
+
312
+ /**
313
+ * Convert a jsts.geom.Point to a GeoJSON object
314
+ *
315
+ * @param {jsts.geom.Point}
316
+ * point Point to convert.
317
+ *
318
+ * @return {Array} Array of 2 ordinates (paired to a coordinate).
319
+ */
320
+ 'Point': function(point) {
321
+ var array = this.extract.coordinate.apply(this, [point.coordinate]);
322
+
323
+ return {
324
+ type: 'Point',
325
+ coordinates: array
326
+ };
327
+ },
328
+
329
+ /**
330
+ * Convert a jsts.geom.MultiPoint to a GeoJSON object
331
+ *
332
+ * @param {jsts.geom.MultiPoint}
333
+ * multipoint MultiPoint to convert.
334
+ *
335
+ * @return {Array} Array of coordinates.
336
+ */
337
+ 'MultiPoint': function(multipoint) {
338
+ var array = [];
339
+
340
+ for (var i = 0; i < multipoint.geometries.length; ++i) {
341
+ var point = multipoint.geometries[i];
342
+ var geoJson = this.extract.Point.apply(this, [point]);
343
+ array.push(geoJson.coordinates);
344
+ }
345
+
346
+ return {
347
+ type: 'MultiPoint',
348
+ coordinates: array
349
+ };
350
+ },
351
+
352
+ /**
353
+ * Convert a jsts.geom.LineString to a GeoJSON object
354
+ *
355
+ * @param {jsts.geom.LineString}
356
+ * linestring LineString to convert.
357
+ *
358
+ * @return {Array} Array of coordinates.
359
+ */
360
+ 'LineString': function(linestring) {
361
+ var array = [];
362
+
363
+ for (var i = 0; i < linestring.points.length; ++i) {
364
+ var coordinate = linestring.points[i];
365
+ array.push(this.extract.coordinate.apply(this, [coordinate]));
366
+ }
367
+
368
+ return {
369
+ type: 'LineString',
370
+ coordinates: array
371
+ };
372
+ },
373
+
374
+ /**
375
+ * Convert a jsts.geom.MultiLineString to a GeoJSON object
376
+ *
377
+ * @param {jsts.geom.MultiLineString}
378
+ * multilinestring MultiLineString to convert.
379
+ *
380
+ * @return {Array} Array of Array of coordinates.
381
+ */
382
+ 'MultiLineString': function(multilinestring) {
383
+ var array = [];
384
+
385
+ for (var i = 0; i < multilinestring.geometries.length; ++i) {
386
+ var linestring = multilinestring.geometries[i];
387
+ var geoJson = this.extract.LineString.apply(this, [linestring]);
388
+ array.push(geoJson.coordinates);
389
+ }
390
+
391
+ return {
392
+ type: 'MultiLineString',
393
+ coordinates: array
394
+ };
395
+ },
396
+
397
+ /**
398
+ * Convert a jsts.geom.Polygon to a GeoJSON object
399
+ *
400
+ * @param {jsts.geom.Polygon}
401
+ * polygon Polygon to convert.
402
+ *
403
+ * @return {Array} Array with shell, holes.
404
+ */
405
+ 'Polygon': function(polygon) {
406
+ var array = [];
407
+
408
+ // shell
409
+ var shellGeoJson = this.extract.LineString.apply(this, [polygon.shell]);
410
+ array.push(shellGeoJson.coordinates);
411
+
412
+ // holes
413
+ for (var i = 0; i < polygon.holes.length; ++i) {
414
+ var hole = polygon.holes[i];
415
+ var holeGeoJson = this.extract.LineString.apply(this, [hole]);
416
+ array.push(holeGeoJson.coordinates);
417
+ }
418
+
419
+ return {
420
+ type: 'Polygon',
421
+ coordinates: array
422
+ };
423
+ },
424
+
425
+ /**
426
+ * Convert a jsts.geom.MultiPolygon to a GeoJSON object
427
+ *
428
+ * @param {jsts.geom.MultiPolygon}
429
+ * multipolygon MultiPolygon to convert.
430
+ *
431
+ * @return {Array} Array of polygons.
432
+ */
433
+ 'MultiPolygon': function(multipolygon) {
434
+ var array = [];
435
+
436
+ for (var i = 0; i < multipolygon.geometries.length; ++i) {
437
+ var polygon = multipolygon.geometries[i];
438
+ var geoJson = this.extract.Polygon.apply(this, [polygon]);
439
+ array.push(geoJson.coordinates);
440
+ }
441
+
442
+ return {
443
+ type: 'MultiPolygon',
444
+ coordinates: array
445
+ };
446
+ },
447
+
448
+ /**
449
+ * Convert a jsts.geom.GeometryCollection to a GeoJSON object
450
+ *
451
+ * @param {jsts.geom.GeometryCollection}
452
+ * collection GeometryCollection to convert.
453
+ *
454
+ * @return {Array} Array of geometries.
455
+ */
456
+ 'GeometryCollection': function(collection) {
457
+ var array = [];
458
+
459
+ for (var i = 0; i < collection.geometries.length; ++i) {
460
+ var geometry = collection.geometries[i];
461
+ var type = geometry.CLASS_NAME.slice(10);
462
+ array.push(this.extract[type].apply(this, [geometry]));
463
+ }
464
+
465
+ return {
466
+ type: 'GeometryCollection',
467
+ geometries: array
468
+ };
469
+ }
470
+ };
471
+ })();