use of com.revolsys.geometry.model.Punctual in project com.revolsys.open by revolsys.
the class MultiPointEditorTest method testSetZ.
@Test
public void testSetZ() {
final PunctualEditor editor = PUNCTUAL.newGeometryEditor(3);
editor.setZ(0, 10);
final Punctual newMultiPoint = editor.newGeometry();
Assert.assertNotSame(PUNCTUAL, newMultiPoint);
Assert.assertEquals(10.0, newMultiPoint.getZ(0), 0.0);
}
use of com.revolsys.geometry.model.Punctual in project com.revolsys.open by revolsys.
the class MultiPointEditorTest method testSetY.
@Test
public void testSetY() {
final PunctualEditor editor = PUNCTUAL.newGeometryEditor(3);
editor.setY(0, 10);
final Punctual newMultiPoint = editor.newGeometry();
Assert.assertNotSame(PUNCTUAL, newMultiPoint);
Assert.assertEquals(10.0, newMultiPoint.getY(0), 0.0);
}
use of com.revolsys.geometry.model.Punctual in project com.revolsys.open by revolsys.
the class GeometryFactoryTest method testCreateGeometry.
private static void testCreateGeometry() {
final LineString pointPoints = new LineStringDouble(2, 0.0, 0);
final LineString point2Points = new LineStringDouble(2, 20.0, 20);
final LineString ringPoints = new LineStringDouble(2, 0.0, 0, 0, 100, 100, 100, 100, 0, 0, 0);
final LineString ring2Points = new LineStringDouble(2, 20.0, 20, 20, 80, 80, 80, 80, 20, 20, 20);
final LineString ring3Points = new LineStringDouble(2, 120.0, 120, 120, 180, 180, 180, 180, 120, 120, 120);
final Point point = GEOMETRY_FACTORY.point(2, 0.0, 0);
assertCopyGeometry(point, pointPoints);
final LineString line = GEOMETRY_FACTORY.lineString(ringPoints);
assertCopyGeometry(line, ringPoints);
final LinearRing linearRing = GEOMETRY_FACTORY.linearRing(ringPoints);
assertCopyGeometry(linearRing, ringPoints);
final Polygon polygon = GEOMETRY_FACTORY.polygon(ringPoints);
assertCopyGeometry(polygon, ringPoints);
final Polygon polygon2 = GEOMETRY_FACTORY.polygon(ringPoints, ring2Points);
assertCopyGeometry(polygon2, ringPoints, ring2Points);
final Punctual multiPoint = GEOMETRY_FACTORY.punctual(pointPoints);
assertCopyGeometry(multiPoint, pointPoints);
final Punctual multiPoint2 = GEOMETRY_FACTORY.punctual(pointPoints, point2Points);
assertCopyGeometry(multiPoint2, pointPoints, point2Points);
final Lineal multiLineString = GEOMETRY_FACTORY.lineal(ringPoints);
assertCopyGeometry(multiLineString, ringPoints);
final Lineal multiLineString2 = GEOMETRY_FACTORY.lineal(ringPoints, ring2Points);
assertCopyGeometry(multiLineString2, ringPoints, ring2Points);
final Polygonal multiPolygon = GEOMETRY_FACTORY.polygonal(ringPoints);
assertCopyGeometry(multiPolygon, ringPoints);
final Polygonal multiPolygon2 = GEOMETRY_FACTORY.polygonal(ringPoints, ring3Points);
assertCopyGeometry(multiPolygon2, ringPoints, ring3Points);
}
use of com.revolsys.geometry.model.Punctual in project com.revolsys.open by revolsys.
the class GeometryGraph method getBoundaryIntersection.
/**
* Get the intersection between the line and the boundary of this geometry.
*
* @param line
* @return
*/
public Geometry getBoundaryIntersection(final LineString line) {
final List<Point> pointIntersections = new ArrayList<>();
final List<LineString> lineIntersections = new ArrayList<>();
final GeometryFactory geometryFactory = getGeometryFactory();
final BoundingBox boundingBox = getBoundingBox(line);
if (boundingBox.intersects(this.boundingBox)) {
final LineString points = line;
final int vertexCount = points.getVertexCount();
final Point fromPoint = points.getPoint(0);
final Point toPoint = points.getPoint(vertexCount - 1);
Point previousPoint = fromPoint;
for (int vertexIndex = 1; vertexIndex < vertexCount; vertexIndex++) {
final Point nextPoint = points.getPoint(vertexIndex);
final LineSegment line1 = new LineSegmentDoubleGF(getGeometryFactory(), previousPoint, nextPoint);
final List<Edge<LineSegment>> edges = EdgeLessThanDistance.getEdges(this, line1, this.maxDistance);
for (final Edge<LineSegment> edge2 : edges) {
final LineSegment line2 = edge2.getObject();
final Geometry segmentIntersection = line1.getIntersection(line2);
if (segmentIntersection instanceof Point) {
final Point intersection = (Point) segmentIntersection;
if (intersection.equals(fromPoint) || intersection.equals(toPoint)) {
// Point intersection, make sure it's not at the start
final Node<LineSegment> node = findNode(intersection);
if (node == null) {
pointIntersections.add(geometryFactory.point(intersection));
} else {
final int degree = node.getDegree();
if (isStartPoint(node)) {
if (degree > 2) {
// Intersection not at the start/end of the other line,
// taking
// into account loops
pointIntersections.add(geometryFactory.point(intersection));
}
} else if (degree > 1) {
// Intersection not at the start/end of the other line
pointIntersections.add(geometryFactory.point(intersection));
}
}
} else {
// Intersection not at the start/end of the line
pointIntersections.add(geometryFactory.point(intersection));
}
} else if (segmentIntersection instanceof LineSegment) {
lineIntersections.add((LineSegment) segmentIntersection);
}
for (final Point point : line1.vertices()) {
if (line2.distancePoint(point) < this.maxDistance) {
if (point.equals(fromPoint) || point.equals(toPoint)) {
// Point intersection, make sure it's not at the start
final double maxDistance1 = this.maxDistance;
for (final Node<LineSegment> node : this.getNodes(point, maxDistance1)) {
final int degree = node.getDegree();
if (isStartPoint(node)) {
if (degree > 2) {
// Intersection not at the start/end of the other line,
// taking
// into account loops
pointIntersections.add(geometryFactory.point(point));
}
} else if (degree > 1) {
// Intersection not at the start/end of the other line
pointIntersections.add(geometryFactory.point(point));
}
}
} else {
// Intersection not at the start/end of the line
pointIntersections.add(geometryFactory.point(point));
}
}
}
}
previousPoint = nextPoint;
}
}
if (lineIntersections.isEmpty()) {
return geometryFactory.punctual(pointIntersections);
} else {
final List<LineString> mergedLines = LineMerger.merge(lineIntersections);
final Lineal multiLine = geometryFactory.lineal(mergedLines);
if (pointIntersections.isEmpty()) {
return multiLine;
} else {
final Punctual multiPoint = geometryFactory.punctual(pointIntersections);
return multiPoint.union(multiLine);
}
}
}
use of com.revolsys.geometry.model.Punctual in project com.revolsys.open by revolsys.
the class UnaryUnionOp method union.
/**
* Gets the union of the input geometries.
* If no input geometries were provided but a {@link GeometryFactory} was provided,
* an empty {@link Geometry} is returned.
* Otherwise, the return value is <code>null</code>.
*
* @return a Geometry containing the union,
* or an empty GEOMETRYCOLLECTION if no geometries were provided in the input,
* or <code>null</code> if no GeometryFactory was provided
*/
private static Geometry union(final GeometryFactory geometryFactory, final List<Point> points, final List<LineString> lines, final List<Polygon> polygons) {
if (geometryFactory == null) {
return null;
} else {
/**
* For points and lines, only a single union operation is
* required, since the OGC model allowing self-intersecting
* MultiPoint and MultiLineStrings.
* This is not the case for polygons, so Cascaded Union is required.
*/
Punctual unionPoints = null;
if (points.size() > 0) {
final Punctual punctual = geometryFactory.punctual(points);
unionPoints = punctual.union();
}
Geometry unionLines = null;
if (lines.size() > 0) {
final Geometry lineal = geometryFactory.geometry(lines);
unionLines = unionNoOpt(geometryFactory, lineal);
}
Geometry unionPolygons = null;
if (polygons.size() > 0) {
unionPolygons = CascadedPolygonUnion.union(polygons);
}
/**
* Performing two unions is somewhat inefficient,
* but is mitigated by unioning lines and points first
*/
Geometry union = null;
if (unionLines == null) {
union = unionPolygons;
} else if (unionPolygons == null) {
union = unionLines;
} else {
union = unionPolygons.union(unionLines);
}
if (unionPoints != null) {
if (union == null) {
union = unionPoints;
} else {
union = union(unionPoints, union);
}
}
if (union == null) {
return geometryFactory.geometryCollection();
} else {
return union;
}
}
}
Aggregations