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,58 @@
|
|
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
|
+
(function() {
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Converts a geometry in GeoJSON to a {@link Geometry}.
|
10
|
+
* <p>
|
11
|
+
* A <code>GeoJSONReader</code> is parameterized by a <code>GeometryFactory</code>,
|
12
|
+
* to allow it to create <code>Geometry</code> objects of the appropriate
|
13
|
+
* implementation. In particular, the <code>GeometryFactory</code> determines
|
14
|
+
* the <code>PrecisionModel</code> and <code>SRID</code> that is used.
|
15
|
+
* <P>
|
16
|
+
*
|
17
|
+
* @constructor
|
18
|
+
*/
|
19
|
+
jsts.io.GeoJSONReader = function(geometryFactory) {
|
20
|
+
this.geometryFactory = geometryFactory || new jsts.geom.GeometryFactory();
|
21
|
+
this.precisionModel = this.geometryFactory.getPrecisionModel();
|
22
|
+
this.parser = new jsts.io.GeoJSONParser(this.geometryFactory);
|
23
|
+
};
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Reads a GeoJSON representation of a {@link Geometry}
|
27
|
+
*
|
28
|
+
* @param {object}
|
29
|
+
* geoJson a GeoJSON Object or String.
|
30
|
+
* @return {jsts.geom.Geometry} a <code>Geometry.</code>
|
31
|
+
*/
|
32
|
+
jsts.io.GeoJSONReader.prototype.read = function(geoJson) {
|
33
|
+
var geometry = this.parser.read(geoJson);
|
34
|
+
|
35
|
+
if (this.precisionModel.getType() === jsts.geom.PrecisionModel.FIXED) {
|
36
|
+
this.reducePrecision(geometry);
|
37
|
+
}
|
38
|
+
|
39
|
+
return geometry;
|
40
|
+
};
|
41
|
+
|
42
|
+
// NOTE: this is a hack
|
43
|
+
jsts.io.GeoJSONReader.prototype.reducePrecision = function(geometry) {
|
44
|
+
var i, len;
|
45
|
+
|
46
|
+
if (geometry.coordinate) {
|
47
|
+
this.precisionModel.makePrecise(geometry.coordinate);
|
48
|
+
} else if (geometry.points) {
|
49
|
+
for (i = 0, len = geometry.points.length; i < len; i++) {
|
50
|
+
this.precisionModel.makePrecise(geometry.points[i]);
|
51
|
+
}
|
52
|
+
} else if (geometry.geometries) {
|
53
|
+
for (i = 0, len = geometry.geometries.length; i < len; i++) {
|
54
|
+
this.reducePrecision(geometry.geometries[i]);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
};
|
58
|
+
})();
|
@@ -0,0 +1,38 @@
|
|
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
|
+
(function() {
|
8
|
+
/**
|
9
|
+
* Writes the GeoJSON representation of a {@link Geometry}. The
|
10
|
+
* The GeoJSON format is defined <A
|
11
|
+
* HREF="http://geojson.org/geojson-spec.html">here</A>.
|
12
|
+
* <p>
|
13
|
+
* The <code>GeoJSONWriter</code> outputs coordinates rounded to the precision
|
14
|
+
* model. Only the maximum number of decimal places necessary to represent the
|
15
|
+
* ordinates to the required precision will be output.
|
16
|
+
* <p>
|
17
|
+
*
|
18
|
+
* @see WKTReader
|
19
|
+
* @constructor
|
20
|
+
*/
|
21
|
+
jsts.io.GeoJSONWriter = function() {
|
22
|
+
this.parser = new jsts.io.GeoJSONParser(this.geometryFactory);
|
23
|
+
};
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Converts a <code>Geometry</code> to its GeoJSON representation.
|
27
|
+
*
|
28
|
+
* @param {jsts.geom.Geometry}
|
29
|
+
* geometry a <code>Geometry</code> to process.
|
30
|
+
* @return {Object} The GeoJSON representation of the Geometry.
|
31
|
+
*/
|
32
|
+
|
33
|
+
jsts.io.GeoJSONWriter.prototype.write = function(geometry) {
|
34
|
+
var geoJson = this.parser.write(geometry);
|
35
|
+
|
36
|
+
return geoJson;
|
37
|
+
};
|
38
|
+
})();
|
@@ -0,0 +1,245 @@
|
|
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
|
+
jsts.io.OpenLayersParser = function(geometryFactory) {
|
8
|
+
this.geometryFactory = geometryFactory || new jsts.geom.GeometryFactory();
|
9
|
+
};
|
10
|
+
|
11
|
+
/**
|
12
|
+
* @param geometry
|
13
|
+
* {OpenLayers.Geometry}
|
14
|
+
* @return {jsts.geom.Geometry}
|
15
|
+
*/
|
16
|
+
jsts.io.OpenLayersParser.prototype.read = function(geometry) {
|
17
|
+
if (geometry.CLASS_NAME === 'OpenLayers.Geometry.Point') {
|
18
|
+
return this.convertFromPoint(geometry);
|
19
|
+
} else if (geometry.CLASS_NAME === 'OpenLayers.Geometry.LineString') {
|
20
|
+
return this.convertFromLineString(geometry);
|
21
|
+
} else if (geometry.CLASS_NAME === 'OpenLayers.Geometry.LinearRing') {
|
22
|
+
return this.convertFromLinearRing(geometry);
|
23
|
+
} else if (geometry.CLASS_NAME === 'OpenLayers.Geometry.Polygon') {
|
24
|
+
return this.convertFromPolygon(geometry);
|
25
|
+
} else if (geometry.CLASS_NAME === 'OpenLayers.Geometry.MultiPoint') {
|
26
|
+
return this.convertFromMultiPoint(geometry);
|
27
|
+
} else if (geometry.CLASS_NAME === 'OpenLayers.Geometry.MultiLineString') {
|
28
|
+
return this.convertFromMultiLineString(geometry);
|
29
|
+
} else if (geometry.CLASS_NAME === 'OpenLayers.Geometry.MultiPolygon') {
|
30
|
+
return this.convertFromMultiPolygon(geometry);
|
31
|
+
} else if (geometry.CLASS_NAME === 'OpenLayers.Geometry.Collection') {
|
32
|
+
return this.convertFromCollection(geometry);
|
33
|
+
}
|
34
|
+
};
|
35
|
+
|
36
|
+
jsts.io.OpenLayersParser.prototype.convertFromPoint = function(point) {
|
37
|
+
return this.geometryFactory.createPoint(new jsts.geom.Coordinate(point.x,
|
38
|
+
point.y));
|
39
|
+
};
|
40
|
+
|
41
|
+
jsts.io.OpenLayersParser.prototype.convertFromLineString = function(lineString) {
|
42
|
+
var i;
|
43
|
+
var coordinates = [];
|
44
|
+
|
45
|
+
for (i = 0; i < lineString.components.length; i++) {
|
46
|
+
coordinates.push(new jsts.geom.Coordinate(lineString.components[i].x,
|
47
|
+
lineString.components[i].y));
|
48
|
+
}
|
49
|
+
|
50
|
+
return this.geometryFactory.createLineString(coordinates);
|
51
|
+
};
|
52
|
+
|
53
|
+
jsts.io.OpenLayersParser.prototype.convertFromLinearRing = function(linearRing) {
|
54
|
+
var i;
|
55
|
+
var coordinates = [];
|
56
|
+
|
57
|
+
for (i = 0; i < linearRing.components.length; i++) {
|
58
|
+
coordinates.push(new jsts.geom.Coordinate(linearRing.components[i].x,
|
59
|
+
linearRing.components[i].y));
|
60
|
+
}
|
61
|
+
|
62
|
+
return this.geometryFactory.createLinearRing(coordinates);
|
63
|
+
};
|
64
|
+
|
65
|
+
jsts.io.OpenLayersParser.prototype.convertFromPolygon = function(polygon) {
|
66
|
+
var i;
|
67
|
+
var shell = null;
|
68
|
+
var holes = [];
|
69
|
+
|
70
|
+
for (i = 0; i < polygon.components.length; i++) {
|
71
|
+
var linearRing = this.convertFromLinearRing(polygon.components[i]);
|
72
|
+
|
73
|
+
if (i === 0) {
|
74
|
+
shell = linearRing;
|
75
|
+
} else {
|
76
|
+
holes.push(linearRing);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
return this.geometryFactory.createPolygon(shell, holes);
|
81
|
+
};
|
82
|
+
|
83
|
+
jsts.io.OpenLayersParser.prototype.convertFromMultiPoint = function(multiPoint) {
|
84
|
+
var i;
|
85
|
+
var points = [];
|
86
|
+
|
87
|
+
for (i = 0; i < multiPoint.components.length; i++) {
|
88
|
+
points.push(this.convertFromPoint(multiPoint.components[i]));
|
89
|
+
}
|
90
|
+
|
91
|
+
return this.geometryFactory.createMultiPoint(points);
|
92
|
+
};
|
93
|
+
|
94
|
+
jsts.io.OpenLayersParser.prototype.convertFromMultiLineString = function(
|
95
|
+
multiLineString) {
|
96
|
+
var i;
|
97
|
+
var lineStrings = [];
|
98
|
+
|
99
|
+
for (i = 0; i < multiLineString.components.length; i++) {
|
100
|
+
lineStrings.push(this.convertFromLineString(multiLineString.components[i]));
|
101
|
+
}
|
102
|
+
|
103
|
+
return this.geometryFactory.createMultiLineString(lineStrings);
|
104
|
+
};
|
105
|
+
|
106
|
+
jsts.io.OpenLayersParser.prototype.convertFromMultiPolygon = function(
|
107
|
+
multiPolygon) {
|
108
|
+
var i;
|
109
|
+
var polygons = [];
|
110
|
+
|
111
|
+
for (i = 0; i < multiPolygon.components.length; i++) {
|
112
|
+
polygons.push(this.convertFromPolygon(multiPolygon.components[i]));
|
113
|
+
}
|
114
|
+
|
115
|
+
return this.geometryFactory.createMultiPolygon(polygons);
|
116
|
+
};
|
117
|
+
|
118
|
+
jsts.io.OpenLayersParser.prototype.convertFromCollection = function(collection) {
|
119
|
+
var i;
|
120
|
+
var geometries = [];
|
121
|
+
|
122
|
+
for (i = 0; i < collection.components.length; i++) {
|
123
|
+
geometries.push(this.convertFrom(collection.components[i]));
|
124
|
+
}
|
125
|
+
|
126
|
+
return this.geometryFactory.createGeometryCollection(geometries);
|
127
|
+
};
|
128
|
+
|
129
|
+
/**
|
130
|
+
* @param geometry
|
131
|
+
* {jsts.geom.Geometry}
|
132
|
+
* @return {OpenLayers.Geometry}
|
133
|
+
*/
|
134
|
+
jsts.io.OpenLayersParser.prototype.write = function(geometry) {
|
135
|
+
if (geometry.CLASS_NAME === 'jsts.geom.Point') {
|
136
|
+
return this.convertToPoint(geometry.coordinate);
|
137
|
+
} else if (geometry.CLASS_NAME === 'jsts.geom.LineString') {
|
138
|
+
return this.convertToLineString(geometry);
|
139
|
+
} else if (geometry.CLASS_NAME === 'jsts.geom.LinearRing') {
|
140
|
+
return this.convertToLinearRing(geometry);
|
141
|
+
} else if (geometry.CLASS_NAME === 'jsts.geom.Polygon') {
|
142
|
+
return this.convertToPolygon(geometry);
|
143
|
+
} else if (geometry.CLASS_NAME === 'jsts.geom.MultiPoint') {
|
144
|
+
return this.convertToMultiPoint(geometry);
|
145
|
+
} else if (geometry.CLASS_NAME === 'jsts.geom.MultiLineString') {
|
146
|
+
return this.convertToMultiLineString(geometry);
|
147
|
+
} else if (geometry.CLASS_NAME === 'jsts.geom.MultiPolygon') {
|
148
|
+
return this.convertToMultiPolygon(geometry);
|
149
|
+
} else if (geometry.CLASS_NAME === 'jsts.geom.GeometryCollection') {
|
150
|
+
return this.convertToCollection(geometry);
|
151
|
+
}
|
152
|
+
};
|
153
|
+
|
154
|
+
jsts.io.OpenLayersParser.prototype.convertToPoint = function(coordinate) {
|
155
|
+
return new OpenLayers.Geometry.Point(coordinate.x, coordinate.y);
|
156
|
+
};
|
157
|
+
|
158
|
+
jsts.io.OpenLayersParser.prototype.convertToLineString = function(lineString) {
|
159
|
+
var i;
|
160
|
+
var points = [];
|
161
|
+
|
162
|
+
for (i = 0; i < lineString.points.length; i++) {
|
163
|
+
var coordinate = lineString.points[i];
|
164
|
+
points.push(this.convertToPoint(coordinate));
|
165
|
+
}
|
166
|
+
|
167
|
+
return new OpenLayers.Geometry.LineString(points);
|
168
|
+
};
|
169
|
+
|
170
|
+
jsts.io.OpenLayersParser.prototype.convertToLinearRing = function(linearRing) {
|
171
|
+
var i;
|
172
|
+
var points = [];
|
173
|
+
|
174
|
+
for (i = 0; i < linearRing.points.length; i++) {
|
175
|
+
var coordinate = linearRing.points[i];
|
176
|
+
points.push(this.convertToPoint(coordinate));
|
177
|
+
}
|
178
|
+
|
179
|
+
return new OpenLayers.Geometry.LinearRing(points);
|
180
|
+
};
|
181
|
+
|
182
|
+
jsts.io.OpenLayersParser.prototype.convertToPolygon = function(polygon) {
|
183
|
+
var i;
|
184
|
+
var rings = [];
|
185
|
+
|
186
|
+
rings.push(this.convertToLinearRing(polygon.shell));
|
187
|
+
|
188
|
+
for (i = 0; i < polygon.holes.length; i++) {
|
189
|
+
var ring = polygon.holes[i];
|
190
|
+
rings.push(this.convertToLinearRing(ring));
|
191
|
+
}
|
192
|
+
|
193
|
+
return new OpenLayers.Geometry.Polygon(rings);
|
194
|
+
};
|
195
|
+
|
196
|
+
jsts.io.OpenLayersParser.prototype.convertToMultiPoint = function(multiPoint) {
|
197
|
+
var i;
|
198
|
+
var points = [];
|
199
|
+
|
200
|
+
for (i = 0; i < multiPoint.geometries.length; i++) {
|
201
|
+
var coordinate = multiPoint.geometries[i].coordinate;
|
202
|
+
points.push(new OpenLayers.Geometry.Point(coordinate.x, coordinate.y));
|
203
|
+
}
|
204
|
+
|
205
|
+
return new OpenLayers.Geometry.MultiPoint(points);
|
206
|
+
};
|
207
|
+
|
208
|
+
jsts.io.OpenLayersParser.prototype.convertToMultiLineString = function(
|
209
|
+
multiLineString) {
|
210
|
+
var i;
|
211
|
+
var lineStrings = [];
|
212
|
+
|
213
|
+
for (i = 0; i < multiLineString.geometries.length; i++) {
|
214
|
+
lineStrings.push(this.convertToLineString(multiLineString.geometries[i]));
|
215
|
+
}
|
216
|
+
|
217
|
+
return new OpenLayers.Geometry.MultiLineString(lineStrings);
|
218
|
+
};
|
219
|
+
|
220
|
+
jsts.io.OpenLayersParser.prototype.convertToMultiPolygon = function(
|
221
|
+
multiPolygon) {
|
222
|
+
var i;
|
223
|
+
var polygons = [];
|
224
|
+
|
225
|
+
for (i = 0; i < multiPolygon.geometries.length; i++) {
|
226
|
+
polygons.push(this.convertToPolygon(multiPolygon.geometries[i]));
|
227
|
+
}
|
228
|
+
|
229
|
+
return new OpenLayers.Geometry.MultiPolygon(polygons);
|
230
|
+
};
|
231
|
+
|
232
|
+
jsts.io.OpenLayersParser.prototype.convertToCollection = function(
|
233
|
+
geometryCollection) {
|
234
|
+
var i;
|
235
|
+
var geometries = [];
|
236
|
+
|
237
|
+
for (i = 0; i < geometryCollection.geometries.length; i++) {
|
238
|
+
var geometry = geometryCollection.geometries[i];
|
239
|
+
var geometryOpenLayers = this.write(geometry);
|
240
|
+
|
241
|
+
geometries.push(geometryOpenLayers);
|
242
|
+
}
|
243
|
+
|
244
|
+
return new OpenLayers.Geometry.Collection(geometries);
|
245
|
+
};
|
@@ -0,0 +1,421 @@
|
|
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
|
+
* This file incorporates work covered by the following copyright and
|
7
|
+
* permission notice:
|
8
|
+
*
|
9
|
+
* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
|
10
|
+
* full list of contributors). Published under the Clear BSD license.
|
11
|
+
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
|
12
|
+
* full text of the license.
|
13
|
+
*/
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Class for reading and writing Well-Known Text.
|
17
|
+
*
|
18
|
+
* NOTE: Adapted from OpenLayers 2.11 implementation.
|
19
|
+
*/
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Create a new parser for WKT
|
23
|
+
*
|
24
|
+
* @param {}
|
25
|
+
* geometryFactory
|
26
|
+
* @return An instance of WKTParser.
|
27
|
+
*/
|
28
|
+
jsts.io.WKTParser = function(geometryFactory) {
|
29
|
+
this.geometryFactory = geometryFactory || new jsts.geom.GeometryFactory();
|
30
|
+
|
31
|
+
this.regExes = {
|
32
|
+
'typeStr': /^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$/,
|
33
|
+
'emptyTypeStr': /^\s*(\w+)\s*EMPTY\s*$/,
|
34
|
+
'spaces': /\s+/,
|
35
|
+
'parenComma': /\)\s*,\s*\(/,
|
36
|
+
'doubleParenComma': /\)\s*\)\s*,\s*\(\s*\(/, // can't use {2} here
|
37
|
+
'trimParens': /^\s*\(?(.*?)\)?\s*$/
|
38
|
+
};
|
39
|
+
};
|
40
|
+
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Deserialize a WKT string and return a geometry. Supports WKT for POINT,
|
44
|
+
* MULTIPOINT, LINESTRING, LINEARRING, MULTILINESTRING, POLYGON, MULTIPOLYGON,
|
45
|
+
* and GEOMETRYCOLLECTION.
|
46
|
+
*
|
47
|
+
* @param {String}
|
48
|
+
* wkt A WKT string.
|
49
|
+
* @return {jsts.geom.Geometry} A geometry instance.
|
50
|
+
*/
|
51
|
+
jsts.io.WKTParser.prototype.read = function(wkt) {
|
52
|
+
var geometry, type, str;
|
53
|
+
wkt = wkt.replace(/[\n\r]/g, ' ');
|
54
|
+
var matches = this.regExes.typeStr.exec(wkt);
|
55
|
+
if (wkt.search('EMPTY') !== -1) {
|
56
|
+
matches = this.regExes.emptyTypeStr.exec(wkt);
|
57
|
+
matches[2] = undefined;
|
58
|
+
}
|
59
|
+
if (matches) {
|
60
|
+
type = matches[1].toLowerCase();
|
61
|
+
str = matches[2];
|
62
|
+
if (this.parse[type]) {
|
63
|
+
geometry = this.parse[type].apply(this, [str]);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
if (geometry === undefined)
|
68
|
+
throw new Error('Could not parse WKT ' + wkt);
|
69
|
+
|
70
|
+
return geometry;
|
71
|
+
};
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Serialize a geometry into a WKT string.
|
75
|
+
*
|
76
|
+
* @param {jsts.geom.Geometry}
|
77
|
+
* geometry A feature or array of features.
|
78
|
+
* @return {String} The WKT string representation of the input geometries.
|
79
|
+
*/
|
80
|
+
jsts.io.WKTParser.prototype.write = function(geometry) {
|
81
|
+
return this.extractGeometry(geometry);
|
82
|
+
};
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Entry point to construct the WKT for a single Geometry object.
|
86
|
+
*
|
87
|
+
* @param {jsts.geom.Geometry}
|
88
|
+
* geometry
|
89
|
+
*
|
90
|
+
* @return {String} A WKT string of representing the geometry.
|
91
|
+
*/
|
92
|
+
jsts.io.WKTParser.prototype.extractGeometry = function(geometry) {
|
93
|
+
var type = geometry.CLASS_NAME.split('.')[2].toLowerCase();
|
94
|
+
if (!this.extract[type]) {
|
95
|
+
return null;
|
96
|
+
}
|
97
|
+
var wktType = type.toUpperCase();
|
98
|
+
var data;
|
99
|
+
if (geometry.isEmpty()) {
|
100
|
+
data = wktType + ' EMPTY';
|
101
|
+
} else {
|
102
|
+
data = wktType + '(' + this.extract[type].apply(this, [geometry]) + ')';
|
103
|
+
}
|
104
|
+
return data;
|
105
|
+
};
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Object with properties corresponding to the geometry types. Property values
|
109
|
+
* are functions that do the actual data extraction.
|
110
|
+
*/
|
111
|
+
jsts.io.WKTParser.prototype.extract = {
|
112
|
+
'coordinate': function(coordinate) {
|
113
|
+
return coordinate.x + ' ' + coordinate.y;
|
114
|
+
},
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Return a space delimited string of point coordinates.
|
118
|
+
*
|
119
|
+
* @param {jsts.geom.Point}
|
120
|
+
* point
|
121
|
+
* @return {String} A string of coordinates representing the point.
|
122
|
+
*/
|
123
|
+
'point': function(point) {
|
124
|
+
return point.coordinate.x + ' ' + point.coordinate.y;
|
125
|
+
},
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Return a comma delimited string of point coordinates from a multipoint.
|
129
|
+
*
|
130
|
+
* @param {jsts.geom.MultiPoint>}
|
131
|
+
* multipoint
|
132
|
+
* @return {String} A string of point coordinate strings representing the
|
133
|
+
* multipoint.
|
134
|
+
*/
|
135
|
+
'multipoint': function(multipoint) {
|
136
|
+
var array = [];
|
137
|
+
for ( var i = 0, len = multipoint.geometries.length; i < len; ++i) {
|
138
|
+
array.push('(' +
|
139
|
+
this.extract.point.apply(this, [multipoint.geometries[i]]) + ')');
|
140
|
+
}
|
141
|
+
return array.join(',');
|
142
|
+
},
|
143
|
+
|
144
|
+
/**
|
145
|
+
* Return a comma delimited string of point coordinates from a line.
|
146
|
+
*
|
147
|
+
* @param {jsts.geom.LineString>}
|
148
|
+
* linestring
|
149
|
+
* @return {String} A string of point coordinate strings representing the
|
150
|
+
* linestring.
|
151
|
+
*/
|
152
|
+
'linestring': function(linestring) {
|
153
|
+
var array = [];
|
154
|
+
for ( var i = 0, len = linestring.points.length; i < len; ++i) {
|
155
|
+
array.push(this.extract.coordinate.apply(this, [linestring.points[i]]));
|
156
|
+
}
|
157
|
+
return array.join(',');
|
158
|
+
},
|
159
|
+
|
160
|
+
/**
|
161
|
+
* Return a comma delimited string of linestring strings from a
|
162
|
+
* multilinestring.
|
163
|
+
*
|
164
|
+
* @param {jsts.geom.MultiLineString>}
|
165
|
+
* multilinestring
|
166
|
+
* @return {String} A string of of linestring strings representing the
|
167
|
+
* multilinestring.
|
168
|
+
*/
|
169
|
+
'multilinestring': function(multilinestring) {
|
170
|
+
var array = [];
|
171
|
+
for ( var i = 0, len = multilinestring.geometries.length; i < len; ++i) {
|
172
|
+
array.push('(' +
|
173
|
+
this.extract.linestring.apply(this, [multilinestring.geometries[i]]) +
|
174
|
+
')');
|
175
|
+
}
|
176
|
+
return array.join(',');
|
177
|
+
},
|
178
|
+
|
179
|
+
/**
|
180
|
+
* Return a comma delimited string of linear ring arrays from a polygon.
|
181
|
+
*
|
182
|
+
* @param {jsts.geom.Polygon>}
|
183
|
+
* polygon
|
184
|
+
* @return {String} An array of linear ring arrays representing the polygon.
|
185
|
+
*/
|
186
|
+
'polygon': function(polygon) {
|
187
|
+
var array = [];
|
188
|
+
array.push('(' + this.extract.linestring.apply(this, [polygon.shell]) + ')');
|
189
|
+
for ( var i = 0, len = polygon.holes.length; i < len; ++i) {
|
190
|
+
array.push('(' + this.extract.linestring.apply(this, [polygon.holes[i]]) + ')');
|
191
|
+
}
|
192
|
+
return array.join(',');
|
193
|
+
},
|
194
|
+
|
195
|
+
/**
|
196
|
+
* Return an array of polygon arrays from a multipolygon.
|
197
|
+
*
|
198
|
+
* @param {jsts.geom.MultiPolygon>}
|
199
|
+
* multipolygon
|
200
|
+
* @return {String} An array of polygon arrays representing the multipolygon.
|
201
|
+
*/
|
202
|
+
'multipolygon': function(multipolygon) {
|
203
|
+
var array = [];
|
204
|
+
for ( var i = 0, len = multipolygon.geometries.length; i < len; ++i) {
|
205
|
+
array.push('(' + this.extract.polygon.apply(this, [multipolygon.geometries[i]]) + ')');
|
206
|
+
}
|
207
|
+
return array.join(',');
|
208
|
+
},
|
209
|
+
|
210
|
+
/**
|
211
|
+
* Return the WKT portion between 'GEOMETRYCOLLECTION(' and ')' for an
|
212
|
+
* geometrycollection.
|
213
|
+
*
|
214
|
+
* @param {jsts.geom.GeometryCollection>}
|
215
|
+
* collection
|
216
|
+
* @return {String} internal WKT representation of the collection.
|
217
|
+
*/
|
218
|
+
'geometrycollection': function(collection) {
|
219
|
+
var array = [];
|
220
|
+
for ( var i = 0, len = collection.geometries.length; i < len; ++i) {
|
221
|
+
array.push(this.extractGeometry.apply(this, [collection.geometries[i]]));
|
222
|
+
}
|
223
|
+
return array.join(',');
|
224
|
+
}
|
225
|
+
|
226
|
+
};
|
227
|
+
|
228
|
+
/**
|
229
|
+
* Object with properties corresponding to the geometry types. Property values
|
230
|
+
* are functions that do the actual parsing.
|
231
|
+
*/
|
232
|
+
jsts.io.WKTParser.prototype.parse = {
|
233
|
+
/**
|
234
|
+
* Return point geometry given a point WKT fragment.
|
235
|
+
*
|
236
|
+
* @param {String}
|
237
|
+
* str A WKT fragment representing the point.
|
238
|
+
* @return {jsts.geom.Point} A point geometry.
|
239
|
+
* @private
|
240
|
+
*/
|
241
|
+
'point': function(str) {
|
242
|
+
if (str === undefined) {
|
243
|
+
return this.geometryFactory.createPoint(null);
|
244
|
+
}
|
245
|
+
|
246
|
+
var coords = str.trim().split(this.regExes.spaces);
|
247
|
+
return this.geometryFactory.createPoint(new jsts.geom.Coordinate(coords[0],
|
248
|
+
coords[1]));
|
249
|
+
},
|
250
|
+
|
251
|
+
/**
|
252
|
+
* Return a multipoint geometry given a multipoint WKT fragment.
|
253
|
+
*
|
254
|
+
* @param {String}
|
255
|
+
* A WKT fragment representing the multipoint.
|
256
|
+
* @return {jsts.geom.Point} A multipoint feature.
|
257
|
+
* @private
|
258
|
+
*/
|
259
|
+
'multipoint': function(str) {
|
260
|
+
if (str === undefined) {
|
261
|
+
return this.geometryFactory.createMultiPoint(null);
|
262
|
+
}
|
263
|
+
|
264
|
+
var point;
|
265
|
+
var points = str.trim().split(',');
|
266
|
+
var components = [];
|
267
|
+
for ( var i = 0, len = points.length; i < len; ++i) {
|
268
|
+
point = points[i].replace(this.regExes.trimParens, '$1');
|
269
|
+
components.push(this.parse.point.apply(this, [point]));
|
270
|
+
}
|
271
|
+
return this.geometryFactory.createMultiPoint(components);
|
272
|
+
},
|
273
|
+
|
274
|
+
/**
|
275
|
+
* Return a linestring geometry given a linestring WKT fragment.
|
276
|
+
*
|
277
|
+
* @param {String}
|
278
|
+
* A WKT fragment representing the linestring.
|
279
|
+
* @return {jsts.geom.LineString} A linestring geometry.
|
280
|
+
* @private
|
281
|
+
*/
|
282
|
+
'linestring': function(str) {
|
283
|
+
if (str === undefined) {
|
284
|
+
return this.geometryFactory.createLineString(null);
|
285
|
+
}
|
286
|
+
|
287
|
+
var points = str.trim().split(',');
|
288
|
+
var components = [];
|
289
|
+
var coords;
|
290
|
+
for ( var i = 0, len = points.length; i < len; ++i) {
|
291
|
+
coords = points[i].trim().split(this.regExes.spaces);
|
292
|
+
components.push(new jsts.geom.Coordinate(coords[0], coords[1]));
|
293
|
+
}
|
294
|
+
return this.geometryFactory.createLineString(components);
|
295
|
+
},
|
296
|
+
|
297
|
+
/**
|
298
|
+
* Return a linearring geometry given a linearring WKT fragment.
|
299
|
+
*
|
300
|
+
* @param {String}
|
301
|
+
* A WKT fragment representing the linearring.
|
302
|
+
* @return {jsts.geom.LinearRing} A linearring geometry.
|
303
|
+
* @private
|
304
|
+
*/
|
305
|
+
'linearring': function(str) {
|
306
|
+
if (str === undefined) {
|
307
|
+
return this.geometryFactory.createLinearRing(null);
|
308
|
+
}
|
309
|
+
|
310
|
+
var points = str.trim().split(',');
|
311
|
+
var components = [];
|
312
|
+
var coords;
|
313
|
+
for ( var i = 0, len = points.length; i < len; ++i) {
|
314
|
+
coords = points[i].trim().split(this.regExes.spaces);
|
315
|
+
components.push(new jsts.geom.Coordinate(coords[0], coords[1]));
|
316
|
+
}
|
317
|
+
return this.geometryFactory.createLinearRing(components);
|
318
|
+
},
|
319
|
+
|
320
|
+
/**
|
321
|
+
* Return a multilinestring geometry given a multilinestring WKT fragment.
|
322
|
+
*
|
323
|
+
* @param {String}
|
324
|
+
* A WKT fragment representing the multilinestring.
|
325
|
+
* @return {jsts.geom.MultiLineString} A multilinestring geometry.
|
326
|
+
* @private
|
327
|
+
*/
|
328
|
+
'multilinestring': function(str) {
|
329
|
+
if (str === undefined) {
|
330
|
+
return this.geometryFactory.createMultiLineString(null);
|
331
|
+
}
|
332
|
+
|
333
|
+
var line;
|
334
|
+
var lines = str.trim().split(this.regExes.parenComma);
|
335
|
+
var components = [];
|
336
|
+
for ( var i = 0, len = lines.length; i < len; ++i) {
|
337
|
+
line = lines[i].replace(this.regExes.trimParens, '$1');
|
338
|
+
components.push(this.parse.linestring.apply(this, [line]));
|
339
|
+
}
|
340
|
+
return this.geometryFactory.createMultiLineString(components);
|
341
|
+
},
|
342
|
+
|
343
|
+
/**
|
344
|
+
* Return a polygon geometry given a polygon WKT fragment.
|
345
|
+
*
|
346
|
+
* @param {String}
|
347
|
+
* A WKT fragment representing the polygon.
|
348
|
+
* @return {jsts.geom.Polygon} A polygon geometry.
|
349
|
+
* @private
|
350
|
+
*/
|
351
|
+
'polygon': function(str) {
|
352
|
+
if (str === undefined) {
|
353
|
+
return this.geometryFactory.createPolygon(null);
|
354
|
+
}
|
355
|
+
|
356
|
+
var ring, linestring, linearring;
|
357
|
+
var rings = str.trim().split(this.regExes.parenComma);
|
358
|
+
var shell;
|
359
|
+
var holes = [];
|
360
|
+
for ( var i = 0, len = rings.length; i < len; ++i) {
|
361
|
+
ring = rings[i].replace(this.regExes.trimParens, '$1');
|
362
|
+
linestring = this.parse.linestring.apply(this, [ring]);
|
363
|
+
linearring = this.geometryFactory.createLinearRing(linestring.points);
|
364
|
+
if (i === 0) {
|
365
|
+
shell = linearring;
|
366
|
+
} else {
|
367
|
+
holes.push(linearring);
|
368
|
+
}
|
369
|
+
|
370
|
+
}
|
371
|
+
return this.geometryFactory.createPolygon(shell, holes);
|
372
|
+
},
|
373
|
+
|
374
|
+
/**
|
375
|
+
* Return a multipolygon geometry given a multipolygon WKT fragment.
|
376
|
+
*
|
377
|
+
* @param {String}
|
378
|
+
* A WKT fragment representing the multipolygon.
|
379
|
+
* @return {jsts.geom.MultiPolygon} A multipolygon geometry.
|
380
|
+
* @private
|
381
|
+
*/
|
382
|
+
'multipolygon': function(str) {
|
383
|
+
if (str === undefined) {
|
384
|
+
return this.geometryFactory.createMultiPolygon(null);
|
385
|
+
}
|
386
|
+
|
387
|
+
var polygon;
|
388
|
+
var polygons = str.trim().split(this.regExes.doubleParenComma);
|
389
|
+
var components = [];
|
390
|
+
for ( var i = 0, len = polygons.length; i < len; ++i) {
|
391
|
+
polygon = polygons[i].replace(this.regExes.trimParens, '$1');
|
392
|
+
components.push(this.parse.polygon.apply(this, [polygon]));
|
393
|
+
}
|
394
|
+
return this.geometryFactory.createMultiPolygon(components);
|
395
|
+
},
|
396
|
+
|
397
|
+
/**
|
398
|
+
* Return a geometrycollection given a geometrycollection WKT fragment.
|
399
|
+
*
|
400
|
+
* @param {String}
|
401
|
+
* A WKT fragment representing the geometrycollection.
|
402
|
+
* @return {jsts.geom.GeometryCollection}
|
403
|
+
* @private
|
404
|
+
*/
|
405
|
+
'geometrycollection': function(str) {
|
406
|
+
if (str === undefined) {
|
407
|
+
return this.geometryFactory.createGeometryCollection(null);
|
408
|
+
}
|
409
|
+
|
410
|
+
// separate components of the collection with |
|
411
|
+
str = str.replace(/,\s*([A-Za-z])/g, '|$1');
|
412
|
+
var wktArray = str.trim().split('|');
|
413
|
+
var components = [];
|
414
|
+
for ( var i = 0, len = wktArray.length; i < len; ++i) {
|
415
|
+
components.push(jsts.io.WKTParser.prototype.read.apply(this,
|
416
|
+
[wktArray[i]]));
|
417
|
+
}
|
418
|
+
return this.geometryFactory.createGeometryCollection(components);
|
419
|
+
}
|
420
|
+
|
421
|
+
};
|