use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class SimpleRecordConveter method convert.
@Override
public Record convert(final Record sourceObject) {
final Record targetObject = this.factory.newRecord(this.recordDefinition);
final Geometry sourceGeometry = sourceObject.getGeometry();
final GeometryFactory geometryFactory = sourceGeometry.getGeometryFactory();
final Geometry targetGeometry = geometryFactory.geometry(sourceGeometry);
targetObject.setGeometryValue(targetGeometry);
for (final SourceToTargetProcess<Record, Record> processor : this.processors) {
processor.process(sourceObject, targetObject);
}
return targetObject;
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class CascadedPolygonUnion method restrictToPolygons.
/**
* Computes a {@link Polygonal} containing only {@link Polygonal} components.
* Extracts the {@link Polygon}s from the input
* and returns them as an appropriate {@link Polygonal} geometry.
* <p>
* If the input is already <tt>Polygonal</tt>, it is returned unchanged.
* <p>
* A particular use case is to filter out non-polygonal components
* returned from an overlay operation.
*
* @param geometry the geometry to filter
* @return a Polygonal geometry
*/
private static Polygonal restrictToPolygons(final Geometry geometry) {
if (geometry instanceof Polygonal) {
return (Polygonal) geometry;
} else {
final List<Polygon> polygons = geometry.getGeometries(Polygon.class);
if (polygons.size() == 1) {
return polygons.get(0);
}
final GeometryFactory geometryFactory = geometry.getGeometryFactory();
return geometryFactory.polygonal(polygons);
}
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class UnaryUnionOp method union.
public static Geometry union(final Punctual punctual, final Geometry otherGeom) {
final PointLocator locater = new PointLocator();
Set<Geometry> exteriorGeometries = null;
for (final Point point : punctual.points()) {
final Location loc = locater.locate(otherGeom, point);
if (loc == Location.EXTERIOR) {
if (exteriorGeometries == null) {
exteriorGeometries = new TreeSet<>();
}
exteriorGeometries.add(point);
}
}
if (exteriorGeometries == null) {
return otherGeom;
} else {
for (final Geometry geometry : otherGeom.geometries()) {
exteriorGeometries.add(geometry);
}
final GeometryFactory geomFactory = otherGeom.getGeometryFactory();
return geomFactory.geometry(exteriorGeometries);
}
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class MinimumClearance method compute.
private void compute() {
if (!this.calculated) {
this.calculated = true;
this.minClearance = Double.MAX_VALUE;
if (!this.geometry.isEmpty()) {
final StrTree<FacetSequence> geomTree = FacetSequenceTreeBuilder.build(this.geometry);
final Pair<FacetSequence, FacetSequence> nearest = geomTree.nearestNeighbour(new MinClearanceDistance(this.calculateLine));
final MinClearanceDistance mcd = new MinClearanceDistance(this.calculateLine);
this.minClearance = mcd.distance(nearest.getValue1(), nearest.getValue2());
final GeometryFactory geometryFactory = this.geometry.getGeometryFactory();
if (this.calculateLine) {
this.minClearancePts = new Point[] { //
geometryFactory.point(mcd.getMinX1(), mcd.getMinY1()), geometryFactory.point(mcd.getMinX2(), mcd.getMinY2()) };
}
}
}
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class LineStringUtil method isPointOnLine.
/**
* Check to see if the point is on any of the segments of the line.
*
* @param line The line.
* @param point The point.
* @return True if the point is on the line, false otherwise.
* @see LineSegmentUtil#isPointOnLine(GeometryFactory, Coordinates,
* Coordinates, Point)
*/
public static boolean isPointOnLine(final LineString line, final Point point) {
final GeometryFactory factory = line.getGeometryFactory();
final double x = point.getX();
final double y = point.getY();
final int vertexCount = line.getVertexCount();
if (vertexCount > 0) {
double x1 = line.getX(0);
double y1 = line.getY(0);
if (x == x1 && y == y1) {
return true;
}
for (int vertexIndex = 1; vertexIndex < vertexCount; vertexIndex++) {
final double x2 = line.getX(vertexIndex);
final double y2 = line.getY(vertexIndex);
if (x == x2 && y == y2) {
return true;
} else {
if (LineSegmentUtil.isPointOnLine(factory, x1, y1, x2, y2, x, y)) {
return true;
}
}
x1 = x2;
y1 = y2;
}
}
return false;
}
Aggregations