Search in sources :

Example 91 with Polygon

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

the class MeasureOverlay method modeMeasureClick.

protected boolean modeMeasureClick(final MouseEvent event) {
    final int modifiers = event.getModifiersEx();
    if (modifiers == 0 && event.getButton() == MouseEvent.BUTTON1) {
        if (isOverlayAction(MEASURE)) {
            final int clickCount = event.getClickCount();
            Point point = getSnapPoint();
            if (point == null) {
                point = getPoint(event);
            }
            if (clickCount == 1) {
                final Geometry measureGeometry = getMeasureGeometry();
                final GeometryFactory geometryFactory = getGeometryFactory2d();
                if (measureGeometry.isEmpty()) {
                    setMeasureGeometry(point);
                } else if (measureGeometry instanceof Point) {
                    final Point from = (Point) measureGeometry;
                    if (!from.equals(point)) {
                        final LineString line = geometryFactory.lineString(from, point);
                        setMeasureGeometry(line);
                    }
                } else if (this.measureDataType == DataTypes.LINE_STRING) {
                    if (measureGeometry instanceof LineString) {
                        LineString line = (LineString) measureGeometry;
                        final Point to = line.getToPoint();
                        if (!to.equals(point)) {
                            final Point newPoint = point;
                            line = line.editLine(editor -> editor.appendVertex(newPoint));
                            setMeasureGeometry(line);
                        }
                    }
                } else {
                    if (measureGeometry instanceof LineString) {
                        LineString line = (LineString) measureGeometry;
                        final Point from = line.getToVertex(0);
                        if (!from.equals(point)) {
                            final Point newPoint = point;
                            line = line.editLine(editor -> editor.appendVertex(newPoint));
                            setMeasureGeometry(line);
                        }
                        if (line.getVertexCount() > 2) {
                            if (!line.isClosed()) {
                                final Vertex firstPoint = line.getVertex(0);
                                line = line.editLine(editor -> editor.appendVertex(firstPoint));
                            }
                            setMeasureGeometry(geometryFactory.polygon(line));
                        }
                    } else if (measureGeometry instanceof Polygon) {
                        final Polygon polygon = (Polygon) measureGeometry;
                        final Point newPoint = point;
                        setMeasureGeometry(polygon.edit(editor -> editor.appendVertex(new int[] { 0 }, newPoint)));
                    }
                }
                event.consume();
                repaint();
                return true;
            }
        }
    }
    return false;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) InputEvent(java.awt.event.InputEvent) Icons(com.revolsys.swing.Icons) Unit(javax.measure.Unit) Point2D(java.awt.geom.Point2D) GeometryStyle(com.revolsys.swing.map.layer.record.style.GeometryStyle) Cursor(java.awt.Cursor) LineString(com.revolsys.geometry.model.LineString) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) WebColors(com.revolsys.awt.WebColors) Viewport2D(com.revolsys.swing.map.Viewport2D) Graphics2D(java.awt.Graphics2D) CustomUnits(com.revolsys.geometry.cs.unit.CustomUnits) Length(javax.measure.quantity.Length) Map(java.util.Map) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) BaseCloseable(com.revolsys.io.BaseCloseable) TextStyle(com.revolsys.swing.map.layer.record.style.TextStyle) Vertex(com.revolsys.geometry.model.vertex.Vertex) SelectedRecordsVertexRenderer(com.revolsys.swing.map.overlay.record.SelectedRecordsVertexRenderer) PropertyChangeEvent(java.beans.PropertyChangeEvent) MapPanel(com.revolsys.swing.map.MapPanel) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) Punctual(com.revolsys.geometry.model.Punctual) Font(java.awt.Font) Area(javax.measure.quantity.Area) DecimalFormat(java.text.DecimalFormat) Set(java.util.Set) Maps(com.revolsys.collection.map.Maps) Polygon(com.revolsys.geometry.model.Polygon) KeyEvent(java.awt.event.KeyEvent) LinearRing(com.revolsys.geometry.model.LinearRing) DataTypes(com.revolsys.datatype.DataTypes) GeometryStyleRenderer(com.revolsys.swing.map.layer.record.renderer.GeometryStyleRenderer) MouseEvent(java.awt.event.MouseEvent) List(java.util.List) TreeMap(java.util.TreeMap) Quantities(tec.uom.se.quantity.Quantities) Units(tec.uom.se.unit.Units) GeometryEditor(com.revolsys.geometry.model.editor.GeometryEditor) TextStyleRenderer(com.revolsys.swing.map.layer.record.renderer.TextStyleRenderer) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) DataType(com.revolsys.datatype.DataType) Geometry(com.revolsys.geometry.model.Geometry) Collections(java.util.Collections) Toolkit(java.awt.Toolkit) Point(com.revolsys.geometry.model.Point) Doubles(com.revolsys.util.number.Doubles) 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) Point(com.revolsys.geometry.model.Point)

