use of com.revolsys.geometry.model.Lineal 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.Lineal in project com.revolsys.open by revolsys.
the class LineStringRelate method isEndOverlaps.
public boolean isEndOverlaps(final double maxDistance) {
if (isOverlaps()) {
boolean overlaps = false;
final boolean from1Within = isWithin2(this.fromPoint1, maxDistance);
final boolean to1Within = isWithin2(this.toPoint1, 1);
if (from1Within != to1Within) {
final boolean from2Within = isWithin1(this.fromPoint2, 1);
final boolean to2Within = isWithin1(this.toPoint2, 1);
if (from2Within != to2Within) {
overlaps = true;
}
}
if (overlaps) {
final Lineal intersection = getOverlap();
if (intersection.getGeometryCount() == 1) {
return true;
}
}
}
return false;
}
use of com.revolsys.geometry.model.Lineal in project com.revolsys.open by revolsys.
the class GmlGeometryFieldType method geometry.
private void geometry(final XmlWriter out, final Object value, final boolean writeSrsName) {
if (value instanceof Geometry) {
final Geometry geometry = (Geometry) value;
if (geometry instanceof Point) {
final Point point = (Point) geometry;
point(out, point, writeSrsName);
} else if (geometry instanceof LineString) {
final LineString line = (LineString) geometry;
lineString(out, line, writeSrsName);
} else if (geometry instanceof Polygon) {
final Polygon polygon = (Polygon) geometry;
polygon(out, polygon, writeSrsName);
} else if (geometry instanceof Punctual) {
final Punctual punctual = (Punctual) geometry;
multiPoint(out, punctual, writeSrsName);
} else if (geometry instanceof Lineal) {
final Lineal lineal = (Lineal) geometry;
multiLineString(out, lineal, writeSrsName);
} else if (geometry instanceof Polygonal) {
final Polygonal polygonal = (Polygonal) geometry;
multiPolygon(out, polygonal, writeSrsName);
} else if (geometry.isGeometryCollection()) {
geometryCollection(out, geometry, writeSrsName);
}
}
}
use of com.revolsys.geometry.model.Lineal in project com.revolsys.open by revolsys.
the class MultiLineStringVertex method next.
@Override
public Vertex next() {
final Lineal lineal = getLineal();
this.vertexIndex++;
while (this.partIndex < lineal.getGeometryCount()) {
final LineString lineString = lineal.getLineString(this.partIndex);
if (this.vertexIndex < lineString.getVertexCount()) {
return this;
} else {
this.partIndex++;
this.vertexIndex = 0;
}
}
throw new NoSuchElementException();
}
use of com.revolsys.geometry.model.Lineal in project com.revolsys.open by revolsys.
the class EWktWriter method write.
public static void write(final Writer out, final Geometry geometry) {
if (geometry != null) {
if (geometry instanceof Point) {
final Point point = (Point) geometry;
write(out, point);
} else if (geometry instanceof Punctual) {
final Punctual punctual = (Punctual) geometry;
write(out, punctual);
} else if (geometry instanceof LinearRing) {
final LinearRing line = (LinearRing) geometry;
write(out, line);
} else if (geometry instanceof LineString) {
final LineString line = (LineString) geometry;
write(out, line);
} else if (geometry instanceof Lineal) {
final Lineal lineal = (Lineal) geometry;
write(out, lineal);
} else if (geometry instanceof Polygon) {
final Polygon polygon = (Polygon) geometry;
write(out, polygon);
} else if (geometry instanceof Polygonal) {
final Polygonal polygonal = (Polygonal) geometry;
write(out, polygonal);
} else if (geometry.isGeometryCollection()) {
writeGeometryCollection(out, geometry);
} else {
throw new IllegalArgumentException("Unknown geometry type" + geometry.getClass());
}
}
}
Aggregations