Search in sources :

Example 71 with Polygon

use of com.revolsys.geometry.model.Polygon 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 72 with Polygon

use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.

the class GridLayerRenderer method render.

@Override
public void render(final Viewport2D viewport, final Cancellable cancellable, final GridLayer layer) {
    try {
        final double scaleForVisible = viewport.getScaleForVisible();
        if (layer.isVisible(scaleForVisible)) {
            final BoundingBox boundingBox = viewport.getBoundingBox();
            final RectangularMapGrid grid = layer.getGrid();
            final List<RectangularMapTile> tiles = grid.getTiles(boundingBox);
            final Graphics2D graphics = viewport.getGraphics();
            if (graphics != null) {
                final Font font = graphics.getFont();
                for (final RectangularMapTile tile : cancellable.cancellable(tiles)) {
                    final BoundingBox tileBoundingBox = tile.getBoundingBox();
                    final BoundingBox intersectBoundingBox = boundingBox.intersection(tileBoundingBox);
                    if (!intersectBoundingBox.isEmpty()) {
                        final GeometryFactory geometryFactory = viewport.getGeometryFactory();
                        final Polygon polygon = tile.getPolygon(geometryFactory, 50);
                        try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
                            viewport.drawGeometryOutline(polygon, this.geometryStyle);
                        }
                        try (BaseCloseable transformClosable = viewport.setUseModelCoordinates(false)) {
                            viewport.drawText(tile, polygon, this.textStyle);
                        }
                    }
                    graphics.setFont(font);
                }
            }
        }
    } catch (final IllegalArgumentException e) {
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) Polygon(com.revolsys.geometry.model.Polygon) RectangularMapTile(com.revolsys.gis.grid.RectangularMapTile) Font(java.awt.Font) RectangularMapGrid(com.revolsys.gis.grid.RectangularMapGrid) Graphics2D(java.awt.Graphics2D)

Example 73 with Polygon

use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.

the class PointCloudLayerRenderer method render.

@Override
public void render(final Viewport2D viewport, final Cancellable cancellable, final PointCloudLayer layer) {
    // TODO cancellable
    final double scaleForVisible = viewport.getScaleForVisible();
    if (layer.isVisible(scaleForVisible)) {
        if (!layer.isEditable()) {
            final PointCloud<?> pointCloud = layer.getPointCloud();
            if (pointCloud != null) {
                final BoundingBox boundingBox = layer.getBoundingBox();
                final Graphics2D graphics = viewport.getGraphics();
                if (graphics != null) {
                    try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(true)) {
                        final Polygon polygon = boundingBox.toPolygon(0);
                        viewport.drawGeometryOutline(polygon, STYLE_BOUNDING_BOX);
                    }
                }
            }
        }
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) BoundingBox(com.revolsys.geometry.model.BoundingBox) Polygon(com.revolsys.geometry.model.Polygon) Graphics2D(java.awt.Graphics2D)

Example 74 with Polygon

use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.

the class EditGeoreferencedImageOverlay method paintComponent.