Example 92 with Polygon

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

the class SierpinskiCarpetBuilder method getGeometry.

@Override
public Geometry getGeometry() {
    final int level = recursionLevelForSize(this.numPts);
    final LineSegment baseLine = getSquareBaseLine();
    final Point origin = baseLine.getPoint(0);
    final List<LinearRing> rings = new ArrayList<>();
    final LinearRing shell = ((Polygon) getSquareExtent().toGeometry()).getShell();
    rings.add(shell);
    addHoles(level, origin.getX(), origin.getY(), getDiameter(), rings);
    return this.geometryFactory.polygon(shell);
}
Also used : ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 93 with Polygon

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

the class DistanceWithLocation method computeContainmentDistance.

private void computeContainmentDistance(final int polyGeomIndex, final GeometryLocation[] locPtPoly) {
    Geometry geometry1;
    Geometry geometry2;
    if (polyGeomIndex == 0) {
        geometry1 = this.geometry1;
        geometry2 = this.geometry2;
    } else {
        geometry1 = this.geometry2;
        geometry2 = this.geometry1;
    }
    final boolean flip = polyGeomIndex == 0;
    final List<Polygon> polys = geometry1.getGeometries(Polygon.class);
    if (polys.size() > 0) {
        final List<GeometryLocation> insideLocs = ConnectedElementLocationFilter.getLocations(geometry2);
        computeContainmentDistance(insideLocs, polys, locPtPoly);
        if (this.minDistance <= this.terminateDistance) {
            // this assignment is determined by the order of the args in the
            // computeInside call above
            setMinDistanceLocations(locPtPoly[0], locPtPoly[1], flip);
            return;
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Polygon(com.revolsys.geometry.model.Polygon)

Example 94 with Polygon

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

the class GeometryTransformer method transformMultiPolygon.

protected Geometry transformMultiPolygon(final Polygonal polygonal, final Geometry parent) {
    final List<Geometry> transGeomList = new ArrayList<>();
    for (final Polygon polygon : polygonal.polygons()) {
        final Geometry transformGeom = transformPolygon(polygon, polygonal);
        if (transformGeom == null) {
            continue;
        }
        if (transformGeom.isEmpty()) {
            continue;
        }
        transGeomList.add(transformGeom);
    }
    return this.factory.buildGeometry(transGeomList);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) ArrayList(java.util.ArrayList) Polygon(com.revolsys.geometry.model.Polygon)

Example 95 with Polygon

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

the class SineStarFactory method newSineStar.

/**
 * Generates the geometry for the sine star
 *
 * @return the geometry representing the sine star
 */
public Geometry newSineStar() {
    final BoundingBox env = this.dim.getEnvelope();
    final double radius = env.getWidth() / 2.0;
    double armRatio = this.armLengthRatio;
    if (armRatio < 0.0) {
        armRatio = 0.0;
    }
    if (armRatio > 1.0) {
        armRatio = 1.0;
    }
    final double armMaxLen = armRatio * radius;
    final double insideRadius = (1 - armRatio) * radius;
    final double centreX = env.getMinX() + radius;
    final double centreY = env.getMinY() + radius;
    final double[] coordinates = new double[(this.vertexCount + 1) * 2];
    int coordinateIndex = 0;
    for (int i = 0; i < this.vertexCount; i++) {
        // the fraction of the way thru the current arm - in [0,1]
        final double ptArcFrac = i / (double) this.vertexCount * this.numArms;
        final double armAngFrac = ptArcFrac - Math.floor(ptArcFrac);
        // the angle for the current arm - in [0,2Pi]
        // (each arm is a complete sine wave cycle)
        final double armAng = 2 * Math.PI * armAngFrac;
        // the current length of the arm
        final double armLenFrac = (Math.cos(armAng) + 1.0) / 2.0;
        // the current radius of the curve (core + arm)
        final double curveRadius = insideRadius + armMaxLen * armLenFrac;
        // the current angle of the curve
        final double ang = i * (2 * Math.PI / this.vertexCount);
        final double x = curveRadius * Math.cos(ang) + centreX;
        final double y = curveRadius * Math.sin(ang) + centreY;
        coordinates[coordinateIndex++] = this.geomFact.makeXyPrecise(x);
        coordinates[coordinateIndex++] = this.geomFact.makeXyPrecise(y);
    }
    final LinearRing ring = this.geomFact.linearRing(2, coordinates);
    final Polygon poly = this.geomFact.polygon(ring);
    return poly;
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon)

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