Search in sources :

Example 1 with CoordinateSystem

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

the class UsgsGriddedElevationReader method readHeader.

private void readHeader() {
    try {
        if (readBuffer()) {
            final String fileName = getString(40);
            final String descriptor = getString(40);
            // Blank 81 - 109
            skip(29);
            final String seGeographic = getString(26);
            final String processCode = getString(1);
            // Blank 137
            skip(1);
            final String sectionIndicator = getString(3);
            final String originCode = getString(4);
            final int demLevelCode = getInteger();
            final int elevationPattern = getInteger();
            final int planimetricReferenceSystem = getInteger();
            final int zone = getInteger();
            final double[] projectionParameters = new double[15];
            for (int i = 0; i < projectionParameters.length; i++) {
                projectionParameters[i] = getDoubleSci();
            }
            final int planimetricUom = getInteger();
            final int verticalUom = getInteger();
            this.polygonBounds = getPolygonCoordinates();
            final double min = getDouble24();
            final double max = getDouble24();
            final double angle = getDouble24();
            if (angle != 0) {
                throw new IllegalArgumentException("Angle=" + angle + " not currently supported for USGS DEM: " + this.resource);
            }
            final int verticalAccuracy = getInteger();
            final double resolutionX = getDouble12();
            final double resolutionY = getDouble12();
            if (resolutionX != resolutionY) {
                throw new IllegalArgumentException("resolutionX " + resolutionX + " != " + resolutionY + " resolutionY for USGS DEM: " + this.resource);
            }
            this.resolutionX = (int) resolutionX;
            this.resolutionY = (int) resolutionY;
            if (resolutionX != this.resolutionX) {
                throw new IllegalArgumentException("resolutionX " + resolutionX + " must currently be an integer for USGS DEM: " + this.resource);
            }
            this.resolutionZ = getDouble12();
            this.rasterRowCount = getInteger();
            this.rasterColCount = getInteger();
            final Short largestContourInterval = getShort();
            final Byte largestContourIntervalUnits = getByte();
            final Short smallestContourInterval = getShort();
            final Byte smallest = getByte();
            final Integer sourceYear = getInteger(4);
            final Integer revisionYear = getInteger(4);
            final String inspectionFlag = getString(1);
            final String dataValidationFlag = getString(1);
            final String suspectAndVoidAreaFlag = getString(1);
            final Integer verticalDatum = getInteger(2);
            final Integer horizontalDatum = getInteger(2);
            final Integer dataEdition = getInteger(4);
            final Integer percentVoid = getInteger(4);
            final Integer edgeMatchWest = getInteger(2);
            final Integer edgeMatchNorth = getInteger(2);
            final Integer edgeMatchEast = getInteger(2);
            final Integer edgeMatchSouth = getInteger(2);
            final Double verticalDatumShift = getDouble(7);
            LinearUnit linearUnit = null;
            if (planimetricUom == 1) {
                linearUnit = EpsgCoordinateSystems.getLinearUnit("foot");
            } else if (planimetricUom == 2) {
                linearUnit = EpsgCoordinateSystems.getLinearUnit("metre");
            }
            GeographicCoordinateSystem geographicCoordinateSystem;
            switch(horizontalDatum) {
                case 0:
                    geographicCoordinateSystem = null;
                    break;
                case 1:
                    geographicCoordinateSystem = (GeographicCoordinateSystem) EpsgCoordinateSystems.getCoordinateSystem("NAD27");
                    break;
                case 2:
                    geographicCoordinateSystem = (GeographicCoordinateSystem) EpsgCoordinateSystems.getCoordinateSystem("WGS 72");
                    break;
                case 3:
                    geographicCoordinateSystem = (GeographicCoordinateSystem) EpsgCoordinateSystems.getCoordinateSystem("WGS 84");
                    break;
                case 4:
                    geographicCoordinateSystem = (GeographicCoordinateSystem) EpsgCoordinateSystems.getCoordinateSystem("NAD83");
                    break;
                default:
                    throw new IllegalArgumentException("horizontalDatum=" + horizontalDatum + " not currently supported for USGS DEM: " + this.resource);
            }
            final double scaleZ = 1.0 / this.resolutionZ;
            int coordinateSystemId = 0;
            CoordinateSystem coordinateSystem = null;
            if (0 == planimetricReferenceSystem) {
                coordinateSystemId = geographicCoordinateSystem.getCoordinateSystemId();
            } else if (1 == planimetricReferenceSystem) {
                coordinateSystemId = 26900 + zone;
            } else if (2 == planimetricReferenceSystem) {
                throw new IllegalArgumentException("planimetricReferenceSystem=" + planimetricReferenceSystem + " not currently supported for USGS DEM: " + this.resource);
            } else if (3 == planimetricReferenceSystem) {
                final Map<ParameterName, ParameterValue> parameters = new LinkedHashMap<>();
                parameters.put(ParameterNames.CENTRAL_MERIDIAN, fromDms(projectionParameters[4]));
                parameters.put(ParameterNames.STANDARD_PARALLEL_1, fromDms(projectionParameters[2]));
                parameters.put(ParameterNames.STANDARD_PARALLEL_2, fromDms(projectionParameters[3]));
                parameters.put(ParameterNames.LATITUDE_OF_ORIGIN, fromDms(projectionParameters[5]));
                parameters.put(ParameterNames.FALSE_EASTING, new ParameterValueNumber(projectionParameters[6]));
                parameters.put(ParameterNames.FALSE_NORTHING, new ParameterValueNumber(projectionParameters[7]));
                final CoordinateOperationMethod coordinateOperationMethod = new CoordinateOperationMethod("Albers_Equal_Area");
                final ProjectedCoordinateSystem projectedCoordinateSystem = new ProjectedCoordinateSystem(-1, "", geographicCoordinateSystem, coordinateOperationMethod, parameters, linearUnit);
                final ProjectedCoordinateSystem projectedCoordinateSystem2 = (ProjectedCoordinateSystem) EpsgCoordinateSystems.getCoordinateSystem(projectedCoordinateSystem);
                if (projectedCoordinateSystem2 == projectedCoordinateSystem || projectedCoordinateSystem2 == null) {
                    coordinateSystem = projectedCoordinateSystem2;
                } else {
                    coordinateSystemId = projectedCoordinateSystem2.getCoordinateSystemId();
                }
            } else {
                throw new IllegalArgumentException("planimetricReferenceSystem=" + planimetricReferenceSystem + " not currently supported for USGS DEM: " + this.resource);
            }
            if (coordinateSystemId > 0) {
                this.geometryFactory = GeometryFactory.fixed3d(coordinateSystemId, 0, 0, scaleZ);
            } else if (coordinateSystem == null) {
                throw new IllegalArgumentException("No coordinate system found: " + this.resource);
            } else {
                this.geometryFactory = GeometryFactory.fixed3d(coordinateSystem, 0, 0, scaleZ);
            }
            final Polygon polygon = this.geometryFactory.polygon(this.geometryFactory.linearRing(2, this.polygonBounds));
            this.boundingBox = polygon.getBoundingBox();
        }
    } catch (final Exception e) {
        try {
            close();
        } catch (final Exception e1) {
        }
        throw Exceptions.wrap(e);
    }
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValueNumber(com.revolsys.geometry.cs.ParameterValueNumber) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) IOException(java.io.IOException) NoSuchResourceException(com.revolsys.spring.resource.NoSuchResourceException) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) Polygon(com.revolsys.geometry.model.Polygon) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with CoordinateSystem

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

the class EsriGeodatabaseXmlRecordWriter method writeSpatialReference.

public void writeSpatialReference(final GeometryFactory geometryFactory) {
    if (geometryFactory != null) {
        final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
        if (coordinateSystem != null) {
            final String wkt = geometryFactory.toWktCs();
            this.out.startTag(SPATIAL_REFERENCE);
            if (coordinateSystem instanceof ProjectedCoordinateSystem) {
                this.out.attribute(XsiConstants.TYPE, PROJECTED_COORDINATE_SYSTEM_TYPE);
            } else {
                this.out.attribute(XsiConstants.TYPE, GEOGRAPHIC_COORDINATE_SYSTEM_TYPE);
            }
            this.out.element(WKT, wkt);
            this.out.element(X_ORIGIN, 0);
            this.out.element(Y_ORIGIN, 0);
            final double scaleXy = geometryFactory.getScaleXY();
            this.out.element(XY_SCALE, (int) scaleXy);
            this.out.element(Z_ORIGIN, 0);
            final double scaleZ = geometryFactory.getScaleZ();
            this.out.element(Z_SCALE, (int) scaleZ);
            this.out.element(M_ORIGIN, 0);
            this.out.element(M_SCALE, 1);
            this.out.element(XY_TOLERANCE, Doubles.toString(1.0 / scaleXy * 2.0));
            this.out.element(Z_TOLERANCE, Doubles.toString(1.0 / scaleZ * 2.0));
            this.out.element(M_TOLERANCE, 1);
            this.out.element(HIGH_PRECISION, true);
            this.out.element(WKID, coordinateSystem.getCoordinateSystemId());
            this.out.endTag(SPATIAL_REFERENCE);
        }
    }
}
Also used : CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem)

Example 3 with CoordinateSystem

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

the class GeometryTestUtil method coordinates.

public static double[] coordinates(final GeometryFactory geometryFactory, final double delta) {
    final int axisCount = geometryFactory.getAxisCount();
    final double[] coordinates = new double[axisCount];
    double x;
    double y;
    final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
    if (coordinateSystem == null || geometryFactory.isGeographics()) {
        x = -123.123456;
        y = 52.123456;
    } else {
        final BoundingBox areaBoundingBox = coordinateSystem.getAreaBoundingBox();
        x = Math.round(areaBoundingBox.getCentreX());
        y = Math.round(areaBoundingBox.getCentreY());
    }
    coordinates[0] = x;
    coordinates[1] = y;
    if (axisCount > 2) {
        coordinates[2] = 2.1234567;
    }
    if (axisCount > 3) {
        coordinates[3] = 3.1234567;
    }
    for (int i = 0; i < coordinates.length; i++) {
        coordinates[i] += delta;
    }
    return coordinates;
}
Also used : CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point)

Example 4 with CoordinateSystem

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

the class TestUtil method doTestGeometry.

public static void doTestGeometry(final Class<?> clazz, final String file) {
    boolean valid = true;
    final Resource resource = new ClassPathResource(file, clazz);
    try (Reader<Record> reader = RecordReader.newRecordReader(resource)) {
        int i = 0;
        for (final Record object : reader) {
            final int srid = object.getInteger("srid");
            final int axisCount = object.getInteger("axisCount");
            final double scaleXy = object.getInteger("scaleXy");
            final double scaleZ = object.getInteger("scaleZ");
            final double[] scales = { scaleXy, scaleXy, scaleZ };
            final GeometryFactory geometryFactory = GeometryFactory.fixed(srid, axisCount, scales);
            final String wkt = object.getValue("wkt");
            final Geometry geometry = geometryFactory.geometry(wkt);
            valid &= equalsExpectedWkt(i, object, geometry);
            final CoordinateSystem coordinateSystem = geometry.getCoordinateSystem();
            GeometryFactory otherGeometryFactory;
            if (coordinateSystem instanceof ProjectedCoordinateSystem) {
                final ProjectedCoordinateSystem projectedCoordinateSystem = (ProjectedCoordinateSystem) coordinateSystem;
                otherGeometryFactory = GeometryFactory.fixed(projectedCoordinateSystem.getCoordinateSystemId(), axisCount, scales);
            } else {
                otherGeometryFactory = GeometryFactory.fixed(3005, axisCount, scales);
            }
            final Geometry convertedGeometry = geometry.convertGeometry(otherGeometryFactory);
            final Geometry convertedBackGeometry = convertedGeometry.convertGeometry(geometryFactory);
            valid &= equalsExpectedGeometry(i, convertedBackGeometry, geometry);
            i++;
        }
    }
    if (!valid) {
        Assert.fail("Has Errors");
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ClassPathResource(com.revolsys.spring.resource.ClassPathResource) Resource(com.revolsys.spring.resource.Resource) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) ClassPathResource(com.revolsys.spring.resource.ClassPathResource) Geometry(com.revolsys.geometry.model.Geometry) Record(com.revolsys.record.Record)

Example 5 with CoordinateSystem

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

the class OracleDdlWriter method writeAddGeometryColumn.

public void writeAddGeometryColumn(final RecordDefinition recordDefinition) {
    final PrintWriter out = getOut();
    final String typePath = recordDefinition.getPath();
    String schemaName = JdbcUtils.getSchemaName(typePath);
    if (schemaName.length() == 0) {
        schemaName = "public";
    }
    final String tableName = PathUtil.getName(typePath);
    final FieldDefinition geometryField = recordDefinition.getGeometryField();
    if (geometryField != null) {
        final GeometryFactory geometryFactory = geometryField.getProperty(FieldProperties.GEOMETRY_FACTORY);
        final String name = geometryField.getName();
        String geometryType = "GEOMETRY";
        final DataType dataType = geometryField.getDataType();
        if (dataType == DataTypes.POINT) {
            geometryType = "POINT";
        } else if (dataType == DataTypes.LINE_STRING) {
            geometryType = "LINESTRING";
        } else if (dataType == DataTypes.POLYGON) {
            geometryType = "POLYGON";
        } else if (dataType == DataTypes.MULTI_POINT) {
            geometryType = "MULTIPOINT";
        } else if (dataType == DataTypes.MULTI_LINE_STRING) {
            geometryType = "MULTILINESTRING";
        } else if (dataType == DataTypes.MULTI_POLYGON) {
            geometryType = "MULTIPOLYGON";
        }
        out.print("select addgeometrycolumn('");
        out.print(schemaName.toLowerCase());
        out.print("', '");
        out.print(tableName.toLowerCase());
        out.print("','");
        out.print(name.toLowerCase());
        out.print("',");
        final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
        out.print(coordinateSystem.getCoordinateSystemId());
        out.print(",'");
        out.print(geometryType);
        out.print("', ");
        out.print(geometryFactory.getAxisCount());
        out.println(");");
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) PrintWriter(java.io.PrintWriter)

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