use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class OgrRecordWriter method toOgrGeometry.
protected org.gdal.ogr.Geometry toOgrGeometry(final Geometry geometry, final int geometryType, final int axisCount) {
final org.gdal.ogr.Geometry ogrGeometry = new org.gdal.ogr.Geometry(geometryType);
if (!geometry.isEmpty()) {
switch(geometryType) {
case 1:
case 0x80000000 + 1:
{
final Point point = (Point) geometry;
final double x = point.getX();
final double y = point.getY();
if (axisCount == 2) {
ogrGeometry.AddPoint(x, y);
} else {
final double z = point.getZ();
ogrGeometry.AddPoint(x, y, z);
}
}
break;
case 2:
case 0x80000000 + 2:
final LineString line = (LineString) geometry;
final int vertexCount = line.getVertexCount();
for (int vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
final double x = line.getX(vertexIndex);
final double y = line.getY(vertexIndex);
if (axisCount == 2) {
ogrGeometry.AddPoint(x, y);
} else {
final double z = line.getZ(vertexIndex);
ogrGeometry.AddPoint(x, y, z);
}
}
break;
case 3:
case 0x80000000 + 3:
for (final LinearRing ring : ((Polygon) geometry).rings()) {
final org.gdal.ogr.Geometry ogrRing = toOgrGeometry(ring, 101, axisCount);
ogrGeometry.AddGeometry(ogrRing);
}
break;
case 4:
addParts(ogrGeometry, geometry, 1, axisCount);
break;
case 0x80000000 + 4:
addParts(ogrGeometry, geometry, 0x80000000 + 1, axisCount);
break;
case 5:
addParts(ogrGeometry, geometry, 2, axisCount);
break;
case 0x80000000 + 5:
addParts(ogrGeometry, geometry, 0x80000000 + 2, axisCount);
break;
case 6:
addParts(ogrGeometry, geometry, 3, axisCount);
break;
case 0x80000000 + 6:
addParts(ogrGeometry, geometry, 0x80000000 + 3, axisCount);
break;
// return this.geometryFactory.geometry(parts);
case 101:
for (final Vertex vertex : geometry.vertices()) {
final double x = vertex.getX();
final double y = vertex.getY();
if (axisCount == 2) {
ogrGeometry.AddPoint(x, y);
} else {
final double z = vertex.getZ();
ogrGeometry.AddPoint(x, y, z);
}
}
break;
default:
return null;
}
}
if (axisCount == 2) {
ogrGeometry.FlattenTo2D();
}
return ogrGeometry;
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class DistanceToPoint method computeDistance.
public static void computeDistance(final Geometry geom, final Point point, final PointPairDistance pointDistance) {
if (geom instanceof LineString) {
final LineString line = (LineString) geom;
computeDistance(line, point, pointDistance);
} else if (geom instanceof Polygon) {
final Polygon polygon = (Polygon) geom;
computeDistance(polygon, point, pointDistance);
} else if (geom.isGeometryCollection()) {
for (final Geometry part : geom.geometries()) {
computeDistance(part, point, pointDistance);
}
} else {
// assume geom is Point
pointDistance.setMinimum(geom.getPoint(), point);
}
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class LineMatchGraph method getNonMatchedLines.
public Lineal getNonMatchedLines(final int index1, final int index2) {
final List<LineString> lines = new ArrayList<>();
final Set<Edge<LineSegmentMatch>> processedEdges = new HashSet<>();
for (Node<LineSegmentMatch> currentNode : getStartNodes(index1)) {
final List<Point> coordinates = new ArrayList<>();
while (currentNode != null) {
Node<LineSegmentMatch> nextNode = null;
final List<Edge<LineSegmentMatch>> edges = currentNode.getOutEdges();
for (final Edge<LineSegmentMatch> edge : edges) {
final LineSegmentMatch lineSegmentMatch = edge.getObject();
if (lineSegmentMatch.hasSegment(index1) && !processedEdges.contains(edge)) {
if (!lineSegmentMatch.hasMatches(index1, index2)) {
if (coordinates.isEmpty()) {
final Point startCoordinate = currentNode;
coordinates.add(startCoordinate);
}
final Node<LineSegmentMatch> toNode = edge.getToNode();
final Point toCoordinate = toNode;
coordinates.add(toCoordinate);
} else {
newLine(lines, coordinates);
coordinates.clear();
}
processedEdges.add(edge);
nextNode = edge.getToNode();
}
}
currentNode = nextNode;
}
newLine(lines, coordinates);
}
return this.geometryFactory.lineal(lines);
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class LineMatchGraph method add.
private void add(final LineString line, final int index) {
if (line.getLength() > 0) {
final LineString coords = line;
final Point coordinate0 = coords.getPoint(0);
final Node<LineSegmentMatch> node = getNode(coordinate0);
final Set<Node<LineSegmentMatch>> indexStartNodes = getStartNodes(index);
indexStartNodes.add(node);
Point previousCoordinate = coordinate0;
for (int i = 1; i < coords.getVertexCount(); i++) {
final Point coordinate = coords.getPoint(i);
final LineSegment segment = new LineSegmentDoubleGF(this.geometryFactory, previousCoordinate, coordinate);
if (segment.getLength() > 0) {
add(previousCoordinate, coordinate, segment, index);
}
previousCoordinate = coordinate;
}
}
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class LineMatchGraph method getOverlappingMatches.
public Lineal getOverlappingMatches() {
final List<LineString> overlappingLines = new ArrayList<>();
final Set<Edge<LineSegmentMatch>> processedEdges = new HashSet<>();
for (Node<LineSegmentMatch> currentNode : getStartNodes(0)) {
while (currentNode != null) {
Node<LineSegmentMatch> nextNode = null;
final List<Edge<LineSegmentMatch>> edges = currentNode.getOutEdges();
for (final Edge<LineSegmentMatch> edge : edges) {
final LineSegmentMatch lineSegmentMatch = edge.getObject();
if (lineSegmentMatch.hasSegment(0) && !processedEdges.contains(edge)) {
if (lineSegmentMatch.getMatchCount(0) > 2) {
for (int i = 1; i < lineSegmentMatch.getSegmentCount() && lineSegmentMatch.getMatchCount(0) > 2; i++) {
if (lineSegmentMatch.hasSegment(i)) {
if (!hasMatch(currentNode, false, 0, i)) {
final Node<LineSegmentMatch> toNode = edge.getToNode();
if (!hasMatch(toNode, true, 0, i)) {
lineSegmentMatch.removeSegment(i);
} else {
final double matchLength = getMatchLength(currentNode, false, 0, i);
final double duplicateMatchLength = getDuplicateMatchLength(currentNode, true, 0, i);
if (matchLength + duplicateMatchLength <= 2) {
lineSegmentMatch.removeSegment(i);
}
}
}
}
}
if (lineSegmentMatch.getMatchCount(0) > 2) {
overlappingLines.add(lineSegmentMatch.getLine());
}
}
processedEdges.add(edge);
nextNode = edge.getToNode();
}
}
currentNode = nextNode;
}
}
final Lineal lines = this.geometryFactory.lineal(overlappingLines);
return lines;
}
Aggregations