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);
}
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;
}
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;
}
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;
}
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);
}
}
}
}
}
Aggregations