Search in sources :

Example 46 with LinearRing

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

the class OracleSdoGeometryJdbcFieldDefinition method toPolygon.

private Polygon toPolygon(final ResultSet resultSet, final int columnIndex, final int axisCount) throws SQLException {
    final BigDecimal[] elemInfo = JdbcUtils.getBigDecimalArray(resultSet, columnIndex + 4);
    final BigDecimal[] coordinatesArray = JdbcUtils.getBigDecimalArray(resultSet, columnIndex + 5);
    final List<LinearRing> rings = new ArrayList<>();
    int numInteriorRings = 0;
    for (int elemInfoOffset = 0; elemInfoOffset < elemInfo.length; ) {
        final int offset = elemInfo[elemInfoOffset].intValue();
        final int type = (int) elemInfo[elemInfoOffset + 1].longValue();
        final long interpretation = elemInfo[elemInfoOffset + 2].longValue();
        switch(type) {
            case 1003:
                if (rings.isEmpty()) {
                    elemInfoOffset = addRingSimple(rings, axisCount, elemInfo, type, coordinatesArray, elemInfoOffset, offset, interpretation);
                } else {
                    throw new IllegalArgumentException("Cannot have two exterior rings on a geometry");
                }
                break;
            case 1005:
                if (rings.isEmpty()) {
                    elemInfoOffset = addRingComplex(rings, axisCount, elemInfo, type, coordinatesArray, elemInfoOffset, offset, interpretation);
                } else {
                    throw new IllegalArgumentException("Cannot have two exterior rings on a geometry");
                }
                break;
            case 2003:
                if (numInteriorRings == rings.size()) {
                    throw new IllegalArgumentException("Too many interior rings");
                } else {
                    numInteriorRings++;
                    elemInfoOffset = addRingSimple(rings, axisCount, elemInfo, type, coordinatesArray, elemInfoOffset, offset, interpretation);
                }
                break;
            case 2005:
                if (numInteriorRings == rings.size()) {
                    throw new IllegalArgumentException("Too many interior rings");
                } else {
                    numInteriorRings++;
                    elemInfoOffset = addRingSimple(rings, axisCount, elemInfo, type, coordinatesArray, elemInfoOffset, offset, interpretation);
                }
                break;
            default:
                throw new IllegalArgumentException("Unsupported geometry type " + type);
        }
    }
    final Polygon polygon = this.geometryFactory.polygon(rings);
    return polygon;
}
Also used : ArrayList(java.util.ArrayList) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon) BigDecimal(java.math.BigDecimal) Point(com.revolsys.geometry.model.Point)

Example 47 with LinearRing

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

the class GeometryStyleRenderer method renderGeometryOutline.

public static final void renderGeometryOutline(final Viewport2D viewport, final Graphics2D graphics, final Geometry geometry, final GeometryStyle style) {
    if (geometry != null) {
        final BoundingBox viewExtent = viewport.getBoundingBox();
        if (!viewExtent.isEmpty()) {
            final GeometryFactory viewGeometryFactory = viewport.getGeometryFactory2dFloating();
            for (int i = 0; i < geometry.getGeometryCount(); i++) {
                final Geometry part = geometry.getGeometry(i);
                final BoundingBox partExtent = part.getBoundingBox();
                if (partExtent.intersects(viewExtent)) {
                    final Geometry convertedPart = part.convertGeometry(viewGeometryFactory);
                    if (convertedPart instanceof Point) {
                        final Point point = (Point) convertedPart;
                        MarkerStyleRenderer.renderMarker(viewport, graphics, point, style, 0);
                    } else if (convertedPart instanceof LineString) {
                        final LineString lineString = (LineString) convertedPart;
                        renderLineString(viewport, graphics, lineString, style);
                    } else if (convertedPart instanceof Polygon) {
                        final Polygon polygon = (Polygon) convertedPart;
                        for (final LinearRing ring : polygon.rings()) {
                            renderLineString(viewport, graphics, ring, style);
                        }
                    }
                }
            }
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineString(com.revolsys.geometry.model.LineString) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing) Paint(java.awt.Paint) Point(com.revolsys.geometry.model.Point)

Example 48 with LinearRing

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

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

the class DistanceToPoint method computeDistance.

public static void computeDistance(final Polygon poly, final Point point, final PointPairDistance pointDistance) {
    final double x = point.getX();
    final double y = point.getY();
    for (final LinearRing ring : poly.rings()) {
        computeDistance(ring, x, y, pointDistance);
    }
}
Also used : LinearRing(com.revolsys.geometry.model.LinearRing)

Example 50 with LinearRing

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

the class PreparedPolygon method prepareRings.

private static LinearRing[] prepareRings(final Polygon polygon) {
    final LinearRing[] rings = new LinearRing[polygon.getRingCount()];
    for (int i = 0; i < rings.length; i++) {
        final LinearRing ring = polygon.getRing(i);
        rings[i] = ring.prepare();
    }
    return rings;
}
Also used : LinearRing(com.revolsys.geometry.model.LinearRing) Point(com.revolsys.geometry.model.Point)

Aggregations

LinearRing (com.revolsys.geometry.model.LinearRing)95 Polygon (com.revolsys.geometry.model.Polygon)53 Point (com.revolsys.geometry.model.Point)44 ArrayList (java.util.ArrayList)21 LineString (com.revolsys.geometry.model.LineString)19 Geometry (com.revolsys.geometry.model.Geometry)14 Polygonal (com.revolsys.geometry.model.Polygonal)11 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)9 BoundingBox (com.revolsys.geometry.model.BoundingBox)8 Lineal (com.revolsys.geometry.model.Lineal)7 Punctual (com.revolsys.geometry.model.Punctual)6 List (java.util.List)4 NoSuchElementException (java.util.NoSuchElementException)4 IOException (java.io.IOException)3 MCPointInRing (com.revolsys.geometry.algorithm.MCPointInRing)2 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)2 Vertex (com.revolsys.geometry.model.vertex.Vertex)2 BigDecimal (java.math.BigDecimal)2 PointInRing (com.revolsys.geometry.algorithm.PointInRing)1 EdgeRing (com.revolsys.geometry.geomgraph.EdgeRing)1