use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.
the class Gdal method loadSettings.
public static long loadSettings(final Dataset dataset, final Resource resource) {
final Resource settingsFile = resource.newResourceAddExtension("rgobject");
if (settingsFile.exists()) {
try {
final Map<String, Object> settings = Json.toMap(settingsFile);
final String boundingBoxWkt = (String) settings.get("boundingBox");
if (Property.hasValue(boundingBoxWkt)) {
final BoundingBox boundingBox = BoundingBox.newBoundingBox(boundingBoxWkt);
if (!boundingBox.isEmpty()) {
setSpatialReference(dataset, boundingBox.getGeometryFactory());
final double x = boundingBox.getMinX();
final double width = boundingBox.getWidth();
final int imageWidth = dataset.getRasterXSize();
final double y = boundingBox.getMaxY();
final double height = boundingBox.getHeight();
final int imageHeight = dataset.getRasterYSize();
final double[] transform = new double[] { x, width / imageWidth, 0, y, 0, -height / imageHeight };
dataset.SetGeoTransform(transform);
}
}
return settingsFile.getLastModified();
} catch (final Throwable e) {
Logs.error(Gdal.class, "Unable to load:" + settingsFile, e);
return -1;
}
} else {
return -1;
}
}
use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.
the class GdalImage method drawImage.
@Override
public void drawImage(final Graphics2D graphics, final BoundingBox viewBoundingBox, final int viewWidth, final int viewHeight, final boolean useTransform, final Object interpolationMethod) {
try {
final Dataset dataset = getDataset();
final BoundingBox imageBoundingBox = getBoundingBox();
final BoundingBox clipBoundingBox = viewBoundingBox.intersection(imageBoundingBox);
final double scaleFactor = viewWidth / viewBoundingBox.getWidth();
final double clipModelWidth = clipBoundingBox.getWidth();
final int targetWidth = (int) Math.ceil(clipModelWidth * scaleFactor);
final double clipModelHeight = clipBoundingBox.getHeight();
final int targetHeight = (int) Math.ceil(clipModelHeight * scaleFactor);
int bestOverviewIdx = -1;
int srcWidth = getImageWidth();
final double clipResolution = Math.abs(clipBoundingBox.getHeight() / targetHeight);
final List<Dimension> overviewSizes = getOverviewSizes();
for (int i = 0; i < overviewSizes.size(); i++) {
final Dimension overviewSize = overviewSizes.get(i);
final int width = overviewSize.width;
final int height = overviewSize.height;
if (0 != height && 0 != width) {
final double overviewResolution = Math.abs(imageBoundingBox.getHeight() / height);
if (overviewResolution <= clipResolution) {
bestOverviewIdx = i;
srcWidth = width;
}
}
}
final double scale = srcWidth / imageBoundingBox.getWidth();
final int clipXoff = (int) Math.floor((clipBoundingBox.getMinX() - imageBoundingBox.getMinX()) * scale);
final int clipYoff = (int) Math.floor((imageBoundingBox.getMaxY() - clipBoundingBox.getMaxY()) * scale);
final int clipWidth = (int) Math.ceil(clipModelWidth * scale);
final int clipHeight = (int) Math.ceil(clipModelHeight * scale);
final BufferedImage bufferedImage = Gdal.getBufferedImage(dataset, bestOverviewIdx, clipXoff, clipYoff, clipWidth, clipHeight, targetWidth, targetHeight);
super.drawRenderedImage(bufferedImage, clipBoundingBox, graphics, viewBoundingBox, viewWidth, useTransform, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
} catch (final Throwable e) {
e.printStackTrace();
}
}
use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.
the class PointCloud method newGriddedElevationModel.
default GriddedElevationModel newGriddedElevationModel(final Map<String, ? extends Object> properties) {
final TriangulatedIrregularNetwork tin = newTriangulatedIrregularNetwork();
final BoundingBox boundingBox = getBoundingBox();
final int minX = (int) Math.floor(boundingBox.getMinX());
final int minY = (int) Math.floor(boundingBox.getMinY());
final int maxX = (int) Math.ceil(boundingBox.getMaxX());
final int maxY = (int) Math.ceil(boundingBox.getMaxY());
final int width = maxX - minX;
final int height = maxY - minY;
final IntArrayScaleGriddedElevationModel elevationModel = new IntArrayScaleGriddedElevationModel(getGeometryFactory().convertAxisCountAndScales(3, 1000.0, 1000.0, 1000.0), minX, minY, width, height, 1);
tin.forEachTriangle(elevationModel::setElevationsForTriangle);
return null;
}
use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.
the class EpsgCoordinateSystems method loadArea.
private static void loadArea() {
try (ChannelReader reader = newChannelReader("area")) {
while (true) {
final int code = reader.getInt();
final String name = reader.getStringUtf8ByteCount();
final double minX = reader.getDouble();
final double minY = reader.getDouble();
final double maxX = reader.getDouble();
final double maxY = reader.getDouble();
final boolean deprecated = readBoolean(reader);
final Authority authority = new EpsgAuthority(code);
BoundingBox boundingBox;
if (Double.isFinite(minX) || Double.isFinite(minX) || Double.isFinite(minX) || Double.isFinite(minX)) {
boundingBox = new BoundingBoxDoubleXY(minX, minY, maxX, maxY);
} else {
boundingBox = BoundingBox.empty();
}
final Area area = new Area(name, boundingBox, authority, deprecated);
AREA_BY_ID.put(code, area);
}
} catch (final NoSuchResourceException e) {
} catch (final WrappedException e) {
if (Exceptions.isException(e, EOFException.class)) {
} else {
throw e;
}
}
}
use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.
the class RayCrossingCounter method locatePointInRing.
public static Location locatePointInRing(final LineString ring, final double x, final double y) {
final BoundingBox boundingBox = ring.getBoundingBox();
if (boundingBox.covers(x, y)) {
final RayCrossingCounter counter = new RayCrossingCounter(x, y);
ring.findSegment((x1, y1, x2, y2) -> {
counter.countSegment(x2, y2, x1, y1);
if (counter.isOnSegment()) {
return counter.getLocation();
}
return null;
});
return counter.getLocation();
} else {
return Location.EXTERIOR;
}
}
Aggregations