Search in sources :

Example 76 with Polygon

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

the class PdfViewport method drawGeometry.

@Override
public void drawGeometry(final Geometry geometry, final GeometryStyle style) {
    try {
        this.contentStream.saveGraphicsState();
        setGeometryStyle(style);
        this.contentStream.setNonStrokingColor(style.getPolygonFill());
        this.contentStream.setStrokingColor(style.getLineColor());
        for (Geometry part : geometry.geometries()) {
            part = part.convertGeometry(getGeometryFactory());
            if (part instanceof LineString) {
                final LineString line = (LineString) part;
                drawLine(line);
                this.contentStream.stroke();
            } else if (part instanceof Polygon) {
                final Polygon polygon = (Polygon) part;
                int i = 0;
                for (final LinearRing ring : polygon.rings()) {
                    if (i == 0) {
                        if (ring.isClockwise()) {
                            drawLineReverse(ring);
                        } else {
                            drawLine(ring);
                        }
                    } else {
                        if (ring.isCounterClockwise()) {
                            drawLineReverse(ring);
                        } else {
                            drawLine(ring);
                        }
                    }
                    this.contentStream.closeSubPath();
                    i++;
                }
                this.contentStream.fill(PathIterator.WIND_NON_ZERO);
                for (final LinearRing ring : polygon.rings()) {
                    drawLine(ring);
                    this.contentStream.stroke();
                }
            }
        }
    } catch (final IOException e) {
    } finally {
        try {
            this.contentStream.restoreGraphicsState();
        } catch (final IOException e) {
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) LineString(com.revolsys.geometry.model.LineString) IOException(java.io.IOException) Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing)

Example 77 with Polygon

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

the class PointLocator method locate.

public Location locate(final Geometry geometry, final double x, final double y) {
    if (geometry.isEmpty()) {
        return Location.EXTERIOR;
    } else if (geometry instanceof LineString) {
        return geometry.locate(x, y);
    } else if (geometry instanceof Polygon) {
        return geometry.locate(x, y);
    }
    this.isIn = false;
    final int boundaryCount = computeLocation(geometry, x, y);
    if (boundaryCount % 2 == 1) {
        return Location.BOUNDARY;
    } else if (boundaryCount > 0 || this.isIn) {
        return Location.INTERIOR;
    } else {
        return Location.EXTERIOR;
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Example 78 with Polygon

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

the class LineSegment method getCrossing.

default Point getCrossing(final Point point1, final Point point2, final BoundingBox boundingBox) {
    final GeometryFactory geometryFactory = getGeometryFactory();
    Point intersection = null;
    final Polygon polygon = boundingBox.toPolygon(1);
    final LineString ring = polygon.getShell();
    for (int i = 0; i < 4; i++) {
        final Point ringC1 = ring.getPoint(i);
        final Point ringC2 = ring.getPoint(i);
        final LineString currentIntersections = LineSegmentUtil.getIntersection(geometryFactory, point1, point2, ringC1, ringC2);
        if (currentIntersections.getVertexCount() == 1) {
            final Point currentIntersection = currentIntersections.getPoint(0);
            if (intersection == null) {
                intersection = currentIntersection;
            } else if (point1.distancePoint(currentIntersection) < point1.distancePoint(intersection)) {
                intersection = currentIntersection;
            }
        }
    }
    return intersection;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Example 79 with Polygon

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

the class AbstractPreparedPolygonContains method isSingleShell.

/**
 * Tests whether a geometry consists of a single originalGeometry with no holes.
 *
 * @return true if the geometry is a single originalGeometry with no holes
 */
private boolean isSingleShell(final Polygonal polygonal) {
    // handles single-element MultiPolygons, as well as Polygons
    if (polygonal.getPolygonCount() != 1) {
        return false;
    }
    final Polygon poly = polygonal.getPolygon(0);
    final int numHoles = poly.getHoleCount();
    if (numHoles == 0) {
        return true;
    }
    return false;
}
Also used : Polygon(com.revolsys.geometry.model.Polygon)

Example 80 with Polygon

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

the class MultiPolygonSegment method hasNext.

@Override
public boolean hasNext() {
    final Polygonal polygonal = this.polygonal;
    if (polygonal.isEmpty()) {
        return false;
    } else {
        int partIndex = this.partIndex;
        int ringIndex = this.ringIndex;
        int segmentIndex = this.segmentIndex + 1;
        while (partIndex < polygonal.getGeometryCount()) {
            final Polygon polygon = getPolygon();
            while (ringIndex < polygon.getRingCount()) {
                final LinearRing ring = polygon.getRing(ringIndex);
                if (segmentIndex < ring.getSegmentCount()) {
                    return true;
                } else {
                    ringIndex++;
                    segmentIndex = 0;
                }
            }
            partIndex++;
            ringIndex = 0;
            segmentIndex = 0;
        }
        return false;
    }
}
Also used : Polygonal(com.revolsys.geometry.model.Polygonal) Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing)

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