Search in sources :

Example 11 with GeographicCoordinateSystem

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

the class GeoNamesService method getNames.

public List<Record> getNames(final BoundingBox boundingBox) {
    final GeometryFactory geometryFactory = GeometryFactory.floating3d(4326);
    final GeographicCoordinateSystem cs = (GeographicCoordinateSystem) geometryFactory.getCoordinateSystem();
    final BoundingBox geographicBoundingBox = boundingBox.convert(geometryFactory);
    final Map<String, Object> params = new HashMap<>();
    final double radius = cs.getDatum().getEllipsoid().getSemiMajorAxis();
    final double height = geographicBoundingBox.getHeight();
    final double width = geographicBoundingBox.getWidth();
    final double diagonal = Math.sqrt(width * width + height * height);
    final double radiusKm = cs.getUnit().getConverterTo(SI.RADIAN).convert(diagonal) * radius / 1000;
    params.put("lat", geographicBoundingBox.getCentreY());
    params.put("lng", geographicBoundingBox.getCentreY());
    params.put("radius", radiusKm);
    params.put("maxRows", "50");
    final String searchUrlString = UrlUtil.getUrl(this.findNearbyBoundingBoxJsonUrl, params);
    try {
        final URL searchUrl = new URL(searchUrlString);
        final Map<String, Object> result = JsonParser.getMap(searchUrl.openStream());
        return mapToObjects(NAME_RECORD_DEFINITION, result);
    } catch (final IOException e) {
        throw new IllegalArgumentException("Unable to connect to URL:" + searchUrlString);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) HashMap(java.util.HashMap) BoundingBox(com.revolsys.geometry.model.BoundingBox) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) IOException(java.io.IOException) URL(java.net.URL)

Example 12 with GeographicCoordinateSystem

use of com.revolsys.geometry.cs.GeographicCoordinateSystem 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 13 with GeographicCoordinateSystem

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

the class Viewport2D method toModelValue.

public double toModelValue(final Quantity<Length> value) {
    double convertedValue;
    final Unit<Length> unit = value.getUnit();
    if (unit.equals(CustomUnits.PIXEL)) {
        convertedValue = QuantityType.doubleValue(value, CustomUnits.PIXEL);
        final double modelUnitsPerViewUnit = getModelUnitsPerViewUnit();
        convertedValue *= modelUnitsPerViewUnit;
    } else {
        convertedValue = QuantityType.doubleValue(value, Units.METRE);
        final CoordinateSystem coordinateSystem = this.geometryFactory2d.getCoordinateSystem();
        if (coordinateSystem instanceof GeographicCoordinateSystem) {
            final GeographicCoordinateSystem geoCs = (GeographicCoordinateSystem) coordinateSystem;
            final double radius = geoCs.getDatum().getEllipsoid().getSemiMajorAxis();
            convertedValue = Math.toDegrees(convertedValue / radius);
        }
    }
    return convertedValue;
}
Also used : Length(javax.measure.quantity.Length) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem)

Example 14 with GeographicCoordinateSystem

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

Example 15 with GeographicCoordinateSystem

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

the class EpsgCoordinateSystems method newCoordinateSystemProjected.

private static ProjectedCoordinateSystem newCoordinateSystemProjected(final int id, final String name, final Area area, final CoordinateSystem sourceCoordinateSystem, final CoordinateOperation operation, final List<Axis> axis, final boolean deprecated) {
    final EpsgAuthority authority = new EpsgAuthority(id);
    final LinearUnit linearUnit = (LinearUnit) axis.get(0).getUnit();
    final CoordinateOperationMethod method = operation.getMethod();
    final Map<ParameterName, ParameterValue> parameterValues = operation.getParameterValues();
    if (sourceCoordinateSystem instanceof GeographicCoordinateSystem) {
        final GeographicCoordinateSystem geographicCoordinateSystem = (GeographicCoordinateSystem) sourceCoordinateSystem;
        return new ProjectedCoordinateSystem(id, name, geographicCoordinateSystem, area, method, parameterValues, linearUnit, axis, authority, deprecated);
    } else if (!Arrays.asList(5819, 5820, 5821).contains(id)) {
        Logs.error(EpsgCoordinateSystems.class, id + " " + name + " has a projected coordinate system");
        return null;
    } else {
        return null;
    }
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValue(com.revolsys.geometry.cs.ParameterValue) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) ParameterName(com.revolsys.geometry.cs.ParameterName) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem)

Aggregations

GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)28 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)19 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)13 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)9 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)8 Map (java.util.Map)7 ParameterName (com.revolsys.geometry.cs.ParameterName)5 BoundingBox (com.revolsys.geometry.model.BoundingBox)5 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 Authority (com.revolsys.geometry.cs.Authority)4 ParameterValue (com.revolsys.geometry.cs.ParameterValue)4 VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)4 GeodeticDatum (com.revolsys.geometry.cs.datum.GeodeticDatum)4 IOException (java.io.IOException)4 CompoundCoordinateSystem (com.revolsys.geometry.cs.CompoundCoordinateSystem)3 EngineeringCoordinateSystem (com.revolsys.geometry.cs.EngineeringCoordinateSystem)3 GeocentricCoordinateSystem (com.revolsys.geometry.cs.GeocentricCoordinateSystem)3 PrimeMeridian (com.revolsys.geometry.cs.PrimeMeridian)3