Search in sources :

Example 21 with ProjectedCoordinateSystem

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

the class MapRulerBorder method paintBorder.

@Override
public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
    final Graphics2D graphics = (Graphics2D) g;
    graphics.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10));
    final FontMetrics fontMetrics = graphics.getFontMetrics();
    this.labelHeight = fontMetrics.getHeight();
    paintBackground(graphics, x, y, width, height);
    final BoundingBox boundingBox = this.viewport.getBoundingBox();
    if (this.rulerCoordinateSystem instanceof GeographicCoordinateSystem) {
        final Unit<Angle> displayUnit = NonSI.DEGREE_ANGLE;
        paintRuler(graphics, boundingBox, displayUnit, METRIC_GEOGRAPHICS_STEPS, true, x, y, width, height);
    } else if (this.rulerCoordinateSystem instanceof ProjectedCoordinateSystem) {
        if (this.baseUnit.equals(USCustomary.FOOT)) {
            final Unit<Length> displayUnit = USCustomary.FOOT;
            paintRuler(graphics, boundingBox, displayUnit, IMPERIAL_FOOT_STEPS, true, x, y, width, height);
        } else {
            final Unit<Length> displayUnit = Units.METRE;
            paintRuler(graphics, boundingBox, displayUnit, METRIC_PROJECTED_STEPS, true, x, y, width, height);
        }
    }
    graphics.setColor(Color.BLACK);
    graphics.drawRect(this.rulerSize - 1, this.rulerSize - 1, width - 2 * this.rulerSize + 1, height - 2 * this.rulerSize + 1);
}
Also used : Angle(javax.measure.quantity.Angle) FontMetrics(java.awt.FontMetrics) BoundingBox(com.revolsys.geometry.model.BoundingBox) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) Unit(javax.measure.Unit) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D)

Example 22 with ProjectedCoordinateSystem

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

the class EpsgCoordinateSystemsLoader method validateEsri.

private void validateEsri() {
    EsriCoordinateSystems.getCoordinateSystem(0);
    for (final CoordinateSystem coordinateSytstem : EpsgCoordinateSystems.getCoordinateSystems()) {
        if (coordinateSytstem instanceof GeographicCoordinateSystem) {
            final GeographicCoordinateSystem geoCs = (GeographicCoordinateSystem) coordinateSytstem;
            final int id = coordinateSytstem.getCoordinateSystemId();
            final GeographicCoordinateSystem esri = EsriCoordinateSystems.getCoordinateSystem(id);
            if (esri != null && !geoCs.equalsExact(esri)) {
            // System.out.println(id + coordinateSytstem.getCoordinateSystemName());
            }
        } else if (coordinateSytstem instanceof ProjectedCoordinateSystem) {
            final ProjectedCoordinateSystem projectedCs = (ProjectedCoordinateSystem) coordinateSytstem;
            final int id = coordinateSytstem.getCoordinateSystemId();
            final String wkt = new UrlResource("http://spatialreference.org/ref/epsg/" + id + "/esriwkt/").contentsAsString();
            final ProjectedCoordinateSystem esri = GeometryFactory.floating2d(wkt).getCoordinateSystem();
            final CoordinateOperationMethod coordinateOperationMethod = esri.getCoordinateOperationMethod();
            if (esri != null && !projectedCs.equals(esri) && coordinateOperationMethod != null && Property.hasValue(coordinateOperationMethod.getName()) && !projectedCs.isDeprecated()) {
                final Map<ParameterName, Object> p1 = projectedCs.getParameters();
                final Map<ParameterName, Object> p2 = esri.getParameters();
                final Set<ParameterName> n1 = p1.keySet();
                final Set<ParameterName> n2 = p2.keySet();
                if (!n1.equals(n2)) {
                    final TreeSet<ParameterName> nm1 = new TreeSet<>(n1);
                    nm1.removeAll(n2);
                    final TreeSet<ParameterName> nm2 = new TreeSet<>(n2);
                    nm2.removeAll(n1);
                    final String m = id + "\t" + coordinateSytstem.getCoordinateSystemName() + "\t" + nm1 + "\t" + nm2;
                // System.out.println(m);
                }
            }
        }
    }
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) UrlResource(com.revolsys.spring.resource.UrlResource) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) TreeSet(java.util.TreeSet) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 23 with ProjectedCoordinateSystem

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

the class LineStringTest method assertEquals.

