Search in sources :

Example 11 with ProjectedCoordinateSystem

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

the class LinearRing method getPolygonArea.

default double getPolygonArea(final Unit<Area> unit) {
    double area = 0;
    final CoordinateSystem coordinateSystem = getCoordinateSystem();
    if (coordinateSystem instanceof GeographicCoordinateSystem) {
        // TODO better algorithm than converting to world mercator
        final GeometryFactory geometryFactory = GeometryFactory.worldMercator();
        final LinearRing ring = as2d(geometryFactory);
        return ring.getPolygonArea(unit);
    } else if (coordinateSystem instanceof ProjectedCoordinateSystem) {
        final ProjectedCoordinateSystem projectedCoordinateSystem = (ProjectedCoordinateSystem) coordinateSystem;
        final Unit<Length> lengthUnit = projectedCoordinateSystem.getLengthUnit();
        @SuppressWarnings("unchecked") final Unit<Area> areaUnit = (Unit<Area>) lengthUnit.multiply(lengthUnit);
        area = getPolygonArea();
        final Quantity<Area> areaMeasure = Quantities.getQuantity(area, areaUnit);
        area = QuantityType.doubleValue(areaMeasure, unit);
    } else {
        area = getPolygonArea();
    }
    return area;
}
Also used : Area(javax.measure.quantity.Area) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) Quantity(javax.measure.Quantity) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) PreparedLinearRing(com.revolsys.geometry.model.prep.PreparedLinearRing) Unit(javax.measure.Unit)

Example 12 with ProjectedCoordinateSystem

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

the class WikipediaBoundingBoxLayerWorker method handleBackground.

@Override
protected List<LayerRecord> handleBackground() {
    BoundingBox boundingBox = this.boundingBox;
    GeometryFactory geometryFactory = this.geometryFactory;
    final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
    if (coordinateSystem instanceof ProjectedCoordinateSystem) {
        final ProjectedCoordinateSystem projCs = (ProjectedCoordinateSystem) coordinateSystem;
        geometryFactory = projCs.getGeographicCoordinateSystem().getGeometryFactory();
        boundingBox = boundingBox.convert(geometryFactory);
    }
    final List<LayerRecord> results = (List) this.geoNamesService.getWikipediaArticles(boundingBox);
    for (final Record record : results) {
        final String title = record.getValue("title");
        final String wikipediaUrl = record.getValue("wikipediaUrl");
        final String thumbnailImage = record.getValue("thumbnailImg");
        final Point point = record.getGeometry();
        String text;
        if (thumbnailImage != null) {
            text = "<html><b>" + title + "</b><br /><img src=\"" + thumbnailImage + "\" /><br /></html>";
        } else {
            text = "<html><b>" + title + "</b><br /></html>";
        }
    // if (viewport instanceof ComponentViewport2D) {
    // final ComponentViewport2D componentViewport =
    // (ComponentViewport2D)viewport;
    // componentViewport.addHotSpot(geometryFactory, point, text, "http://"
    // + wikipediaUrl);
    // }
    }
    return results;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) BoundingBox(com.revolsys.geometry.model.BoundingBox) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) List(java.util.List) Record(com.revolsys.record.Record) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) Point(com.revolsys.geometry.model.Point)

Example 13 with ProjectedCoordinateSystem

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

the class MeasureOverlay method setMeasureGeometry.

public void setMeasureGeometry(Geometry measureGeometry) {
    if (measureGeometry == null) {
        measureGeometry = EMPTY_GEOMETRY;
    }
    if (measureGeometry != this.measureGeometry) {
        this.measureGeometry = measureGeometry;
        if (measureGeometry == null) {
            this.measureLabel = "";
        } else {
            Unit<Length> lengthUnit = Units.METRE;
            final CoordinateSystem coordinateSystem = measureGeometry.getCoordinateSystem();
            if (coordinateSystem instanceof ProjectedCoordinateSystem) {
                lengthUnit = coordinateSystem.getLengthUnit();
            }
            final double length = measureGeometry.getLength(lengthUnit);
            @SuppressWarnings("unchecked") final Unit<Area> areaUnit = (Unit<Area>) lengthUnit.multiply(lengthUnit);
            final double area = measureGeometry.getArea(areaUnit);
            final String unitString = lengthUnit.toString();
            synchronized (MEASURE_FORMAT) {
                final StringBuilder label = new StringBuilder();
                final String lengthString = MEASURE_FORMAT.format(Doubles.makePrecise(100, length));
                label.append(lengthString);
                label.append(unitString);
                if (this.measureDataType == DataTypes.POLYGON && measureGeometry instanceof Polygon) {
                    final String areaString = MEASURE_FORMAT.format(Doubles.makePrecise(100, area));
                    label.append(" \n");
                    label.append(areaString);
                    label.append(unitString);
                    label.append('\u00B2');
                }
                this.measureLabel = label.toString();
            }
        }
        setXorGeometry(null);
    }
}
Also used : Area(javax.measure.quantity.Area) Length(javax.measure.quantity.Length) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) LineString(com.revolsys.geometry.model.LineString) Unit(javax.measure.Unit) Polygon(com.revolsys.geometry.model.Polygon)

Example 14 with ProjectedCoordinateSystem

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

the class GeoNamesBoundingBoxLayerWorker method handleBackground.

