-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GeometryPrecisionReducer to allow keeping collapsed components (#738
) Signed-off-by: Martin Davis <[email protected]>
- Loading branch information
Showing
4 changed files
with
138 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...re/src/main/java/org/locationtech/jts/precision/PointwisePrecisionReducerTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2021 Martin Davis. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* and Eclipse Distribution License v. 1.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*/ | ||
package org.locationtech.jts.precision; | ||
|
||
import org.locationtech.jts.geom.Coordinate; | ||
import org.locationtech.jts.geom.CoordinateSequence; | ||
import org.locationtech.jts.geom.Geometry; | ||
import org.locationtech.jts.geom.LineString; | ||
import org.locationtech.jts.geom.LinearRing; | ||
import org.locationtech.jts.geom.PrecisionModel; | ||
import org.locationtech.jts.geom.util.GeometryTransformer; | ||
|
||
/** | ||
* A transformer to reduce the precision of a geometry pointwise. | ||
* | ||
* @author mdavis | ||
* | ||
*/ | ||
class PointwisePrecisionReducerTransformer extends GeometryTransformer { | ||
|
||
public static Geometry reduce(Geometry geom, PrecisionModel targetPM) { | ||
PointwisePrecisionReducerTransformer trans = new PointwisePrecisionReducerTransformer(targetPM); | ||
return trans.transform(geom); | ||
} | ||
|
||
private PrecisionModel targetPM; | ||
|
||
PointwisePrecisionReducerTransformer(PrecisionModel targetPM) { | ||
this.targetPM = targetPM; | ||
} | ||
|
||
protected CoordinateSequence transformCoordinates( | ||
CoordinateSequence coordinates, Geometry parent) { | ||
if (coordinates.size() == 0) | ||
return null; | ||
|
||
Coordinate[] coordsReduce = reducePointwise(coordinates); | ||
return factory.getCoordinateSequenceFactory().create(coordsReduce); | ||
} | ||
|
||
private Coordinate[] reducePointwise(CoordinateSequence coordinates) { | ||
Coordinate[] coordReduce = new Coordinate[coordinates.size()]; | ||
// copy coordinates and reduce | ||
for (int i = 0; i < coordinates.size(); i++) { | ||
Coordinate coord = coordinates.getCoordinate(i).copy(); | ||
targetPM.makePrecise(coord); | ||
coordReduce[i]= coord; | ||
} | ||
return coordReduce; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters