Search in sources :

Example 31 with CoordinateSystem

use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.

the class GeometryFactory method writeWktCs.

private boolean writeWktCs(final Writer writer, final int indentLevel) {
    final CoordinateSystem coordinateSystem = getCoordinateSystem();
    if (coordinateSystem == null) {
        return false;
    } else {
        final int coordinateSystemId = getCoordinateSystemId();
        final CoordinateSystem esriCoordinateSystem = EsriCoordinateSystems.getCoordinateSystem(coordinateSystemId);
        if (esriCoordinateSystem == null) {
            EsriCsWktWriter.write(writer, coordinateSystem, indentLevel);
        } else {
            EsriCsWktWriter.write(writer, esriCoordinateSystem, indentLevel);
        }
        return true;
    }
}
Also used : ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) AbstractPoint(com.revolsys.geometry.model.impl.AbstractPoint)

Example 32 with CoordinateSystem

use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.

the class BoundingBox method clipToCoordinateSystem.

/**
 * If the coordinate system is a projected coordinate system then clip to the {@link CoordinateSystem#getAreaBoundingBox()}.
 */
default BoundingBox clipToCoordinateSystem() {
    final GeometryFactory geometryFactory = getGeometryFactory();
    final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
    if (coordinateSystem == null || coordinateSystem instanceof GeographicCoordinateSystem) {
        return this;
    } else {
        final BoundingBox areaBoundingBox = coordinateSystem.getAreaBoundingBox();
        return intersection(areaBoundingBox);
    }
}
Also used : BoundingBoxDoubleXYGeometryFactory(com.revolsys.geometry.model.impl.BoundingBoxDoubleXYGeometryFactory) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem)

Example 33 with CoordinateSystem

use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.

the class BoundingBox method toPolygon.

default Polygon toPolygon(GeometryFactory geometryFactory, int numX, int numY) {
    if (isEmpty()) {
        return geometryFactory.polygon();
    } else {
        final GeometryFactory factory = getGeometryFactory();
        if (geometryFactory == null) {
            if (factory == null) {
                geometryFactory = GeometryFactory.floating2d(0);
            } else {
                geometryFactory = factory;
            }
        }
        try {
            double minStep = 0.00001;
            final CoordinateSystem coordinateSystem = factory.getCoordinateSystem();
            if (coordinateSystem instanceof ProjectedCoordinateSystem) {
                minStep = 1;
            } else {
                minStep = 0.00001;
            }
            double xStep;
            final double width = getWidth();
            if (!Double.isFinite(width)) {
                return geometryFactory.polygon();
            } else if (numX <= 1) {
                numX = 1;
                xStep = width;
            } else {
                xStep = width / numX;
                if (xStep < minStep) {
                    xStep = minStep;
                }
                numX = Math.max(1, (int) Math.ceil(width / xStep));
            }
            double yStep;
            if (numY <= 1) {
                numY = 1;
                yStep = getHeight();
            } else {
                yStep = getHeight() / numY;
                if (yStep < minStep) {
                    yStep = minStep;
                }
                numY = Math.max(1, (int) Math.ceil(getHeight() / yStep));
            }
            final double minX = getMinX();
            final double maxX = getMaxX();
            final double minY = getMinY();
            final double maxY = getMaxY();
            final int coordinateCount = 1 + 2 * (numX + numY);
            final double[] coordinates = new double[coordinateCount * 2];
            int i = 0;
            coordinates[i++] = maxX;
            coordinates[i++] = minY;
            for (int j = 0; j < numX - 1; j++) {
                final double x = maxX - j * xStep;
                coordinates[i++] = x;
                coordinates[i++] = minY;
            }
            coordinates[i++] = minX;
            coordinates[i++] = minY;
            for (int j = 0; j < numY - 1; j++) {
                final double y = minY + j * yStep;
                coordinates[i++] = minX;
                coordinates[i++] = y;
            }
            coordinates[i++] = minX;
            coordinates[i++] = maxY;
            for (int j = 0; j < numX - 1; j++) {
                final double x = minX + j * xStep;
                coordinates[i++] = x;
                coordinates[i++] = maxY;
            }
            coordinates[i++] = maxX;
            coordinates[i++] = maxY;
            for (int j = 0; j < numY - 1; j++) {
                final double y = minY + (numY - j) * yStep;
                coordinates[i++] = maxX;
                coordinates[i++] = y;
            }
            coordinates[i++] = maxX;
            coordinates[i++] = minY;
            final LinearRing ring = factory.linearRing(2, coordinates);
            final Polygon polygon = factory.polygon(ring);
            if (geometryFactory == null) {
                return polygon;
            } else {
                return (Polygon) polygon.convertGeometry(geometryFactory);
            }
        } catch (final IllegalArgumentException e) {
            Logs.error(this, "Unable to convert to polygon: " + this, e);
            return geometryFactory.polygon();
        }
    }
}
Also used : BoundingBoxDoubleXYGeometryFactory(com.revolsys.geometry.model.impl.BoundingBoxDoubleXYGeometryFactory) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem)

Example 34 with CoordinateSystem

use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.

the class BoundingBox method intersects.

/**
 *  Check if the region defined by <code>other</code>
 *  overlaps (intersects) the region of this <code>BoundingBox</code>.
 *
 *@param  other  the <code>BoundingBox</code> which this <code>BoundingBox</code> is
 *          being checked for overlapping
 *@return        <code>true</code> if the <code>BoundingBox</code>s overlap
 */
default boolean intersects(final BoundingBox other) {
    if (isEmpty() || other.isEmpty()) {
        return false;
    } else {
        final CoordinateSystem coordinateSystem = getCoordinateSystem();
        final BoundingBox convertedBoundingBox = other.toCoordinateSystem(coordinateSystem, 2);
        return intersectsFast(convertedBoundingBox);
    }
}
Also used : CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem)

Example 35 with CoordinateSystem

use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.

the class MoepBinaryIterator method loadHeader.

private void loadHeader() throws IOException {
    this.fileType = (byte) read();
    if (this.fileType / 100 == 0) {
        this.coordinateBytes = 2;
    } else {
        this.fileType %= 100;
        this.coordinateBytes = 4;
    }
    String mapsheet = readString(11);
    mapsheet = mapsheet.replaceAll("\\.", "").toLowerCase();
    final Bcgs20000RectangularMapGrid bcgsGrid = new Bcgs20000RectangularMapGrid();
    final UtmRectangularMapGrid utmGrid = new UtmRectangularMapGrid();
    final double latitude = bcgsGrid.getLatitude(mapsheet) + 0.05;
    final double longitude = bcgsGrid.getLongitude(mapsheet) - 0.1;
    final int crsId = utmGrid.getNad83Srid(longitude, latitude);
    final CoordinateSystem coordinateSystem = EpsgCoordinateSystems.getCoordinateSystem(crsId);
    final String submissionDateString = readString(6);
    final double centreX = readLEInt(this.in);
    final double centreY = readLEInt(this.in);
    this.center = new PointDoubleXY(centreX, centreY);
    this.factory = GeometryFactory.fixed3d(coordinateSystem.getCoordinateSystemId(), 1.0, 1.0, 1.0);
    setProperty(IoConstants.GEOMETRY_FACTORY, this.factory);
}
Also used : Bcgs20000RectangularMapGrid(com.revolsys.gis.grid.Bcgs20000RectangularMapGrid) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) UtmRectangularMapGrid(com.revolsys.gis.grid.UtmRectangularMapGrid) LineString(com.revolsys.geometry.model.LineString) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) 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