jsts-rails 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/jsts-rails/version.rb +1 -1
- data/vendor/assets/javascripts/javascript.util.js +33 -1
- data/vendor/assets/javascripts/jsts-original.js +164 -1573
- data/vendor/assets/javascripts/jsts.js +197 -0
- data/vendor/assets/javascripts/jsts/algorithm/Angle.js +387 -0
- data/vendor/assets/javascripts/jsts/algorithm/BoundaryNodeRule.js +67 -0
- data/vendor/assets/javascripts/jsts/algorithm/CGAlgorithms.js +596 -0
- data/vendor/assets/javascripts/jsts/algorithm/CentralEndpointIntersector.js +118 -0
- data/vendor/assets/javascripts/jsts/algorithm/CentroidArea.js +225 -0
- data/vendor/assets/javascripts/jsts/algorithm/CentroidLine.js +85 -0
- data/vendor/assets/javascripts/jsts/algorithm/CentroidPoint.js +77 -0
- data/vendor/assets/javascripts/jsts/algorithm/ConvexHull.js +409 -0
- data/vendor/assets/javascripts/jsts/algorithm/HCoordinate.js +234 -0
- data/vendor/assets/javascripts/jsts/algorithm/LineIntersector.js +502 -0
- data/vendor/assets/javascripts/jsts/algorithm/MCPointInRing.js +124 -0
- data/vendor/assets/javascripts/jsts/algorithm/PointLocator.js +247 -0
- data/vendor/assets/javascripts/jsts/algorithm/RayCrossingCounter.js +215 -0
- data/vendor/assets/javascripts/jsts/algorithm/RobustDeterminant.js +353 -0
- data/vendor/assets/javascripts/jsts/algorithm/RobustLineIntersector.js +477 -0
- data/vendor/assets/javascripts/jsts/algorithm/distance/DiscreteHausdorffDistance.js +228 -0
- data/vendor/assets/javascripts/jsts/algorithm/distance/DistanceToPoint.js +68 -0
- data/vendor/assets/javascripts/jsts/algorithm/distance/PointPairDistance.js +104 -0
- data/vendor/assets/javascripts/jsts/algorithm/locate/PointOnGeometryLocator.js +7 -0
- data/vendor/assets/javascripts/jsts/algorithm/locate/SimplePointInAreaLocator.js +102 -0
- data/vendor/assets/javascripts/jsts/geom/Coordinate.js +158 -0
- data/vendor/assets/javascripts/jsts/geom/CoordinateArrays.js +148 -0
- data/vendor/assets/javascripts/jsts/geom/CoordinateFilter.js +29 -0
- data/vendor/assets/javascripts/jsts/geom/CoordinateList.js +157 -0
- data/vendor/assets/javascripts/jsts/geom/CoordinateSequenceFilter.js +63 -0
- data/vendor/assets/javascripts/jsts/geom/Dimension.js +137 -0
- data/vendor/assets/javascripts/jsts/geom/Envelope.js +833 -0
- data/vendor/assets/javascripts/jsts/geom/Geometry.js +1535 -0
- data/vendor/assets/javascripts/jsts/geom/GeometryCollection.js +230 -0
- data/vendor/assets/javascripts/jsts/geom/GeometryComponentFilter.js +36 -0
- data/vendor/assets/javascripts/jsts/geom/GeometryFactory.js +263 -0
- data/vendor/assets/javascripts/jsts/geom/GeometryFilter.js +29 -0
- data/vendor/assets/javascripts/jsts/geom/IntersectionMatrix.js +650 -0
- data/vendor/assets/javascripts/jsts/geom/LineSegment.js +275 -0
- data/vendor/assets/javascripts/jsts/geom/LineString.js +299 -0
- data/vendor/assets/javascripts/jsts/geom/LinearRing.js +69 -0
- data/vendor/assets/javascripts/jsts/geom/Location.js +83 -0
- data/vendor/assets/javascripts/jsts/geom/MultiLineString.js +47 -0
- data/vendor/assets/javascripts/jsts/geom/MultiPoint.js +64 -0
- data/vendor/assets/javascripts/jsts/geom/MultiPolygon.js +64 -0
- data/vendor/assets/javascripts/jsts/geom/Point.js +197 -0
- data/vendor/assets/javascripts/jsts/geom/Polygon.js +263 -0
- data/vendor/assets/javascripts/jsts/geom/PrecisionModel.js +187 -0
- data/vendor/assets/javascripts/jsts/geom/Triangle.js +313 -0
- data/vendor/assets/javascripts/jsts/geom/util/GeometryCombiner.js +143 -0
- data/vendor/assets/javascripts/jsts/geom/util/GeometryExtracter.js +76 -0
- data/vendor/assets/javascripts/jsts/geom/util/GeometryTransformer.js +295 -0
- data/vendor/assets/javascripts/jsts/geom/util/LinearComponentExtracter.js +207 -0
- data/vendor/assets/javascripts/jsts/geom/util/PointExtracter.js +67 -0
- data/vendor/assets/javascripts/jsts/geom/util/PolygonExtracter.js +71 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Depth.js +145 -0
- data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdge.js +270 -0
- data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdgeStar.js +388 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Edge.js +291 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeEnd.js +188 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeEndStar.js +322 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersection.js +122 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersectionList.js +146 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeList.js +111 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeNodingValidator.js +76 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeRing.js +230 -0
- data/vendor/assets/javascripts/jsts/geomgraph/GeometryGraph.js +469 -0
- data/vendor/assets/javascripts/jsts/geomgraph/GraphComponent.js +181 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Label.js +316 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Node.js +105 -0
- data/vendor/assets/javascripts/jsts/geomgraph/NodeFactory.js +22 -0
- data/vendor/assets/javascripts/jsts/geomgraph/NodeMap.js +128 -0
- data/vendor/assets/javascripts/jsts/geomgraph/PlanarGraph.js +214 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Position.js +63 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Quadrant.js +143 -0
- data/vendor/assets/javascripts/jsts/geomgraph/TopologyLocation.js +251 -0
- data/vendor/assets/javascripts/jsts/geomgraph/index/EdgeSetIntersector.js +47 -0
- data/vendor/assets/javascripts/jsts/geomgraph/index/SegmentIntersector.js +298 -0
- data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleEdgeSetIntersector.js +107 -0
- data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleMCSweepLineIntersector.js +29 -0
- data/vendor/assets/javascripts/jsts/index/ArrayListVisitor.js +37 -0
- data/vendor/assets/javascripts/jsts/index/DoubleBits.js +132 -0
- data/vendor/assets/javascripts/jsts/index/IntervalSize.js +55 -0
- data/vendor/assets/javascripts/jsts/index/ItemVisitor.js +23 -0
- data/vendor/assets/javascripts/jsts/index/SpatialIndex.js +67 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Bintree.js +224 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Interval.js +160 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Key.js +110 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Node.js +204 -0
- data/vendor/assets/javascripts/jsts/index/bintree/NodeBase.js +220 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Root.js +113 -0
- data/vendor/assets/javascripts/jsts/index/chain/MonotoneChain.js +244 -0
- data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainBuilder.js +106 -0
- data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainOverlapAction.js +56 -0
- data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainSelectAction.js +44 -0
- data/vendor/assets/javascripts/jsts/index/kdtree/KdNode.js +171 -0
- data/vendor/assets/javascripts/jsts/index/kdtree/KdTree.js +218 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/Key.js +134 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/Node.js +220 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/NodeBase.js +330 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/Quadtree.js +228 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/Root.js +105 -0
- data/vendor/assets/javascripts/jsts/index/strtree/AbstractNode.js +107 -0
- data/vendor/assets/javascripts/jsts/index/strtree/AbstractSTRtree.js +594 -0
- data/vendor/assets/javascripts/jsts/index/strtree/Boundable.js +37 -0
- data/vendor/assets/javascripts/jsts/index/strtree/BoundablePair.js +0 -0
- data/vendor/assets/javascripts/jsts/index/strtree/Interval.js +94 -0
- data/vendor/assets/javascripts/jsts/index/strtree/ItemBoundable.js +60 -0
- data/vendor/assets/javascripts/jsts/index/strtree/SIRtree.js +122 -0
- data/vendor/assets/javascripts/jsts/index/strtree/STRtree.js +450 -0
- data/vendor/assets/javascripts/jsts/io/GeoJSONParser.js +471 -0
- data/vendor/assets/javascripts/jsts/io/GeoJSONReader.js +58 -0
- data/vendor/assets/javascripts/jsts/io/GeoJSONWriter.js +38 -0
- data/vendor/assets/javascripts/jsts/io/OpenLayersParser.js +245 -0
- data/vendor/assets/javascripts/jsts/io/WKTParser.js +421 -0
- data/vendor/assets/javascripts/jsts/io/WKTReader.js +68 -0
- data/vendor/assets/javascripts/jsts/io/WKTWriter.js +61 -0
- data/vendor/assets/javascripts/jsts/noding/BasicSegmentString.js +87 -0
- data/vendor/assets/javascripts/jsts/noding/FastNodingValidator.js +127 -0
- data/vendor/assets/javascripts/jsts/noding/InteriorIntersectionFinder.js +171 -0
- data/vendor/assets/javascripts/jsts/noding/IntersectionAdder.js +198 -0
- data/vendor/assets/javascripts/jsts/noding/IntersectionFinderAdder.js +79 -0
- data/vendor/assets/javascripts/jsts/noding/MCIndexNoder.js +147 -0
- data/vendor/assets/javascripts/jsts/noding/NodableSegmentString.js +35 -0
- data/vendor/assets/javascripts/jsts/noding/NodedSegmentString.js +235 -0
- data/vendor/assets/javascripts/jsts/noding/Noder.js +41 -0
- data/vendor/assets/javascripts/jsts/noding/NodingValidator.js +5 -0
- data/vendor/assets/javascripts/jsts/noding/Octant.js +84 -0
- data/vendor/assets/javascripts/jsts/noding/OrientedCoordinateArray.js +94 -0
- data/vendor/assets/javascripts/jsts/noding/ScaledNoder.js +105 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentIntersector.js +45 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentNode.js +70 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentNodeList.js +262 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentPointComparator.js +78 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentString.js +61 -0
- data/vendor/assets/javascripts/jsts/noding/SinglePassNoder.js +51 -0
- data/vendor/assets/javascripts/jsts/noding/snapround/HotPixel.js +271 -0
- data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexPointSnapper.js +96 -0
- data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexSnapRounder.js +147 -0
- data/vendor/assets/javascripts/jsts/operation/BoundaryOp.js +166 -0
- data/vendor/assets/javascripts/jsts/operation/GeometryGraphOperation.js +90 -0
- data/vendor/assets/javascripts/jsts/operation/IsSimpleOp.js +293 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferBuilder.js +317 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferInputLineSimplifier.js +294 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferOp.js +340 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferParameters.js +328 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferSubgraph.js +296 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveBuilder.js +369 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveSetBuilder.js +301 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentGenerator.js +777 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentString.js +109 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/RightmostEdgeFinder.js +164 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/SubgraphDepthLocater.js +220 -0
- data/vendor/assets/javascripts/jsts/operation/distance/ConnectedElementLocationFilter.js +67 -0
- data/vendor/assets/javascripts/jsts/operation/distance/DistanceOp.js +506 -0
- data/vendor/assets/javascripts/jsts/operation/distance/GeometryLocation.js +102 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/LineBuilder.js +194 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/MaximalEdgeRing.js +72 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/MinimalEdgeRing.js +33 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/OverlayNodeFactory.js +26 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/OverlayOp.js +584 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/PointBuilder.js +103 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/PolygonBuilder.js +282 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/snap/GeometrySnapper.js +228 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/snap/LineStringSnapper.js +228 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapIfNeededOverlayOp.js +85 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapOverlayOp.js +134 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/EdgeRing.js +259 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeDirectedEdge.js +94 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeEdge.js +31 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeGraph.js +507 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/Polygonizer.js +259 -0
- data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBuilder.js +140 -0
- data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundle.js +183 -0
- data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundleStar.js +48 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateComputer.js +444 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateNode.js +46 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeFactory.js +25 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeGraph.js +118 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateOp.js +75 -0
- data/vendor/assets/javascripts/jsts/operation/union/CascadedPolygonUnion.js +319 -0
- data/vendor/assets/javascripts/jsts/operation/union/PointGeometryUnion.js +118 -0
- data/vendor/assets/javascripts/jsts/operation/union/UnaryUnionOp.js +244 -0
- data/vendor/assets/javascripts/jsts/operation/union/UnionInteracting.js +156 -0
- data/vendor/assets/javascripts/jsts/operation/valid/ConnectedInteriorTester.js +259 -0
- data/vendor/assets/javascripts/jsts/operation/valid/ConsistentAreaTester.js +127 -0
- data/vendor/assets/javascripts/jsts/operation/valid/IndexedNestedRingTester.js +89 -0
- data/vendor/assets/javascripts/jsts/operation/valid/IsValidOp.js +619 -0
- data/vendor/assets/javascripts/jsts/operation/valid/TopologyValidationError.js +199 -0
- data/vendor/assets/javascripts/jsts/planargraph/DirectedEdge.js +232 -0
- data/vendor/assets/javascripts/jsts/planargraph/DirectedEdgeStar.js +168 -0
- data/vendor/assets/javascripts/jsts/planargraph/Edge.js +124 -0
- data/vendor/assets/javascripts/jsts/planargraph/GraphComponent.js +182 -0
- data/vendor/assets/javascripts/jsts/planargraph/Node.js +127 -0
- data/vendor/assets/javascripts/jsts/planargraph/NodeMap.js +76 -0
- data/vendor/assets/javascripts/jsts/planargraph/PlanarGraph.js +246 -0
- data/vendor/assets/javascripts/jsts/simplify/LineSegmentIndex.js +101 -0
- data/vendor/assets/javascripts/jsts/triangulate/DelaunayTriangulationBuilder.js +224 -0
- data/vendor/assets/javascripts/jsts/triangulate/IncrementalDelaunayTriangulator.js +111 -0
- data/vendor/assets/javascripts/jsts/triangulate/VoronoiDiagramBuilder.js +172 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/LastFoundQuadEdgeLocator.js +52 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdge.js +437 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdgeSubdivision.js +1064 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/TrianglePredicate.js +350 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/Vertex.js +496 -0
- data/vendor/assets/javascripts/jsts/util/Assert.js +80 -0
- data/vendor/assets/javascripts/jsts/util/AssertionFailedException.js +23 -0
- data/vendor/assets/javascripts/jsts/util/UniqueCoordinateArrayFilter.js +52 -0
- metadata +204 -1
@@ -0,0 +1,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
|
+
})();
|