Search in sources :

Example 36 with Vertex

use of com.revolsys.geometry.model.vertex.Vertex in project com.revolsys.open by revolsys.

the class MeasureOverlay method modeMeasureUpdateXorGeometry.

protected void modeMeasureUpdateXorGeometry() {
    final Point point = getOverlayPoint();
    if (!hasSnapPoint()) {
        setMapCursor(CURSOR);
    }
    Geometry xorGeometry = null;
    if (this.measureGeometry.isEmpty()) {
    } else {
        Vertex fromPoint;
        final Vertex toPoint;
        if (this.measureGeometry instanceof LineString) {
            fromPoint = this.measureGeometry.getVertex(0);
            toPoint = this.measureGeometry.getToVertex(0);
        } else {
            fromPoint = this.measureGeometry.getVertex(0, 0);
            toPoint = this.measureGeometry.getToVertex(0, 0);
        }
        final GeometryFactory geometryFactory = getGeometryFactory2d();
        if (toPoint != null && !toPoint.isEmpty()) {
            if (this.measureGeometry instanceof Point) {
                xorGeometry = geometryFactory.lineString(toPoint, point);
            } else {
                if (toPoint.equals(fromPoint) || this.measureDataType == DataTypes.LINE_STRING) {
                    xorGeometry = newXorLine(geometryFactory, toPoint, point);
                } else {
                    final Point p1 = geometryFactory.point(toPoint);
                    final Point p3 = geometryFactory.point(fromPoint);
                    final GeometryFactory viewportGeometryFactory = getViewportGeometryFactory2d();
                    xorGeometry = viewportGeometryFactory.lineString(p1, point, p3);
                }
            }
        }
    }
    setXorGeometry(xorGeometry);
}
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)

Example 37 with Vertex

use of com.revolsys.geometry.model.vertex.Vertex 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)

Example 38 with Vertex

use of com.revolsys.geometry.model.vertex.Vertex 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 39 with Vertex

use of com.revolsys.geometry.model.vertex.Vertex in project com.revolsys.open by revolsys.

the class MeasureOverlay method getVertexGeometry.

protected Geometry getVertexGeometry(final MouseEvent event, final CloseLocation location) {
    final Geometry geometry = location.getGeometry();
    int previousPointOffset;
    int[] vertexId = location.getVertexId();
    if (vertexId == null) {
        previousPointOffset = 0;
        vertexId = location.getSegmentId();
    } else {
        previousPointOffset = -1;
    }
    final GeometryFactory geometryFactory = getGeometryFactory2d();
    if (geometry instanceof Point) {
    } else {
        final Point point = getPoint(geometryFactory, event);
        final Vertex vertex = geometry.getVertex(vertexId);
        Point previousPoint = null;
        Point nextPoint = null;
        if (previousPointOffset == 0) {
            previousPoint = vertex;
        } else {
            previousPoint = vertex.getLinePrevious();
        }
        nextPoint = vertex.getLineNext();
        final List<LineString> lines = new ArrayList<>();
        if (previousPoint != null && !previousPoint.isEmpty()) {
            lines.add(newXorLine(geometryFactory, previousPoint, point));
        }
        if (nextPoint != null && !nextPoint.isEmpty()) {
            lines.add(newXorLine(geometryFactory, nextPoint, point));
        }
        if (!lines.isEmpty()) {
            return geometryFactory.lineal(lines);
        }
    }
    return null;
}
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) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 40 with Vertex

use of com.revolsys.geometry.model.vertex.Vertex in project com.revolsys.open by revolsys.

the class GeometryCoordinatesTableModel method setValueAt.

@Override
public void setValueAt(final Object value, final int rowIndex, final int columnIndex) {
    if (Property.hasValue(value)) {
        if (rowIndex < getRowCount()) {
            if (columnIndex >= this.numIndexItems) {
                final int axisIndex = columnIndex - this.numIndexItems;
                final Vertex vertex = getVertex(rowIndex);
                if (vertex != null) {
                    final double coordinate = MathUtil.toDouble(value.toString());
                    final int[] vertexId = vertex.getVertexId();
                    final Geometry newGeometry = this.geometry.edit(editor -> editor.setCoordinate(vertexId, axisIndex, coordinate));
                    setGeometry(newGeometry);
                }
            }
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Vertex(com.revolsys.geometry.model.vertex.Vertex) Point(com.revolsys.geometry.model.Point)

Aggregations

Vertex (com.revolsys.geometry.model.vertex.Vertex)42 Point (com.revolsys.geometry.model.Point)18 Geometry (com.revolsys.geometry.model.Geometry)16 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)14 LineString (com.revolsys.geometry.model.LineString)10 Polygon (com.revolsys.geometry.model.Polygon)6 Segment (com.revolsys.geometry.model.segment.Segment)6 ArrayList (java.util.ArrayList)6 GeometryEditor (com.revolsys.geometry.model.editor.GeometryEditor)4 AbstractVertex (com.revolsys.geometry.model.vertex.AbstractVertex)4 LineStringVertex (com.revolsys.geometry.model.vertex.LineStringVertex)4 BaseCloseable (com.revolsys.io.BaseCloseable)4 CloseLocation (com.revolsys.swing.map.overlay.CloseLocation)4 DataType (com.revolsys.datatype.DataType)3 LinearRing (com.revolsys.geometry.model.LinearRing)3 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)3 LineSegment (com.revolsys.geometry.model.segment.LineSegment)3 MapPanel (com.revolsys.swing.map.MapPanel)3 WebColors (com.revolsys.awt.WebColors)2 Maps (com.revolsys.collection.map.Maps)2