Search in sources :

Example 86 with Polygon

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

the class KmlGeometryReader method parsePolygon.

private Polygon parsePolygon() throws XMLStreamException {
    this.in.requireLocalName(POLYGON);
    final List<LinearRing> rings = new ArrayList<>();
    int axisCount = 2;
    final int depth = this.in.getDepth();
    while (this.in.skipToStartElements(depth, OUTER_BOUNDARY_IS, INNER_BOUNDARY_IS)) {
        final LinearRing ring = parseRing();
        if (ring != null) {
            axisCount = Math.max(axisCount, ring.getAxisCount());
            rings.add(ring);
        }
    }
    final GeometryFactory geometryFactory = this.geometryFactory.convertAxisCount(axisCount);
    final Polygon polygon = geometryFactory.polygon(rings);
    return polygon;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ArrayList(java.util.ArrayList) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Example 87 with Polygon

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

the class GmlGeometryFieldType method geometry.

private void geometry(final XmlWriter out, final Object value, final boolean writeSrsName) {
    if (value instanceof Geometry) {
        final Geometry geometry = (Geometry) value;
        if (geometry instanceof Point) {
            final Point point = (Point) geometry;
            point(out, point, writeSrsName);
        } else if (geometry instanceof LineString) {
            final LineString line = (LineString) geometry;
            lineString(out, line, writeSrsName);
        } else if (geometry instanceof Polygon) {
            final Polygon polygon = (Polygon) geometry;
            polygon(out, polygon, writeSrsName);
        } else if (geometry instanceof Punctual) {
            final Punctual punctual = (Punctual) geometry;
            multiPoint(out, punctual, writeSrsName);
        } else if (geometry instanceof Lineal) {
            final Lineal lineal = (Lineal) geometry;
            multiLineString(out, lineal, writeSrsName);
        } else if (geometry instanceof Polygonal) {
            final Polygonal polygonal = (Polygonal) geometry;
            multiPolygon(out, polygonal, writeSrsName);
        } else if (geometry.isGeometryCollection()) {
            geometryCollection(out, geometry, writeSrsName);
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Punctual(com.revolsys.geometry.model.Punctual) Lineal(com.revolsys.geometry.model.Lineal) LineString(com.revolsys.geometry.model.LineString) Polygonal(com.revolsys.geometry.model.Polygonal) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon)

Example 88 with Polygon

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

the class FixedPrecisionSnappingTest method testTriangles.

public void testTriangles() throws ParseException {
    final Polygon a = this.factory.geometry("POLYGON((545 317, 617 379, 581 321, 545 317))");
    final Polygon b = this.factory.geometry("POLYGON((484 290, 558 359, 543 309, 484 290))");
    a.intersection(b);
}
Also used : Polygon(com.revolsys.geometry.model.Polygon)

Example 89 with Polygon

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

the class MeasureOverlay method paintComponent.

@Override
protected void paintComponent(final Viewport2D viewport, final Graphics2D graphics) {
    if (!this.measureGeometry.isEmpty()) {
        final GeometryFactory geometryFactory = getGeometryFactory2d();
        try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
            MEASURE_RENDERER.paintSelected(viewport, graphics, geometryFactory, this.measureGeometry);
            if (this.measureGeometry instanceof Polygon) {
                final Polygon polygon = (Polygon) this.measureGeometry;
                GeometryStyleRenderer.renderPolygon(viewport, graphics, polygon, POLYGON_STYLE);
            }
        }
        if (!(this.measureGeometry instanceof Punctual)) {
            final TextStyle measureTextStyle = new TextStyle();
            measureTextStyle.setTextBoxColor(WebColors.Violet);
            measureTextStyle.setTextSize(Quantities.getQuantity(14, CustomUnits.PIXEL));
            measureTextStyle.setTextFaceName(Font.MONOSPACED);
            Point textPoint;
            measureTextStyle.setTextHorizontalAlignment("right");
            if (this.measureDataType == DataTypes.POLYGON && this.measureGeometry instanceof Polygon) {
                measureTextStyle.setTextDx(Quantities.getQuantity(-5, CustomUnits.PIXEL));
                measureTextStyle.setTextPlacementType("vertex(n-1)");
                measureTextStyle.setTextVerticalAlignment("middle");
                textPoint = this.measureGeometry.getToVertex(0, 1);
            } else {
                measureTextStyle.setTextDx(Quantities.getQuantity(-7, CustomUnits.PIXEL));
                measureTextStyle.setTextDy(Quantities.getQuantity(-2, CustomUnits.PIXEL));
                measureTextStyle.setTextPlacementType("vertex(n)");
                measureTextStyle.setTextVerticalAlignment("top");
                textPoint = this.measureGeometry.getToVertex(0);
            }
            TextStyleRenderer.renderText(viewport, graphics, this.measureLabel, textPoint, measureTextStyle);
        }
    }
    drawXorGeometry(graphics);
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Punctual(com.revolsys.geometry.model.Punctual) TextStyle(com.revolsys.swing.map.layer.record.style.TextStyle) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon)

Example 90 with Polygon

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

the class MeasureOverlay method deleteVertex.

private Geometry deleteVertex() {
    final Geometry geometry = getMeasureGeometry();
    for (final CloseLocation location : getMouseOverLocations()) {
        final int[] vertexId = location.getVertexId();
        if (vertexId != null) {
            if (geometry instanceof Point) {
                return null;
            } else if (geometry instanceof LineString) {
                final LineString line = (LineString) geometry;
                if (line.getVertexCount() == 2) {
                    if (vertexId.length == 1) {
                        if (vertexId[0] == 0) {
                            return line.getPoint(1);
                        } else {
                            return line.getPoint(0);
                        }
                    }
                }
            } else if (geometry instanceof Polygon) {
                final Polygon polygon = (Polygon) geometry;
                final LinearRing ring = polygon.getRing(0);
                if (ring.getVertexCount() == 4) {
                    if (vertexId.length == 2) {
                        final GeometryFactory geometryFactory = geometry.getGeometryFactory();
                        final Vertex point0 = ring.getVertex(0);
                        final Vertex point1 = ring.getVertex(1);
                        final Vertex point2 = ring.getVertex(2);
                        switch(vertexId[1]) {
                            case 0:
                                return geometryFactory.lineString(point1, point2);
                            case 1:
                                return geometryFactory.lineString(point2, point0);
                            default:
                                return geometryFactory.lineString(point0, point1);
                        }
                    }
                }
            }
            try {
                final GeometryEditor geometryEditor = geometry.newGeometryEditor();
                geometryEditor.deleteVertex(vertexId);
                if (geometryEditor.isModified()) {
                    return geometryEditor.newGeometry();
                }
            } catch (final Exception e) {
                Toolkit.getDefaultToolkit().beep();
                return geometry;
            }
        }
    }
    return geometry;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Vertex(com.revolsys.geometry.model.vertex.Vertex) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing) GeometryEditor(com.revolsys.geometry.model.editor.GeometryEditor)

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