@Override
protected void paintComponent(final Viewport2D viewport, final Graphics2D graphics) {
    super.paintComponent(viewport, graphics);
    final GeoreferencedImageLayer layer = this.layer;
    final GeoreferencedImage image = this.image;
    final BoundingBox moveImageBoundingBox = this.moveImageBoundingBox;
    if (layer != null && layer.isVisible() && layer.isExists() && image != null) {
        try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
            final GeometryFactory viewportGeometryFactory = viewport.getGeometryFactory();
            final boolean showOriginalImage = layer.isShowOriginalImage();
            final BoundingBox imageBoundingBox = getImageBoundingBox();
            BoundingBox boundingBox = imageBoundingBox;
            BoundingBox outlineBoundingBox = boundingBox;
            if (moveImageBoundingBox != null) {
                if (showOriginalImage) {
                    boundingBox = moveImageBoundingBox;
                }
                outlineBoundingBox = moveImageBoundingBox;
            }
            final GeoreferencedImage cachedImage = getCachedImage(boundingBox);
            GeoreferencedImageLayerRenderer.renderAlpha(viewport, graphics, cachedImage, false, layer.getOpacity() / 255.0, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            GeoreferencedImageLayerRenderer.renderDifferentCoordinateSystem(viewport, graphics, imageBoundingBox);
            if (outlineBoundingBox != null && !outlineBoundingBox.isEmpty()) {
                final Polygon imageBoundary = outlineBoundingBox.convert(getViewportGeometryFactory()).toPolygon(1);
                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
                viewport.drawGeometryOutline(imageBoundary, STYLE_BOX_OUTLINE);
                MarkerStyleRenderer.renderMarkerVertices(viewport, graphics, imageBoundary, STYLE_BOX_CORNER);
                final List<MappedLocation> tiePoints = image.getTiePoints();
                final int tiePointCount = tiePoints.size();
                final GeometryFactory viewGeometryFactory = getGeometryFactory();
                if (tiePointCount > 0) {
                    for (final MappedLocation mappedLocation : tiePoints) {
                        LineString line = mappedLocation.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
                        if (line != null) {
                            line = line.convertGeometry(viewportGeometryFactory);
                            try (BaseCloseable transformCloseable1 = viewport.setUseModelCoordinates(graphics, true)) {
                                TIE_POINT_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, line);
                            }
                        }
                    }
                    for (final MappedLocation mappedLocation : tiePoints) {
                        LineString line = mappedLocation.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
                        if (line != null) {
                            line = line.convertGeometry(viewportGeometryFactory);
                            TIE_POINT_VERTEX_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, line);
                        }
                    }
                }
                if (!showOriginalImage) {
                    final double width = image.getImageWidth() - 1;
                    final double height = image.getImageHeight() - 1;
                    final double[] targetCoordinates = MappedLocation.toModelCoordinates(image, boundingBox, true, 0, height, width, height, width, 0, 0, 0, 0, height);
                    final LineString line = viewGeometryFactory.lineString(2, targetCoordinates);
                    GeometryStyleRenderer.renderLineString(viewport, graphics, line, STYLE_IMAGE_LINE);
                }
            }
            final MappedLocation moveTiePoint = getMoveTiePoint();
            if (moveTiePoint != null) {
                final LineString line = moveTiePoint.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
                Vertex vertex;
                if (this.moveTiePointSource) {
                    vertex = line.getVertex(0);
                } else {
                    vertex = line.getToVertex(0);
                }
                TIE_POINT_CLOSE_VERTEX_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, vertex);
            }
        }
    }
    drawXorGeometry(graphics);
}
Also used : Vertex(com.revolsys.geometry.model.vertex.Vertex) BaseCloseable(com.revolsys.io.BaseCloseable) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BufferedGeoreferencedImage(com.revolsys.raster.BufferedGeoreferencedImage) GeoreferencedImage(com.revolsys.raster.GeoreferencedImage) MappedLocation(com.revolsys.raster.MappedLocation) GeoreferencedImageLayer(com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer) Point(com.revolsys.geometry.model.Point) LineString(com.revolsys.geometry.model.LineString) BoundingBox(com.revolsys.geometry.model.BoundingBox) Polygon(com.revolsys.geometry.model.Polygon)

Example 75 with Polygon

use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.

the class MarkerStyleRenderer method renderMarker.

public static void renderMarker(final Viewport2D viewport, final Geometry geometry, final MarkerStyle style) {
    try (BaseCloseable transformClosable = viewport.setUseModelCoordinates(false)) {
        @SuppressWarnings("deprecation") final Graphics2D graphics = viewport.getGraphics();
        if (graphics != null && geometry != null) {
            if ("vertices".equals(style.getMarkerPlacementType())) {
                renderMarkerVertices(viewport, graphics, geometry, style);
            } else if ("segments".equals(style.getMarkerPlacementType())) {
                renderMarkerSegments(viewport, graphics, geometry, style);
            } else {
                for (int i = 0; i < geometry.getGeometryCount(); i++) {
                    final Geometry part = geometry.getGeometry(i);
                    if (part instanceof Point) {
                        final Point point = (Point) part;
                        renderMarker(viewport, graphics, point, style, 0);
                    } else if (part instanceof LineString) {
                        final LineString line = (LineString) part;
                        renderMarker(viewport, graphics, line, style);
                    } else if (part instanceof Polygon) {
                        final Polygon polygon = (Polygon) part;
                        renderMarker(viewport, graphics, polygon, style);
                    }
                }
            }
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) BaseCloseable(com.revolsys.io.BaseCloseable) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon) Graphics2D(java.awt.Graphics2D)

Aggregations

Polygon (com.revolsys.geometry.model.Polygon)147 Point (com.revolsys.geometry.model.Point)66 LinearRing (com.revolsys.geometry.model.LinearRing)54 LineString (com.revolsys.geometry.model.LineString)39 Geometry (com.revolsys.geometry.model.Geometry)34 ArrayList (java.util.ArrayList)30 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)22 Polygonal (com.revolsys.geometry.model.Polygonal)17 BoundingBox (com.revolsys.geometry.model.BoundingBox)14 Punctual (com.revolsys.geometry.model.Punctual)12 Test (org.junit.Test)12 Lineal (com.revolsys.geometry.model.Lineal)11 BaseCloseable (com.revolsys.io.BaseCloseable)7 List (java.util.List)7 PolygonEditor (com.revolsys.geometry.model.editor.PolygonEditor)6 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)6 Vertex (com.revolsys.geometry.model.vertex.Vertex)6 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)3 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)3 Graphics2D (java.awt.Graphics2D)3