Skip to content

Commit

Permalink
Fixed DouglasPeuckerSimplifier and expose most public classes in sing…
Browse files Browse the repository at this point in the history
…le file builds
  • Loading branch information
bjornharrtell committed Feb 10, 2016
1 parent b1ba282 commit 7a84dd8
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 3 deletions.
67 changes: 67 additions & 0 deletions src/jsts.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import Coordinate from './org/locationtech/jts/geom/Coordinate'
import GeometryFactory from './org/locationtech/jts/geom/GeometryFactory'
import Geometry from './org/locationtech/jts/geom/Geometry'
Expand All @@ -8,18 +9,46 @@ import GeometryCollection from './org/locationtech/jts/geom/GeometryCollection'
import MultiPoint from './org/locationtech/jts/geom/MultiPoint'
import MultiLineString from './org/locationtech/jts/geom/MultiLineString'
import MultiPolygon from './org/locationtech/jts/geom/MultiPolygon'

import Densifier from './org/locationtech/jts/densify/Densifier'
import LineDissolver from './org/locationtech/jts/dissolve/LineDissolver'

import GeoJSONReader from './org/locationtech/jts/io/GeoJSONReader'
import GeoJSONWriter from './org/locationtech/jts/io/GeoJSONWriter'
import WKTReader from './org/locationtech/jts/io/WKTReader'
import WKTWriter from './org/locationtech/jts/io/WKTWriter'
import olParser from './org/locationtech/jts/io/olParser'

import BoundaryOp from './org/locationtech/jts/operation/BoundaryOp'
import IsSimpleOp from './org/locationtech/jts/operation/IsSimpleOp'
import BufferOp from './org/locationtech/jts/operation/buffer/BufferOp'
import DistanceOp from './org/locationtech/jts/operation/distance/DistanceOp'
import LineMerger from './org/locationtech/jts/operation/linemerge/LineMerger'
import OverlayOp from './org/locationtech/jts/operation/overlay/OverlayOp'
import Polygonizer from './org/locationtech/jts/operation/polygonize/Polygonizer'
import RelateOp from './org/locationtech/jts/operation/relate/RelateOp'
import CascadedPolygonUnion from './org/locationtech/jts/operation/union/CascadedPolygonUnion'
import UnaryUnionOp from './org/locationtech/jts/operation/union/UnaryUnionOp'
import IsValidOp from './org/locationtech/jts/operation/valid/IsValidOp'

// import GeometryPrecisionReducer from './org/locationtech/jts/precision/GeometryPrecisionReducer'

import DouglasPeuckerSimplifier from './org/locationtech/jts/simplify/DouglasPeuckerSimplifier'
import TopologyPreservingSimplifier from './org/locationtech/jts/simplify/TopologyPreservingSimplifier'

import patch from './org/locationtech/jts/monkey'

(function () {
patch()
})()

