use of com.revolsys.elevation.gridded.GriddedElevationModel in project com.revolsys.open by revolsys.
the class HillShadeGriddedElevationModelRasterizer method getValue.
@Override
public int getValue(final int gridX, final int gridY) {
final GriddedElevationModel elevationModel = this.elevationModel;
final int width = this.width;
final int height = this.height;
double a = Double.NaN;
double b = Double.NaN;
double c = Double.NaN;
double d = Double.NaN;
final double e = elevationModel.getElevationFast(gridX, gridY);
if (Double.isFinite(e)) {
double f = Double.NaN;
double g = Double.NaN;
double h = Double.NaN;
double i = Double.NaN;
final boolean firstX = gridX == 0;
final boolean firstY = gridY == 0;
final boolean lastX = gridX == width - 1;
final boolean lastY = gridY == height - 1;
final int gridX0 = gridX - 1;
final int gridX2 = gridX + 1;
if (!lastY) {
final int gridY2 = gridY + 1;
if (!firstX) {
a = elevationModel.getElevationFast(gridX0, gridY2);
}
b = elevationModel.getElevationFast(gridX, gridY2);
if (!lastX) {
c = elevationModel.getElevationFast(gridX2, gridY2);
}
}
if (!firstX) {
d = elevationModel.getElevationFast(gridX0, gridY);
}
if (!lastX) {
f = elevationModel.getElevationFast(gridX2, gridY);
}
if (!firstY) {
final int gridY0 = gridY - 1;
if (!firstX) {
g = elevationModel.getElevationFast(gridX0, gridY0);
}
h = elevationModel.getElevationFast(gridX, gridY0);
if (!lastX) {
i = elevationModel.getElevationFast(gridX2, gridY0);
}
}
if (!Double.isFinite(d)) {
if (Double.isFinite(f)) {
d = e - (f - e);
} else {
d = e;
f = e;
}
} else if (!Double.isFinite(f)) {
f = e;
}
if (!Double.isFinite(a)) {
if (Double.isFinite(g)) {
a = d - (g - d);
} else {
a = d;
}
}
if (!Double.isFinite(b)) {
if (Double.isFinite(h)) {
b = e - (h - e);
} else {
b = e;
}
}
if (!Double.isFinite(c)) {
if (Double.isFinite(i)) {
c = f - (i - f);
} else {
c = f;
}
}
if (!Double.isFinite(g)) {
g = d - (a - d);
}
if (!Double.isFinite(h)) {
h = e - (b - e);
}
if (!Double.isFinite(i)) {
i = f - (c - f);
}
return getHillShade(a, b, c, d, f, g, h, i);
} else {
return GriddedElevationModel.NULL_COLOUR;
}
}
use of com.revolsys.elevation.gridded.GriddedElevationModel in project com.revolsys.open by revolsys.
the class GriddedElevationModelTest method assertWriteRead.
/**
* 1. Write the model to the file specified by filePath.
* 2. Read the model from the written file.
* 3. Compare the read model with the original model
*
* @param model The model to test.
* @param filePath The file to write to.
*/
protected static void assertWriteRead(final GriddedElevationModel model, final String filePath) {
final Path path = writeModel(model, filePath);
final GriddedElevationModel actualModel = GriddedElevationModel.newGriddedElevationModel(path);
assertModelEquals(model, actualModel);
}
use of com.revolsys.elevation.gridded.GriddedElevationModel in project com.revolsys.open by revolsys.
the class GriddedElevationModelTest method newIntArrayModelNaNOnDiagonal.
/**
* Create a new {@link IntArrayScaleGriddedElevationModel}.
* The elevation for each cell is set to gridX.gridY (e.g. 10.34).
* Except where gridX == gridY where NaN is used.
*
* @param coordinateSystemId The coordinate system id.
* @return The model
*/
protected static GriddedElevationModel newIntArrayModelNaNOnDiagonal(final int coordinateSystemId) {
final GeometryFactory geometryFactory = GeometryFactory.fixed3d(coordinateSystemId, 1000.0, 1000.0, 1000.0);
final GriddedElevationModel model = new IntArrayScaleGriddedElevationModel(geometryFactory, 0, 0, 255, 255, 1);
for (int gridY = 0; gridY < model.getGridHeight() - 1; gridY++) {
for (int gridX = 0; gridX < model.getGridWidth() - 1; gridX++) {
double elevation;
if (gridX == gridY) {
elevation = Double.NaN;
} else {
elevation = gridX + gridY / 1000.0;
}
model.setElevation(gridX, gridY, elevation);
}
}
return model;
}
use of com.revolsys.elevation.gridded.GriddedElevationModel in project com.revolsys.open by revolsys.
the class GriddedElevationModelLayer method propertyChange.
@Override
public void propertyChange(final PropertyChangeEvent event) {
super.propertyChange(event);
final String propertyName = event.getPropertyName();
if ("hasChanges".equals(propertyName)) {
final GriddedElevationModel image = getElevationModel();
if (event.getSource() == image) {
image.writeGriddedElevationModel();
}
}
}
use of com.revolsys.elevation.gridded.GriddedElevationModel in project com.revolsys.open by revolsys.
the class MultipleGriddedElevationModelLayerRenderer method addRenderer.
@Override
public int addRenderer(int index, final RasterizerGriddedElevationModelLayerRenderer renderer) {
if (renderer == null) {
return -1;
} else {
final String originalName = renderer.getName();
String name = originalName;
int i = 1;
while (hasRendererWithSameName(renderer, name)) {
name = originalName + i;
i++;
}
renderer.setName(name);
renderer.setParent(this);
synchronized (this.renderers) {
if (index < 0) {
index = this.renderers.size();
}
final GriddedElevationModel elevationModel = getElevationModel();
renderer.setElevationModel(elevationModel);
this.renderers.add(index, renderer);
}
firePropertyChange("renderers", index, null, renderer);
return index;
}
}
Aggregations