use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.
the class EsriGeodatabaseXmlRecordWriter method writeExtent.
public void writeExtent(final GeometryFactory geometryFactory) {
if (geometryFactory != null) {
final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
if (coordinateSystem != null) {
final BoundingBox boundingBox = coordinateSystem.getAreaBoundingBox();
this.out.startTag(EXTENT);
this.out.attribute(XsiConstants.TYPE, ENVELOPE_N_TYPE);
this.out.element(X_MIN, boundingBox.getMinX());
this.out.element(Y_MIN, boundingBox.getMinY());
this.out.element(X_MAX, boundingBox.getMaxX());
this.out.element(Y_MAX, boundingBox.getMaxY());
this.out.element(Z_MIN, boundingBox.getMin(2));
this.out.element(Z_MAX, boundingBox.getMax(2));
writeSpatialReference(geometryFactory);
this.out.endTag(EXTENT);
}
}
}
use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.
the class SpatialReference method getGeometryFactory.
public GeometryFactory getGeometryFactory() {
if (this.geometryFactory == null) {
final CoordinateSystem coordinateSystem = getCoordinateSystem();
int coordinateSystemId;
if (coordinateSystem == null) {
coordinateSystemId = 0;
} else {
coordinateSystemId = coordinateSystem.getCoordinateSystemId();
}
if (this.xYScale == FLOATING_SCALE) {
this.geometryFactory = GeometryFactory.fixed3d(coordinateSystemId, 0.0, 0.0, this.zScale);
} else {
this.geometryFactory = GeometryFactory.fixed3d(coordinateSystemId, this.xYScale, this.xYScale, this.zScale);
}
}
return this.geometryFactory;
}
use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.
the class CoordinateSystemField method itemStateChanged.
@Override
public void itemStateChanged(final ItemEvent e) {
final int stateChange = e.getStateChange();
if (stateChange == ItemEvent.SELECTED) {
final Object value = e.getItem();
final CoordinateSystem coordinateSystem = getCoordinateSystem(value);
if (coordinateSystem != null) {
final GeometryFactory geometryFactory = coordinateSystem.getGeometryFactory();
geometryFactoryChanged(geometryFactory);
}
}
}
use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.
the class TiffImage method loadGeoTiffMetaData.
private boolean loadGeoTiffMetaData(final XTIFFDirectory directory) {
try {
final int xResolution = (int) getFieldAsDouble(directory, TAG_X_RESOLUTION, 1);
final int yResolution = (int) getFieldAsDouble(directory, TAG_Y_RESOLUTION, 1);
setDpi(xResolution, yResolution);
} catch (final Throwable e) {
Logs.error(this, e);
}
GeometryFactory geometryFactory = null;
final Map<Integer, Object> geoKeys = getGeoKeys(directory);
int coordinateSystemId = Maps.getInteger(geoKeys, PROJECTED_COORDINATE_SYSTEM_ID, 0);
if (coordinateSystemId == 0) {
coordinateSystemId = Maps.getInteger(geoKeys, GEOGRAPHIC_COORDINATE_SYSTEM_ID, 0);
if (coordinateSystemId != 0) {
geometryFactory = GeometryFactory.floating2d(coordinateSystemId);
}
} else if (coordinateSystemId <= 0 || coordinateSystemId == 32767) {
final int geoSrid = Maps.getInteger(geoKeys, GEOGRAPHIC_COORDINATE_SYSTEM_ID, 0);
if (geoSrid != 0) {
if (geoSrid > 0 && geoSrid < 32767) {
final GeographicCoordinateSystem geographicCoordinateSystem = EpsgCoordinateSystems.getCoordinateSystem(geoSrid);
final String name = "unknown";
final CoordinateOperationMethod coordinateOperationMethod = getProjection(geoKeys);
final Map<ParameterName, ParameterValue> parameters = new LinkedHashMap<>();
addDoubleParameter(parameters, ParameterNames.STANDARD_PARALLEL_1, geoKeys, STANDARD_PARALLEL_1_KEY);
addDoubleParameter(parameters, ParameterNames.STANDARD_PARALLEL_2, geoKeys, STANDARD_PARALLEL_2_KEY);
addDoubleParameter(parameters, ParameterNames.CENTRAL_MERIDIAN, geoKeys, LONGITUDE_OF_CENTER_2_KEY);
addDoubleParameter(parameters, ParameterNames.LATITUDE_OF_ORIGIN, geoKeys, LATITUDE_OF_CENTER_2_KEY);
addDoubleParameter(parameters, ParameterNames.FALSE_EASTING, geoKeys, FALSE_EASTING_KEY);
addDoubleParameter(parameters, ParameterNames.FALSE_NORTHING, geoKeys, FALSE_NORTHING_KEY);
final LinearUnit linearUnit = getLinearUnit(geoKeys);
final ProjectedCoordinateSystem coordinateSystem = new ProjectedCoordinateSystem(coordinateSystemId, name, geographicCoordinateSystem, coordinateOperationMethod, parameters, linearUnit);
final CoordinateSystem epsgCoordinateSystem = EpsgCoordinateSystems.getCoordinateSystem(coordinateSystem);
geometryFactory = GeometryFactory.floating2d(epsgCoordinateSystem.getCoordinateSystemId());
}
}
} else {
geometryFactory = GeometryFactory.floating2d(coordinateSystemId);
}
if (geometryFactory != null) {
setGeometryFactory(geometryFactory);
}
final XTIFFField tiePoints = directory.getField(XTIFF.TIFFTAG_GEO_TIEPOINTS);
if (tiePoints == null) {
final XTIFFField geoTransform = directory.getField(XTIFF.TIFFTAG_GEO_TRANS_MATRIX);
if (geoTransform == null) {
return false;
} else {
final double x1 = geoTransform.getAsDouble(3);
final double y1 = geoTransform.getAsDouble(7);
final double pixelWidth = geoTransform.getAsDouble(0);
final double pixelHeight = geoTransform.getAsDouble(5);
final double xRotation = geoTransform.getAsDouble(4);
final double yRotation = geoTransform.getAsDouble(1);
setResolution(pixelWidth);
// TODO rotation
setBoundingBox(x1, y1, pixelWidth, pixelHeight);
return true;
}
} else {
final XTIFFField pixelScale = directory.getField(XTIFF.TIFFTAG_GEO_PIXEL_SCALE);
if (pixelScale == null) {
return false;
} else {
final double rasterXOffset = tiePoints.getAsDouble(0);
final double rasterYOffset = tiePoints.getAsDouble(1);
if (rasterXOffset != 0 && rasterYOffset != 0) {
// These should be 0, not sure what to do if they are not
throw new IllegalArgumentException("Exepectig 0 for the raster x,y tie points in a GeoTIFF");
}
// double rasterZOffset = fieldModelTiePoints.getAsDouble(2);
// setTopLeftRasterPoint(new PointDouble(
// rasterXOffset,
// rasterYOffset));
// Top left corner of image in model coordinates
final double x1 = tiePoints.getAsDouble(3);
final double y1 = tiePoints.getAsDouble(4);
// double modelZOffset = fieldModelTiePoints.getAsDouble(5);
// setTopLeftModelPoint(new PointDouble(
// modelXOffset,
// modelYOffset));
final double pixelWidth = pixelScale.getAsDouble(0);
final double pixelHeight = pixelScale.getAsDouble(1);
setResolution(pixelWidth);
setBoundingBox(x1, y1, pixelWidth, -pixelHeight);
return true;
}
}
}
use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.
the class BoundingBoxTest method assertBoundingBox.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void assertBoundingBox(final Geometry geometry, final BoundingBox boundingBox, final GeometryFactory geometryFactory, final boolean empty, final int axisCount, final double... bounds) {
Assert.assertEquals("Geometry Factory", geometryFactory, boundingBox.getGeometryFactory());
Assert.assertEquals("Empty", empty, boundingBox.isEmpty());
Assert.assertEquals("Axis Count", axisCount, boundingBox.getAxisCount());
Assert.assertEquals("Bounds", Lists.newArray(bounds), Lists.newArray(boundingBox.getMinMaxValues()));
Unit unit = Units.METRE;
Unit lengthUnit = Units.METRE;
final StringBuilder wkt = new StringBuilder();
final int srid = boundingBox.getCoordinateSystemId();
if (geometryFactory == GeometryFactory.DEFAULT_3D) {
Assert.assertEquals("coordinateSystem", null, boundingBox.getCoordinateSystem());
Assert.assertEquals("srid", 0, srid);
} else {
if (srid > 0) {
wkt.append("SRID=");
wkt.append(srid);
wkt.append(";");
}
Assert.assertEquals("srid", geometryFactory.getCoordinateSystemId(), srid);
final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
Assert.assertEquals("coordinateSystem", coordinateSystem, boundingBox.getCoordinateSystem());
if (coordinateSystem != null) {
unit = coordinateSystem.getUnit();
lengthUnit = coordinateSystem.getLengthUnit();
}
}
wkt.append("BBOX");
assertMinMax(boundingBox, -1, Double.NaN, Double.NaN);
assertMinMax(boundingBox, axisCount + 1, Double.NaN, Double.NaN);
double width = 0;
double height = 0;
double minX = Double.NaN;
double maxX = Double.NaN;
double minY = Double.NaN;
double maxY = Double.NaN;
double area = 0;
if (bounds == null) {
wkt.append(" EMPTY");
} else {
minX = bounds[0];
maxX = bounds[axisCount];
if (axisCount > 1) {
minY = bounds[1];
maxY = bounds[axisCount + 1];
width = Math.abs(maxX - minX);
height = Math.abs(maxY - minY);
area = width * height;
} else {
area = 0;
}
if (axisCount == 3) {
wkt.append(" Z");
} else if (axisCount == 4) {
wkt.append(" ZM");
} else if (axisCount != 2) {
wkt.append(" ");
wkt.append(axisCount);
}
wkt.append("(");
for (int axisIndex = 0; axisIndex < axisCount; axisIndex++) {
if (axisIndex > 0) {
wkt.append(',');
}
wkt.append(Doubles.toString(bounds[axisIndex]));
}
wkt.append(' ');
for (int axisIndex = 0; axisIndex < axisCount; axisIndex++) {
if (axisIndex > 0) {
wkt.append(',');
}
wkt.append(Doubles.toString(bounds[axisCount + axisIndex]));
}
wkt.append(')');
for (int i = 0; i < axisCount; i++) {
assertMinMax(boundingBox, i, bounds[i], bounds[axisCount + i]);
Assert.assertEquals("Minimum " + i, Quantities.getQuantity(bounds[i], unit), boundingBox.getMinimum(i));
Assert.assertEquals("Maximum" + i, Quantities.getQuantity(bounds[axisCount + i], unit), boundingBox.getMaximum(i));
Assert.assertEquals("Minimum " + i, bounds[i], boundingBox.getMinimum(i, unit), 0);
Assert.assertEquals("Maximum " + i, bounds[axisCount + i], boundingBox.getMaximum(i, unit), 0);
}
}
Assert.assertEquals("MinX", minX, boundingBox.getMinX(), 0);
Assert.assertEquals("MaxX", maxX, boundingBox.getMaxX(), 0);
if (!boundingBox.isEmpty()) {
Assert.assertEquals("MinimumX", Quantities.getQuantity(minX, unit), boundingBox.getMinimum(0));
Assert.assertEquals("MaximumX", Quantities.getQuantity(maxX, unit), boundingBox.getMaximum(0));
Assert.assertEquals("MinimumX", minX, boundingBox.getMinimum(0, unit), 0);
Assert.assertEquals("MaximumX", maxX, boundingBox.getMaximum(0, unit), 0);
Assert.assertEquals("MinimumY", Quantities.getQuantity(minY, unit), boundingBox.getMinimum(1));
Assert.assertEquals("MaximumY", Quantities.getQuantity(maxY, unit), boundingBox.getMaximum(1));
Assert.assertEquals("MinimumY", minY, boundingBox.getMinimum(1, unit), 0);
Assert.assertEquals("MaximumY", maxY, boundingBox.getMaximum(1, unit), 0);
}
Assert.assertEquals("MinY", minY, boundingBox.getMinY(), 0);
Assert.assertEquals("MaxY", maxY, boundingBox.getMaxY(), 0);
Assert.assertEquals("WKT", wkt.toString(), boundingBox.toString());
Assert.assertEquals("Area", area, boundingBox.getArea(), 0);
Assert.assertEquals("Width", width, boundingBox.getWidth(), 0);
Assert.assertEquals("Width", width, QuantityType.doubleValue(boundingBox.getWidthLength(), lengthUnit), 0);
Assert.assertEquals("Width", Quantities.getQuantity(width, lengthUnit), boundingBox.getWidthLength());
Assert.assertEquals("Height", height, boundingBox.getHeight(), 0);
Assert.assertEquals("Height", height, QuantityType.doubleValue(boundingBox.getHeightLength(), lengthUnit), 0);
Assert.assertEquals("Height", Quantities.getQuantity(height, lengthUnit), boundingBox.getHeightLength());
Assert.assertEquals("Aspect Ratio", width / height, boundingBox.getAspectRatio(), 0);
if (geometry != null) {
if (geometry.isEmpty()) {
final boolean intersects = geometry.intersects(boundingBox);
Assert.assertFalse("Bounding Box Intersects Empty", intersects);
} else {
final boolean intersects = geometry.intersects(boundingBox);
Assert.assertTrue("Bounding Box Intersects", intersects);
// Test outside
Assert.assertFalse("Bounding Box Intersects", geometry.intersects(boundingBox.move(-100, -100)));
Assert.assertFalse("Bounding Box Intersects", geometry.intersects(boundingBox.move(-100, 0)));
Assert.assertFalse("Bounding Box Intersects", geometry.intersects(boundingBox.move(-100, 100)));
Assert.assertFalse("Bounding Box Intersects", geometry.intersects(boundingBox.move(0, -100)));
Assert.assertFalse("Bounding Box Intersects", geometry.intersects(boundingBox.move(0, 100)));
Assert.assertFalse("Bounding Box Intersects", geometry.intersects(boundingBox.move(100, -100)));
Assert.assertFalse("Bounding Box Intersects", geometry.intersects(boundingBox.move(100, 0)));
Assert.assertFalse("Bounding Box Intersects", geometry.intersects(boundingBox.move(100, 100)));
}
}
}
Aggregations