Search in sources :

Example 21 with CoordinateSystem

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

the class RectangularMapGrid method getMapTileName.

default String getMapTileName(final Geometry geometry) {
    final CoordinateSystem coordinateSystem = getCoordinateSystem();
    final Geometry projectedGeometry = geometry.convertGeometry(coordinateSystem.getGeometryFactory());
    final Point centroid = projectedGeometry.getCentroid();
    final Point coordinate = centroid.getPoint();
    final String mapsheet = getMapTileName(coordinate.getX(), coordinate.getY());
    return mapsheet;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) Point(com.revolsys.geometry.model.Point)

Example 22 with CoordinateSystem

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

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

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

the class FixedScaleZoomMode method getBoundingBox.

/**
 * Get the best bounding box matching the zoom mode policy
 * <ul>
 * <li>If the coordinate system for the bounding box wasn't specified it will
 * be set to the coordinate system of the viewport.</li>
 * <li>The bounding box will be converted to the coordinate system of the
 * viewport.</li>
 * </ul>
 *
 * @param viewport The viewport.
 * @param boundingBox The bounding box.
 * @return The bounding box.
 */
@Override
public BoundingBox getBoundingBox(final ComponentViewport2D viewport, final BoundingBox boundingBox) {
    final double viewAspectRatio = viewport.getViewAspectRatio();
    if (!Double.isNaN(viewAspectRatio) && !boundingBox.isEmpty()) {
        final GeometryFactory geometryFactory = viewport.getGeometryFactory();
        final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
        final BoundingBox areaBoundingBox = coordinateSystem.getAreaBoundingBox();
        final GeometryFactory bboxGeometryFactory = boundingBox.getGeometryFactory();
        BoundingBox newBoundingBox = boundingBox;
        if (bboxGeometryFactory == null) {
            newBoundingBox = boundingBox.convert(geometryFactory);
        } else {
            if (bboxGeometryFactory.equals(geometryFactory)) {
                newBoundingBox = boundingBox;
            } else {
                newBoundingBox = boundingBox.convert(geometryFactory);
            }
        }
        double maxScale = viewport.getMaxScale();
        maxScale = getScale(maxScale, false);
        double scale = getScale(viewport, newBoundingBox);
        if (!Double.isNaN(scale)) {
            scale = getScale(scale, false);
            if (scale > maxScale) {
                scale = maxScale;
            }
            final double x = newBoundingBox.getCentreX();
            final double y = newBoundingBox.getCentreY();
            final BoundingBox boundingBox2 = viewport.getBoundingBox(x, y, scale);
            // y2);
            return boundingBox2;
        }
        return newBoundingBox;
    }
    return boundingBox;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 25 with CoordinateSystem

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

the class ComponentViewport2D method setGeometryFactoryPreEvent.

@Override
protected void setGeometryFactoryPreEvent(final GeometryFactory geometryFactory) {
    final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
    if (coordinateSystem != null) {
        final BoundingBox areaBoundingBox = coordinateSystem.getAreaBoundingBox();
        final double minX = areaBoundingBox.getMinX();
        final double maxX = areaBoundingBox.getMaxX();
        final double minY = areaBoundingBox.getMinY();
        final double maxY = areaBoundingBox.getMaxY();
        final double logMinX = Math.log10(Math.abs(minX));
        final double logMinY = Math.log10(Math.abs(minY));
        final double logMaxX = Math.log10(Math.abs(maxX));
        final double logMaxY = Math.log10(Math.abs(maxY));
        final double maxLog = Math.abs(Math.max(Math.max(logMinX, logMinY), Math.max(logMaxX, logMaxY)));
        this.maxIntegerDigits = (int) Math.floor(maxLog + 1);
        this.maxDecimalDigits = 15 - this.maxIntegerDigits;
        final BoundingBox boundingBox = getBoundingBox();
        if (Property.hasValue(boundingBox)) {
            final BoundingBox newBoundingBox = boundingBox.convert(geometryFactory);
            BoundingBox intersection = newBoundingBox.intersection(areaBoundingBox);
            if (intersection.isEmpty()) {
                intersection = areaBoundingBox;
            }
            setBoundingBox(intersection);
        }
    }
}
Also used : CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) BoundingBox(com.revolsys.geometry.model.BoundingBox)

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