use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class ShapefileGeometryUtil method writePolygon.
private List<LineString> writePolygon(final EndianOutput out, final Geometry geometry, final int shapeType, final int headerOverhead, final int wordsPerPoint) throws IOException {
int vertexCount = 0;
final List<LineString> rings = new ArrayList<>();
for (int i = 0; i < geometry.getGeometryCount(); i++) {
final Geometry part = geometry.getGeometry(i);
if (part instanceof Polygon) {
final Polygon polygon = (Polygon) part;
LineString shell = polygon.getShell();
shell = shell.toClockwise();
rings.add(shell);
vertexCount += shell.getVertexCount();
final int numHoles = polygon.getHoleCount();
for (int j = 0; j < numHoles; j++) {
LineString hole = polygon.getHole(j);
hole = hole.toCounterClockwise();
rings.add(hole);
vertexCount += hole.getVertexCount();
}
} else {
throw new IllegalArgumentException("Expecting " + Polygon.class + " geometry got " + part.getClass());
}
}
final int numParts = rings.size();
if (this.writeLength) {
final int recordLength = 22 + headerOverhead + 2 * numParts + wordsPerPoint * vertexCount;
out.writeInt(recordLength);
}
out.writeLEInt(shapeType);
final BoundingBox envelope = geometry.getBoundingBox();
writeEnvelope(out, envelope);
out.writeLEInt(numParts);
out.writeLEInt(vertexCount);
int partIndex = 0;
for (final LineString ring : rings) {
out.writeLEInt(partIndex);
partIndex += ring.getVertexCount();
}
for (final LineString ring : rings) {
writeXYCoordinates(out, ring);
}
return rings;
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class ShapefileGeometryHandler method writeZCoordinatesRange.
public void writeZCoordinatesRange(final EndianOutput out, final List<LineString> coordinatesList) {
double minZ = Double.MAX_VALUE;
double maxZ = -Double.MAX_VALUE;
for (final LineString ring : coordinatesList) {
for (int i = 0; i < ring.getVertexCount(); i++) {
double z = ring.getCoordinate(i, 2);
if (Double.isNaN(z)) {
z = 0;
}
minZ = Math.min(z, minZ);
maxZ = Math.max(z, maxZ);
}
}
if (minZ == Double.MAX_VALUE || maxZ == -Double.MAX_VALUE) {
out.writeLEDouble(0);
out.writeLEDouble(0);
} else {
out.writeLEDouble(minZ);
out.writeLEDouble(maxZ);
}
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class ShapefileGeometryHandler method writeMCoordinatesRange.
public void writeMCoordinatesRange(final EndianOutput out, final List<LineString> coordinatesList) {
double minM = Double.MAX_VALUE;
double maxM = -Double.MAX_VALUE;
for (final LineString ring : coordinatesList) {
for (int i = 0; i < ring.getVertexCount(); i++) {
double m = ring.getCoordinate(i, 2);
if (Double.isNaN(m)) {
m = 0;
}
minM = Math.min(m, minM);
maxM = Math.max(m, maxM);
}
}
if (minM == Double.MAX_VALUE && maxM == -Double.MAX_VALUE) {
out.writeLEDouble(0);
out.writeLEDouble(0);
} else {
out.writeLEDouble(minM);
out.writeLEDouble(maxM);
}
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class ShapefileGeometryHandler method readPolyline.
public Geometry readPolyline(final GeometryFactory geometryFactory, final ByteBuffer buffer, final int recordLength) {
buffer.getDouble();
buffer.getDouble();
buffer.getDouble();
buffer.getDouble();
final int numParts = buffer.getInt();
final int vertexCount = buffer.getInt();
final int axisCount = 2;
if (numParts == 1) {
buffer.getInt();
final double[] coordinates = readXYCoordinates(buffer, vertexCount, axisCount);
return geometryFactory.lineString(2, coordinates);
} else {
final int[] partIndex = new int[numParts + 1];
partIndex[numParts] = vertexCount;
for (int i = 0; i < partIndex.length - 1; i++) {
partIndex[i] = buffer.getInt();
}
final List<LineString> lines = new ArrayList<>();
for (int i = 0; i < partIndex.length - 1; i++) {
final int startIndex = partIndex[i];
final int endIndex = partIndex[i + 1];
final int numCoords = endIndex - startIndex;
final double[] coordinates = readXYCoordinates(buffer, numCoords, axisCount);
lines.add(geometryFactory.lineString(2, coordinates));
}
return geometryFactory.lineal(lines);
}
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class MoepBinaryIterator method readLineString.
private void readLineString(final int extraParams, final Record object) throws IOException {
int numCoords = 0;
if (extraParams == 2 || extraParams == 4) {
numCoords = readLEShort(this.in);
} else {
numCoords = read();
}
if (extraParams == 3 || extraParams == 4) {
final int z = readLEShort(this.in);
final LineString line = readContourLine(numCoords);
object.setGeometryValue(line);
object.setValue(MoepConstants.ELEVATION, z);
} else {
final LineString line = readSimpleLine(numCoords);
object.setGeometryValue(line);
}
}
Aggregations