use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class EsriAsciiGriddedElevationModelReader method getBufferedReader.
protected BufferedReader getBufferedReader() {
final String fileExtension = this.resource.getFileNameExtension();
try {
if (fileExtension.equals("zip")) {
final ZipInputStream in = this.resource.newBufferedInputStream(ZipInputStream::new);
final String fileName = this.resource.getBaseName();
final String baseName = FileUtil.getBaseName(fileName);
final String projName = baseName + ".prj";
for (ZipEntry zipEntry = in.getNextEntry(); zipEntry != null; zipEntry = in.getNextEntry()) {
final String name = zipEntry.getName();
if (name.equals(projName)) {
final String wkt = FileUtil.getString(new InputStreamReader(in, StandardCharsets.UTF_8), false);
final GeometryFactory geometryFactory = GeometryFactory.floating3d(wkt);
setGeometryFactory(geometryFactory);
} else if (name.equals(fileName)) {
this.reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
return this.reader;
}
}
throw new IllegalArgumentException("Cannot find " + fileName + " in " + this.resource);
} else if (fileExtension.equals("gz")) {
final String baseName = this.resource.getBaseName();
setGeometryFactory(this.resource.getParent().newChildResource(baseName));
final InputStream in = this.resource.newBufferedInputStream();
final GZIPInputStream gzIn = new GZIPInputStream(in);
this.reader = new BufferedReader(new InputStreamReader(gzIn, StandardCharsets.UTF_8));
return this.reader;
} else {
setGeometryFactory(this.resource);
this.reader = this.resource.newBufferedReader();
return this.reader;
}
} catch (final IOException e) {
throw Exceptions.wrap("Unable to open: " + this.resource, e);
}
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class EsriAsciiGriddedElevationModelWriter method open.
protected void open(final GriddedElevationModel model) {
final GeometryFactory geometryFactory = model.getGeometryFactory();
if (this.writer == null) {
final String fileNameExtension = this.resource.getFileNameExtension();
final OutputStream bufferedOut = this.resource.newBufferedOutputStream();
if ("zip".equals(fileNameExtension) || ScaledIntegerGriddedDigitalElevation.FILE_EXTENSION_ZIP.equals(fileNameExtension)) {
try {
final String fileName = this.resource.getBaseName();
final ZipOutputStream zipOut = new ZipOutputStream(bufferedOut);
final String prjString = geometryFactory.toWktCs();
if (prjString.length() > 0) {
final ZipEntry prjEntry = new ZipEntry(FileUtil.getBaseName(fileName) + ".prj");
zipOut.putNextEntry(prjEntry);
zipOut.write(prjString.getBytes(StandardCharsets.UTF_8));
}
final ZipEntry fileEntry = new ZipEntry(fileName);
zipOut.putNextEntry(fileEntry);
this.writer = new OutputStreamWriter(zipOut, StandardCharsets.UTF_8);
} catch (final IOException e) {
throw Exceptions.wrap("Error creating: " + this.resource, e);
}
} else if ("gz".equals(fileNameExtension)) {
try {
String fileName = this.resource.getBaseName();
if (!fileName.endsWith("." + ScaledIntegerGriddedDigitalElevation.FILE_EXTENSION)) {
fileName += "." + ScaledIntegerGriddedDigitalElevation.FILE_EXTENSION;
}
final GZIPOutputStream zipOut = new GZIPOutputStream(bufferedOut);
this.writer = new OutputStreamWriter(zipOut, StandardCharsets.UTF_8);
} catch (final IOException e) {
throw Exceptions.wrap("Error creating: " + this.resource, e);
}
} else {
geometryFactory.writePrjFile(this.resource);
this.writer = this.resource.newWriter();
}
}
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class ScaledIntegerGriddedDigitalElevationModelFile method createNewFile.
protected void createNewFile() throws IOException {
Paths.createParentDirectories(this.path);
this.channel = FileChannel.open(this.path, Paths.OPEN_OPTIONS_READ_WRITE_SET, this.fileAttributes);
try (final ChannelWriter writer = new ChannelWriter(this.channel)) {
final int gridWidth = getGridWidth();
final int gridHeight = getGridHeight();
final double gridCellSize = getGridCellSize();
final BoundingBox boundingBox = getBoundingBox();
final GeometryFactory geometryFactory = getGeometryFactory();
ScaledIntegerGriddedDigitalElevationModelWriter.writeHeader(writer, boundingBox, geometryFactory, gridWidth, gridHeight, (int) gridCellSize);
final int count = gridWidth * gridHeight;
for (int i = 0; i < count; i++) {
writer.putInt(Integer.MIN_VALUE);
}
}
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class ScaledIntegerTriangulatedIrregularNetworkReader method forEachTriangle.
public void forEachTriangle(final TriangleConsumer action) {
open();
final GeometryFactory geometryFactory = this.geometryFactory;
final ChannelReader in = this.in;
try {
boolean hasMore = true;
while (hasMore) {
int triangleVertexCount = 0;
try {
final double x1 = geometryFactory.toDoubleX(in.getInt());
final double y1 = geometryFactory.toDoubleY(in.getInt());
final double z1 = geometryFactory.toDoubleZ(in.getInt());
final double x2 = geometryFactory.toDoubleX(in.getInt());
final double y2 = geometryFactory.toDoubleY(in.getInt());
final double z2 = geometryFactory.toDoubleZ(in.getInt());
final double x3 = geometryFactory.toDoubleX(in.getInt());
final double y3 = geometryFactory.toDoubleY(in.getInt());
final double z3 = geometryFactory.toDoubleZ(in.getInt());
action.accept(x1, y1, z1, x2, y2, z2, x3, y3, z3);
triangleVertexCount = 9;
} catch (final WrappedException e) {
if (Exceptions.isException(e, EOFException.class) && triangleVertexCount == 0) {
hasMore = false;
} else {
throw e;
}
}
}
} finally {
close();
}
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class Graph method moveToMidpoint.
public void moveToMidpoint(final Map<Point, Point> movedNodes, final Graph<T> graph1, final Node<T> node1, final Node<T> node2) {
final GeometryFactory precisionModel = graph1.getPrecisionModel();
final Point midPoint = LineSegmentUtil.midPoint(precisionModel, node1, node2);
if (!node1.equals(2, midPoint)) {
if (movedNodes != null) {
movedNodes.put(node1.newPoint2D(), midPoint);
}
node1.moveNode(midPoint);
}
if (!node2.equals(2, midPoint)) {
if (movedNodes != null) {
movedNodes.put(node2.newPoint2D(), midPoint);
}
node2.moveNode(midPoint);
}
}
Aggregations