@Override
protected List<LayerRecord> handleBackground() {
    BoundingBox boundingBox = this.boundingBox;
    GeometryFactory geometryFactory = this.geometryFactory;
    final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
    if (coordinateSystem instanceof ProjectedCoordinateSystem) {
        final ProjectedCoordinateSystem projCs = (ProjectedCoordinateSystem) coordinateSystem;
        final GeographicCoordinateSystem geoCs = projCs.getGeographicCoordinateSystem();
        geometryFactory = geoCs.getGeometryFactory();
        boundingBox = boundingBox.convert(geometryFactory);
    }
    final List<LayerRecord> results = (List) this.geoNamesService.getNames(boundingBox);
    for (final Record record : results) {
        final String name = record.getValue("name");
        final Point point = record.getGeometry();
        final String text = "<html><b>" + name + "</b><br /></html>";
    // if (viewport instanceof ComponentViewport2D) {
    // final ComponentViewport2D componentViewport =
    // (ComponentViewport2D)viewport;
    // componentViewport.addHotSpot(geometryFactory, point, text, null);
    // }
    }
    return results;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) BoundingBox(com.revolsys.geometry.model.BoundingBox) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) List(java.util.List) Record(com.revolsys.record.Record) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) Point(com.revolsys.geometry.model.Point)

Example 15 with ProjectedCoordinateSystem

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

the class EpsgCoordinateSystems method getCoordinateSystem.

public static synchronized CoordinateSystem getCoordinateSystem(final CoordinateSystem coordinateSystem) {
    initialize();
    if (coordinateSystem == null) {
        return null;
    } else {
        int srid = coordinateSystem.getCoordinateSystemId();
        CoordinateSystem matchedCoordinateSystem = coordinateSystemsById.get(srid);
        if (matchedCoordinateSystem == null) {
            matchedCoordinateSystem = coordinateSystemsByName.get(coordinateSystem.getCoordinateSystemName());
            if (matchedCoordinateSystem == null) {
                final int hashCode = coordinateSystem.hashCode();
                int matchCoordinateSystemId = 0;
                final List<CoordinateSystem> coordinateSystems = coordinateSystemsByCoordinateSystem.get(hashCode);
                if (coordinateSystems != null) {
                    for (final CoordinateSystem coordinateSystem3 : coordinateSystems) {
                        if (coordinateSystem3.equals(coordinateSystem)) {
                            final int srid3 = coordinateSystem3.getCoordinateSystemId();
                            if (matchedCoordinateSystem == null) {
                                matchedCoordinateSystem = coordinateSystem3;
                                matchCoordinateSystemId = srid3;
                            } else if (srid3 < matchCoordinateSystemId) {
                                if (!coordinateSystem3.isDeprecated() || matchedCoordinateSystem.isDeprecated()) {
                                    matchedCoordinateSystem = coordinateSystem3;
                                    matchCoordinateSystemId = srid3;
                                }
                            }
                        }
                    }
                }
                if (matchedCoordinateSystem == null) {
                    if (srid <= 0) {
                        srid = nextSrid++;
                    }
                    final String name = coordinateSystem.getCoordinateSystemName();
                    final List<Axis> axis = coordinateSystem.getAxis();
                    final Area area = coordinateSystem.getArea();
                    final Authority authority = coordinateSystem.getAuthority();
                    final boolean deprecated = coordinateSystem.isDeprecated();
                    if (coordinateSystem instanceof GeographicCoordinateSystem) {
                        final GeographicCoordinateSystem geographicCs = (GeographicCoordinateSystem) coordinateSystem;
                        final GeodeticDatum geodeticDatum = geographicCs.getDatum();
                        final PrimeMeridian primeMeridian = geographicCs.getPrimeMeridian();
                        final CoordinateSystem sourceCoordinateSystem = geographicCs.getSourceCoordinateSystem();
                        final CoordinateOperation coordinateOperation = geographicCs.getCoordinateOperation();
                        final GeographicCoordinateSystem newCs = new GeographicCoordinateSystem(srid, name, geodeticDatum, primeMeridian, axis, area, sourceCoordinateSystem, coordinateOperation, deprecated);
                        addCoordinateSystem(newCs);
                        return newCs;
                    } else if (coordinateSystem instanceof ProjectedCoordinateSystem) {
                        final ProjectedCoordinateSystem projectedCs = (ProjectedCoordinateSystem) coordinateSystem;
                        GeographicCoordinateSystem geographicCs = projectedCs.getGeographicCoordinateSystem();
                        geographicCs = (GeographicCoordinateSystem) getCoordinateSystem(geographicCs);
                        final CoordinateOperationMethod coordinateOperationMethod = projectedCs.getCoordinateOperationMethod();
                        final Map<ParameterName, ParameterValue> parameters = projectedCs.getParameterValues();
                        final LinearUnit linearUnit = projectedCs.getLinearUnit();
                        final ProjectedCoordinateSystem newCs = new ProjectedCoordinateSystem(srid, name, geographicCs, area, coordinateOperationMethod, parameters, linearUnit, axis, authority, deprecated);
                        addCoordinateSystem(newCs);
                        return newCs;
                    }
                    return coordinateSystem;
                }
            }
        }
        return matchedCoordinateSystem;
    }
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) Authority(com.revolsys.geometry.cs.Authority) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) GeocentricCoordinateSystem(com.revolsys.geometry.cs.GeocentricCoordinateSystem) CompoundCoordinateSystem(com.revolsys.geometry.cs.CompoundCoordinateSystem) VerticalCoordinateSystem(com.revolsys.geometry.cs.VerticalCoordinateSystem) EngineeringCoordinateSystem(com.revolsys.geometry.cs.EngineeringCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeodeticDatum(com.revolsys.geometry.cs.datum.GeodeticDatum) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString) PrimeMeridian(com.revolsys.geometry.cs.PrimeMeridian) Area(com.revolsys.geometry.cs.Area) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) Map(java.util.Map) IntHashMap(com.revolsys.collection.map.IntHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Axis(com.revolsys.geometry.cs.Axis)

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