Search in sources :

Example 46 with CoordinateSystem

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);
        }
    }
}
Also used : CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 47 with CoordinateSystem

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;
}
Also used : CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem)

Example 48 with CoordinateSystem

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);
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem)

Example 49 with CoordinateSystem

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;
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) XTIFFField(org.libtiff.jai.codec.XTIFFField) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IntHashMap(com.revolsys.collection.map.IntHashMap)

Example 50 with CoordinateSystem

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)));
        }
    }
}
Also used : CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) Unit(javax.measure.Unit) Point(com.revolsys.geometry.model.Point)

Aggregations

CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)51 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)28 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)25 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)14 BoundingBox (com.revolsys.geometry.model.BoundingBox)11 Point (com.revolsys.geometry.model.Point)8 CompoundCoordinateSystem (com.revolsys.geometry.cs.CompoundCoordinateSystem)7 EngineeringCoordinateSystem (com.revolsys.geometry.cs.EngineeringCoordinateSystem)7 GeocentricCoordinateSystem (com.revolsys.geometry.cs.GeocentricCoordinateSystem)7 VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)7 ArrayList (java.util.ArrayList)6 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)5 Map (java.util.Map)5 DataType (com.revolsys.datatype.DataType)4 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)4 Record (com.revolsys.record.Record)4 FieldDefinition (com.revolsys.record.schema.FieldDefinition)4 PrintWriter (java.io.PrintWriter)4 IntHashMap (com.revolsys.collection.map.IntHashMap)3 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)3