export default {
densify: {
Densifier
},
dissolve: {
LineDissolver
},
geom: {
Coordinate,
GeometryFactory,
Expand All @@ -38,5 +67,43 @@ export default {
WKTReader,
WKTWriter,
olParser
},
operation: {
BoundaryOp,
IsSimpleOp,
buffer: {
BufferOp
},
distance: {
DistanceOp
},
linemerge: {
LineMerger
},
overlay: {
OverlayOp
},
polygonize: {
Polygonizer
},
relate: {
RelateOp
},
union: {
CascadedPolygonUnion,
UnaryUnionOp
},
valid: {
IsValidOp
}
},
/*
precision: {
GeometryPrecisionReducer
},
*/
simplify: {
DouglasPeuckerSimplifier,
TopologyPreservingSimplifier
}
}
69 changes: 68 additions & 1 deletion src/org/locationtech/jts/simplify/DouglasPeuckerSimplifier.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import DouglasPeuckerLineSimplifier from './DouglasPeuckerLineSimplifier';
import GeometryTransformer from '../geom/util/GeometryTransformer';
import IllegalArgumentException from '../../../../java/lang/IllegalArgumentException';
import Polygon from '../geom/Polygon';
import LinearRing from '../geom/LinearRing';
import MultiPolygon from '../geom/MultiPolygon';
export default class DouglasPeuckerSimplifier {
constructor(...args) {
(() => {
Expand All @@ -20,6 +25,9 @@ export default class DouglasPeuckerSimplifier {
get interfaces_() {
return [];
}
static get DPTransformer() {
return DPTransformer;
}
static simplify(geom, distanceTolerance) {
var tss = new DouglasPeuckerSimplifier(geom);
tss.setDistanceTolerance(distanceTolerance);
Expand All @@ -30,7 +38,7 @@ export default class DouglasPeuckerSimplifier {
}
getResultGeometry() {
if (this.inputGeom.isEmpty()) return this.inputGeom.copy();
return new DPTransformer(this.isEnsureValidTopology).transform(this.inputGeom);
return new DPTransformer(this.isEnsureValidTopology, this.distanceTolerance).transform(this.inputGeom);
}
setDistanceTolerance(distanceTolerance) {
if (distanceTolerance < 0.0) throw new IllegalArgumentException("Tolerance must be non-negative");
Expand All @@ -40,4 +48,63 @@ export default class DouglasPeuckerSimplifier {
return DouglasPeuckerSimplifier;
}
}
class DPTransformer extends GeometryTransformer {
constructor(...args) {
super();
(() => {
this.isEnsureValidTopology = true;
this.distanceTolerance = null;
})();
const overloads = (...args) => {
switch (args.length) {
case 2:
return ((...args) => {
let [isEnsureValidTopology, distanceTolerance] = args;
this.isEnsureValidTopology = isEnsureValidTopology;
this.distanceTolerance = distanceTolerance;
})(...args);
}
};
return overloads.apply(this, args);
}
get interfaces_() {
return [];
}
transformPolygon(geom, parent) {
if (geom.isEmpty()) return null;
var rawGeom = super.transformPolygon(geom, parent);
if (parent instanceof MultiPolygon) {
return rawGeom;
}
return this.createValidArea(rawGeom);
}
createValidArea(rawAreaGeom) {
if (this.isEnsureValidTopology) return rawAreaGeom.buffer(0.0);
return rawAreaGeom;
}
transformCoordinates(coords, parent) {
var inputPts = coords.toCoordinateArray();
var newPts = null;
if (inputPts.length === 0) {
newPts = new Array(0);
} else {
newPts = DouglasPeuckerLineSimplifier.simplify(inputPts, this.distanceTolerance);
}
return this.factory.getCoordinateSequenceFactory().create(newPts);
}
transformMultiPolygon(geom, parent) {
var rawGeom = super.transformMultiPolygon(geom, parent);
return this.createValidArea(rawGeom);
}
transformLinearRing(geom, parent) {
var removeDegenerateRings = parent instanceof Polygon;
var simpResult = super.transformLinearRing(geom, parent);
if (removeDegenerateRings && !(simpResult instanceof LinearRing)) return null;
;
return simpResult;
}
getClass() {
return DPTransformer;
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import LineString from '../geom/LineString';
import HashMap from '../../../../java/util/HashMap';
import GeometryTransformer from '../geom/util/GeometryTransformer';
import TaggedLinesSimplifier from './TaggedLinesSimplifier';
import IllegalArgumentException from '../../../../java/lang/IllegalArgumentException';
import GeometryComponentFilter from '../geom/GeometryComponentFilter';
Expand All @@ -25,6 +26,9 @@ export default class TopologyPreservingSimplifier {
get interfaces_() {
return [];
}
static get LineStringTransformer() {
return LineStringTransformer;
}
static get LineStringMapBuilderFilter() {
return LineStringMapBuilderFilter;
}
Expand All @@ -38,7 +42,7 @@ export default class TopologyPreservingSimplifier {
this.linestringMap = new HashMap();
this.inputGeom.apply(new LineStringMapBuilderFilter(this));
this.lineSimplifier.simplify(this.linestringMap.values());
var result = new LineStringTransformer().transform(this.inputGeom);
var result = new LineStringTransformer(this.linestringMap).transform(this.inputGeom);
return result;
}
setDistanceTolerance(distanceTolerance) {
Expand All @@ -49,6 +53,38 @@ export default class TopologyPreservingSimplifier {
return TopologyPreservingSimplifier;
}
}
class LineStringTransformer extends GeometryTransformer {
constructor(...args) {
super();
(() => {
this.linestringMap = null;
})();
const overloads = (...args) => {
switch (args.length) {
case 1:
return ((...args) => {
let [linestringMap] = args;
this.linestringMap = linestringMap;
})(...args);
}
};
return overloads.apply(this, args);
}
get interfaces_() {
return [];
}
transformCoordinates(coords, parent) {
if (coords.size() === 0) return null;
if (parent instanceof LineString) {
var taggedLine = this.linestringMap.get(parent);
return this.createCoordinateSequence(taggedLine.getResultCoordinates());
}
return super.transformCoordinates(coords, parent);
}
getClass() {
return LineStringTransformer;
}
}
class LineStringMapBuilderFilter {
constructor(...args) {
(() => {
Expand Down
69 changes: 68 additions & 1 deletion src/org/locationtech/jts/simplify/VWSimplifier.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import GeometryTransformer from '../geom/util/GeometryTransformer';
import VWLineSimplifier from './VWLineSimplifier';
import IllegalArgumentException from '../../../../java/lang/IllegalArgumentException';
import Polygon from '../geom/Polygon';
import LinearRing from '../geom/LinearRing';
import MultiPolygon from '../geom/MultiPolygon';
export default class VWSimplifier {
constructor(...args) {
(() => {
Expand All @@ -20,6 +25,9 @@ export default class VWSimplifier {
get interfaces_() {
return [];
}
static get VWTransformer() {
return VWTransformer;
}
static simplify(geom, distanceTolerance) {
var simp = new VWSimplifier(geom);
simp.setDistanceTolerance(distanceTolerance);
Expand All @@ -30,7 +38,7 @@ export default class VWSimplifier {
}
getResultGeometry() {
if (this.inputGeom.isEmpty()) return this.inputGeom.copy();
return new VWTransformer(this.isEnsureValidTopology).transform(this.inputGeom);
return new VWTransformer(this.isEnsureValidTopology, this.distanceTolerance).transform(this.inputGeom);
}
setDistanceTolerance(distanceTolerance) {
if (distanceTolerance < 0.0) throw new IllegalArgumentException("Tolerance must be non-negative");
Expand All @@ -40,4 +48,63 @@ export default class VWSimplifier {
return VWSimplifier;
}
}
class VWTransformer extends GeometryTransformer {
constructor(...args) {
super();
(() => {
this.isEnsureValidTopology = true;
this.distanceTolerance = null;
})();
const overloads = (...args) => {
switch (args.length) {
case 2:
return ((...args) => {
let [isEnsureValidTopology, distanceTolerance] = args;
this.isEnsureValidTopology = isEnsureValidTopology;
this.distanceTolerance = distanceTolerance;
})(...args);
}
};
return overloads.apply(this, args);
}
get interfaces_() {
return [];
}
transformPolygon(geom, parent) {
if (geom.isEmpty()) return null;
var rawGeom = super.transformPolygon(geom, parent);
if (parent instanceof MultiPolygon) {
return rawGeom;
}
return this.createValidArea(rawGeom);
}
createValidArea(rawAreaGeom) {
if (this.isEnsureValidTopology) return rawAreaGeom.buffer(0.0);
return rawAreaGeom;
}
transformCoordinates(coords, parent) {
var inputPts = coords.toCoordinateArray();
var newPts = null;
if (inputPts.length === 0) {
newPts = new Array(0);
} else {
newPts = VWLineSimplifier.simplify(inputPts, this.distanceTolerance);
}
return this.factory.getCoordinateSequenceFactory().create(newPts);
}
transformMultiPolygon(geom, parent) {
var rawGeom = super.transformMultiPolygon(geom, parent);
return this.createValidArea(rawGeom);
}
transformLinearRing(geom, parent) {
var removeDegenerateRings = parent instanceof Polygon;
var simpResult = super.transformLinearRing(geom, parent);
if (removeDegenerateRings && !(simpResult instanceof LinearRing)) return null;
;
return simpResult;
}
getClass() {
return VWTransformer;
}
}

0 comments on commit 7a84dd8

Please sign in to comment.