use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class SnapTransformer method snapToSelf.
/**
* Snaps the vertices in the component {@link LineString}s
* of the source geometry
* to the vertices of the same geometry.
* Allows optionally cleaning the result to ensure it is
* topologically valid
* (which fixes issues such as topology collapses in polygonal inputs).
*
*@param snapTolerance the snapping tolerance
*@param cleanResult whether the result should be made valid
* @return a new snapped Geometry
*/
public Geometry snapToSelf(final double snapTolerance, final boolean cleanResult) {
final Collection<Point> snapPoints = extractTargetCoordinates(this.srcGeom);
if (snapPoints.isEmpty()) {
return this.srcGeom;
} else {
final SnapTransformer snapTrans = new SnapTransformer(snapTolerance, snapPoints, true);
final Geometry snappedGeom = snapTrans.transform(this.srcGeom);
Geometry result = snappedGeom;
if (cleanResult && result instanceof Polygonal) {
// TODO: use better cleaning approach
result = snappedGeom.buffer(0);
}
return result;
}
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class SnapTransformer method snapSegments.
/**
* Snap segments of the source to nearby snap vertices.
* Source segments are "cracked" at a snap vertex.
* A single input segment may be snapped several times
* to different snap vertices.
* <p>
* For each distinct snap vertex, at most one source segment
* is snapped to. This prevents "cracking" multiple segments
* at the same point, which would likely cause
* topology collapse when being used on polygonal linework.
*
* @param newCoordinates the coordinates of the source linestring to be snapped
* @param snapPoints the target snap vertices
*/
private LineString snapSegments(LineString line) {
LineStringEditor newLine = null;
for (final Point snapPoint : this.snapPoints) {
final int index = findSegmentIndexToSnap(snapPoint, line);
/**
* If a segment to snap to was found, "crack" it at the snap pt.
* The new pt is inserted immediately into the src segment list,
* so that subsequent snapping will take place on the modified segments.
* Duplicate points are not added.
*/
if (index >= 0) {
if (newLine == null) {
if (line instanceof LineStringEditor) {
newLine = (LineStringEditor) line;
} else {
newLine = LineStringEditor.newLineStringEditor(line);
line = newLine;
}
}
newLine.insertVertex(index + 1, snapPoint, false);
}
}
if (newLine == null) {
return line;
} else {
return newLine;
}
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class SnapTransformer method transformPoint.
@Override
protected Point transformPoint(final Point point) {
final double x = point.getX();
final double y = point.getY();
final Point snapVert = findSnapForVertex(x, y);
if (snapVert == null) {
return point;
} else {
return snapVert;
}
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class FuzzyPointLocator method isWithinToleranceOfBoundary.
private boolean isWithinToleranceOfBoundary(final Point pt) {
final double x = pt.getX();
final double y = pt.getY();
for (int i = 0; i < this.linework.getGeometryCount(); i++) {
final LineString line = (LineString) this.linework.getGeometry(i);
for (int j = 0; j < line.getVertexCount() - 1; j++) {
final double x1 = line.getX(j);
final double y1 = line.getY(j + 1);
final double x2 = line.getX(j);
final double y2 = line.getY(j + 1);
final double dist = LineSegmentUtil.distanceLinePoint(x1, y1, x2, y2, x, y);
if (dist <= this.boundaryDistanceTolerance) {
return true;
}
}
}
return false;
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class DistanceWithLocation method computePointLine.
private boolean computePointLine(final Point point, final LineString line) {
final BoundingBox boundingBox = line.getBoundingBox();
if (this.minDistance == Double.MAX_VALUE || boundingBox.distance(point) <= this.minDistance) {
for (final Segment segment : line.segments()) {
final double distance = segment.distancePoint(point);
if (distance < this.minDistance) {
this.minDistance = distance;
final Point closestPoint = segment.closestPoint(point);
final int segmentIndex = segment.getSegmentIndex();
this.minDistanceLocation1 = new GeometryLocation(point, 0, point);
this.minDistanceLocation2 = new GeometryLocation(line, segmentIndex, closestPoint);
if (this.minDistance <= this.terminateDistance) {
return true;
}
}
}
}
return false;
}
Aggregations