use of com.revolsys.geometry.model.vertex.Vertex in project com.revolsys.open by revolsys.
the class ScaledIntegerGriddedDigitalElevation method setElevationNearest.
@SuppressWarnings("unchecked")
public static <G extends Geometry> G setElevationNearest(final Path baseDirectory, final int coordinateSystemId, final int gridCellSize, final int gridSize, final String fileExtension, final G geometry) {
final GeometryEditor<?> editor = geometry.newGeometryEditor();
editor.setAxisCount(3);
for (final Vertex vertex : geometry.vertices()) {
final double x = vertex.getX();
final double y = vertex.getY();
final double elevation = getElevationNearest(baseDirectory, coordinateSystemId, gridCellSize, gridSize, fileExtension, x, y);
if (!Double.isNaN(elevation)) {
final int[] vertexId = vertex.getVertexId();
editor.setZ(vertexId, elevation);
}
}
return (G) editor.newGeometry();
}
use of com.revolsys.geometry.model.vertex.Vertex in project com.revolsys.open by revolsys.
the class BufferCurveMaximumDistanceFinder method computeMaxVertexDistance.
private void computeMaxVertexDistance(final Geometry curve) {
final PointPairDistance maxPtDist = new PointPairDistance();
final PointPairDistance minPtDist = new PointPairDistance();
for (final Vertex vertex : curve.vertices()) {
minPtDist.initialize();
DistanceToPointFinder.computeDistance(this.inputGeom, vertex, minPtDist);
maxPtDist.setMaximum(minPtDist);
}
this.maxPtDist.setMaximum(maxPtDist);
}
use of com.revolsys.geometry.model.vertex.Vertex in project com.revolsys.open by revolsys.
the class PolygonTest method testVertices.
@Test
public void testVertices() {
final List<Point> allCoordinates = new ArrayList<>();
allCoordinates.addAll(EXTERIOR_1);
allCoordinates.addAll(INTERIOR_2);
final Polygon polygon = WITH_HOLE;
int i = 0;
for (final Vertex vertex : polygon.vertices()) {
final Point point = allCoordinates.get(i);
Assert.assertEquals(point, vertex);
i++;
}
Assert.assertEquals(new PointDoubleXY(0.0, 0.0), polygon.getVertex(0, 0));
Assert.assertNull("VertexIndex out of range", polygon.getVertex(0, 6));
Assert.assertNull("VertexIndex out of range", polygon.getVertex(1, 6));
Assert.assertNull("RingIndex Negative", polygon.getVertex(-1, 0));
Assert.assertNull("RingIndex out of range", polygon.getVertex(2, 0));
}
use of com.revolsys.geometry.model.vertex.Vertex in project com.revolsys.open by revolsys.
the class PackedCoordinateUtil method getPackedBytes.
public static byte[] getPackedBytes(final Double xOffset, final Double yOffset, final Double xyScale, final boolean hasZ, final Double zOffset, final Double zScale, final boolean hasM, final Double mScale, final Double mOffset, final List<List<Geometry>> parts) {
final int packedByteLength = 0;
byte dimensionFlag = 0;
final byte annotationDimension = 0;
final byte shapeFlags = 0;
if (hasZ) {
dimensionFlag |= 1;
}
if (hasM) {
dimensionFlag |= 2;
}
final PackedIntegerOutputStream out = new PackedIntegerOutputStream();
out.writeLong5(packedByteLength);
out.writeLong(dimensionFlag);
out.writeLong(annotationDimension);
out.writeLong(shapeFlags);
// Write x,y for all parts
long previousX = Math.round(xOffset * xyScale);
long previousY = Math.round(yOffset * xyScale);
boolean first = true;
for (final List<Geometry> part : parts) {
if (first) {
first = false;
} else {
out.writeLong(-1 - previousX);
out.writeLong(-previousY);
previousX = -1;
previousY = 0;
}
for (final Geometry component : part) {
for (final Vertex vertex : component.vertices()) {
previousX = writeCoordinate(out, vertex, previousX, xyScale, 0);
previousY = writeCoordinate(out, vertex, previousY, xyScale, 1);
}
}
}
// Write z for all parts
if (hasZ) {
writeMultiCoordinates(out, parts, 2, zOffset, zScale);
}
// Write m for all parts
if (hasM) {
writeMultiCoordinates(out, parts, 3, mOffset, mScale);
}
return out.toByteArray();
}
use of com.revolsys.geometry.model.vertex.Vertex 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;
}
Aggregations