Skip to content

Commit ed38579

Browse files
committed
Merge pull request #49 from jericks/geom_densify
Add a Geometry.densify(tolerance) method
2 parents ffcaff3 + 75b1f1a commit ed38579

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

doc/api/geom/geometry.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ Common Geometry Methods
141141

142142
Tests if this geometry crosses the other geometry.
143143

144+
.. function:: Geometry.densify
145+
146+
:arg tolerance: ``Number`` The distance tolerance for the densification.
147+
All line segments in the densified geometry will be no longer than the distance tolereance.
148+
The tolerance value must be non-negative.
149+
:returns: :class:`geom.Geometry`
150+
151+
Densifies a geometry object adding vertices along the line segments of the
152+
geometry.
153+
144154
.. function:: Geometry.difference
145155

146156
:arg other: :class:`geom.Geometry`

src/main/java/org/geoscript/js/geom/Geometry.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Arrays;
66
import java.util.List;
77

8+
import com.vividsolutions.jts.densify.Densifier;
89
import org.geoscript.js.GeoObject;
910
import org.geoscript.js.proj.Projection;
1011
import org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer;
@@ -291,7 +292,15 @@ public ScriptableObject simplify(double tolerance) {
291292
((Geometry) simplified).projection = projection;
292293
return simplified;
293294
}
294-
295+
296+
@JSFunction
297+
public ScriptableObject densify(double tolerance) {
298+
com.vividsolutions.jts.geom.Geometry geom = Densifier.densify(geometry, tolerance);
299+
ScriptableObject densified = GeometryWrapper.wrap(getParentScope(), geom);
300+
((Geometry) densified).projection = projection;
301+
return densified;
302+
}
303+
295304
@JSFunction
296305
public String getGeometryType() {
297306
return geometry.getGeometryType();

src/test/resources/org/geoscript/js/tests/geoscript/geom/test_multilinestring.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ exports["test: simplify"] = function() {
4747

4848
};
4949

50+
exports["test: densify"] = function() {
51+
52+
var g = new GEOM.MultiLineString([[[1, 1], [2, 2], [3, 1], [4, 2]], [[-1, -1], [-2, -2], [-3, -1], [-4, -2]]]);
53+
g.projection = "epsg:4326";
54+
var g2 = g.densify(0.5);
55+
56+
ASSERT.ok(g2 instanceof GEOM.MultiLineString, "correct type");
57+
ASSERT.ok(g2.coordinates[0].length > g.coordinates[0].length, "densified line has more coordinates");
58+
ASSERT.ok(g.projection.equals(g.projection), "same projection");
59+
};
60+
5061

5162
exports["test: bounds"] = function() {
5263

0 commit comments

Comments
 (0)