public static void assertEquals(final Point point, final double... coordinates) {
    final GeometryFactory geometryFactory = point.getGeometryFactory();
    final GeometryFactory geometryFactory2;
    final int axisCount = geometryFactory.getAxisCount();
    if (geometryFactory.getCoordinateSystem() instanceof ProjectedCoordinateSystem) {
        final ProjectedCoordinateSystem projectedCs = (ProjectedCoordinateSystem) geometryFactory.getCoordinateSystem();
        final GeographicCoordinateSystem geographicCoordinateSystem = projectedCs.getGeographicCoordinateSystem();
        geometryFactory2 = GeometryFactory.floating(geographicCoordinateSystem.getCoordinateSystemId(), axisCount);
    } else {
        geometryFactory2 = GeometryFactory.floating(26910, axisCount);
    }
    assertCoordinatesEquals(point, coordinates);
    final Point clone = point.newPoint();
    assertCoordinatesEquals(clone, coordinates);
    final Point converted = point.convertGeometry(geometryFactory);
    assertCoordinatesEquals(converted, coordinates);
    Assert.assertSame(point, converted);
    final Point convertedOther = point.convertGeometry(geometryFactory2);
    final Point convertedBack = convertedOther.convertGeometry(geometryFactory);
    assertCoordinatesEquals(convertedBack, coordinates);
    Assert.assertNotSame(point, convertedBack);
    final Point copy = point.newGeometry(geometryFactory);
    assertCoordinatesEquals(copy, coordinates);
    Assert.assertNotSame(point, copy);
    final Point copyOther = point.convertGeometry(geometryFactory2);
    final Point copyBack = copyOther.convertGeometry(geometryFactory);
    assertCoordinatesEquals(copyBack, coordinates);
    Assert.assertNotSame(point, copyBack);
    final String string = point.toString();
    final Point pointString = geometryFactory.geometry(string);
    assertCoordinatesEquals(pointString, coordinates);
    final String wkt = point.toEwkt();
    final Point pointWkt = geometryFactory.geometry(wkt);
    assertCoordinatesEquals(pointWkt, coordinates);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) Point(com.revolsys.geometry.model.Point) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point)

Example 24 with ProjectedCoordinateSystem

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

the class EsriCoordinateSystemsLoader method projected.

private void projected() {
    final Map<ByteArray, Map<Integer, ProjectedCoordinateSystem>> csBymd5 = new LinkedHashMap<>();
    try (RecordReader reader = RecordReader.newRecordReader(this.mainPath + "data/esri/esriProjectedCs.tsv");
        final ChannelWriter writer = ChannelWriter.newChannelWriter(this.mainPath + "resources/CoordinateSystems/esri/Projected.cs")) {
        for (final Record record : reader) {
            final int id = record.getInteger("ID");
            final String wkt = record.getString("WKT");
            final ProjectedCoordinateSystem coordinateSystem = WktCsParser.read(wkt);
            final byte[] digest = coordinateSystem.md5Digest();
            Maps.addToMap(Maps::newTree, csBymd5, new ByteArray(digest), id, coordinateSystem);
            final String csName = coordinateSystem.getCoordinateSystemName();
            final GeographicCoordinateSystem geographicCoordinateSystem = coordinateSystem.getGeographicCoordinateSystem();
            final String geographicCoordinateSystemName = geographicCoordinateSystem.getCoordinateSystemName();
            final int geographicCoordinateSystemId = this.geographicIdByName.getOrDefault(geographicCoordinateSystemName, 0);
            if (geographicCoordinateSystemId == 0) {
                System.out.println(wkt);
            }
            final String projectionName = coordinateSystem.getCoordinateOperationMethod().getName();
            final Map<ParameterName, ParameterValue> parameterValues = coordinateSystem.getParameterValues();
            final LinearUnit linearUnit = coordinateSystem.getLinearUnit();
            final String unitName = linearUnit.getName();
            final double conversionFactor = linearUnit.getConversionFactor();
            writer.putInt(id);
            writer.putStringUtf8ByteCount(csName);
            writer.putInt(geographicCoordinateSystemId);
            writer.putStringUtf8ByteCount(projectionName);
            writeParameters(writer, parameterValues);
            writer.putStringUtf8ByteCount(unitName);
            writer.putDouble(conversionFactor);
        }
    }
    writeDigestFile(csBymd5, "Projected");
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValue(com.revolsys.geometry.cs.ParameterValue) RecordReader(com.revolsys.record.io.RecordReader) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) ParameterName(com.revolsys.geometry.cs.ParameterName) LinkedHashMap(java.util.LinkedHashMap) ChannelWriter(com.revolsys.io.channels.ChannelWriter) Maps(com.revolsys.collection.map.Maps) Record(com.revolsys.record.Record) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 25 with ProjectedCoordinateSystem

use of com.revolsys.geometry.cs.ProjectedCoordinateSystem 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)

Aggregations

ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)25 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)18 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)15 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)7 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)7 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)7 Map (java.util.Map)7 BoundingBox (com.revolsys.geometry.model.BoundingBox)4 Point (com.revolsys.geometry.model.Point)4 Record (com.revolsys.record.Record)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 IntHashMap (com.revolsys.collection.map.IntHashMap)3 ParameterName (com.revolsys.geometry.cs.ParameterName)3 ParameterValue (com.revolsys.geometry.cs.ParameterValue)3 VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TreeMap (java.util.TreeMap)3