use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class KmlGeometryReader method parsePolygon.
private Polygon parsePolygon() throws XMLStreamException {
this.in.requireLocalName(POLYGON);
final List<LinearRing> rings = new ArrayList<>();
int axisCount = 2;
final int depth = this.in.getDepth();
while (this.in.skipToStartElements(depth, OUTER_BOUNDARY_IS, INNER_BOUNDARY_IS)) {
final LinearRing ring = parseRing();
if (ring != null) {
axisCount = Math.max(axisCount, ring.getAxisCount());
rings.add(ring);
}
}
final GeometryFactory geometryFactory = this.geometryFactory.convertAxisCount(axisCount);
final Polygon polygon = geometryFactory.polygon(rings);
return polygon;
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class GmlGeometryFieldType method geometry.
private void geometry(final XmlWriter out, final Object value, final boolean writeSrsName) {
if (value instanceof Geometry) {
final Geometry geometry = (Geometry) value;
if (geometry instanceof Point) {
final Point point = (Point) geometry;
point(out, point, writeSrsName);
} else if (geometry instanceof LineString) {
final LineString line = (LineString) geometry;
lineString(out, line, writeSrsName);
} else if (geometry instanceof Polygon) {
final Polygon polygon = (Polygon) geometry;
polygon(out, polygon, writeSrsName);
} else if (geometry instanceof Punctual) {
final Punctual punctual = (Punctual) geometry;
multiPoint(out, punctual, writeSrsName);
} else if (geometry instanceof Lineal) {
final Lineal lineal = (Lineal) geometry;
multiLineString(out, lineal, writeSrsName);
} else if (geometry instanceof Polygonal) {
final Polygonal polygonal = (Polygonal) geometry;
multiPolygon(out, polygonal, writeSrsName);
} else if (geometry.isGeometryCollection()) {
geometryCollection(out, geometry, writeSrsName);
}
}
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class FixedPrecisionSnappingTest method testTriangles.
public void testTriangles() throws ParseException {
final Polygon a = this.factory.geometry("POLYGON((545 317, 617 379, 581 321, 545 317))");
final Polygon b = this.factory.geometry("POLYGON((484 290, 558 359, 543 309, 484 290))");
a.intersection(b);
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class MeasureOverlay method paintComponent.
@Override
protected void paintComponent(final Viewport2D viewport, final Graphics2D graphics) {
if (!this.measureGeometry.isEmpty()) {
final GeometryFactory geometryFactory = getGeometryFactory2d();
try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
MEASURE_RENDERER.paintSelected(viewport, graphics, geometryFactory, this.measureGeometry);
if (this.measureGeometry instanceof Polygon) {
final Polygon polygon = (Polygon) this.measureGeometry;
GeometryStyleRenderer.renderPolygon(viewport, graphics, polygon, POLYGON_STYLE);
}
}
if (!(this.measureGeometry instanceof Punctual)) {
final TextStyle measureTextStyle = new TextStyle();
measureTextStyle.setTextBoxColor(WebColors.Violet);
measureTextStyle.setTextSize(Quantities.getQuantity(14, CustomUnits.PIXEL));
measureTextStyle.setTextFaceName(Font.MONOSPACED);
Point textPoint;
measureTextStyle.setTextHorizontalAlignment("right");
if (this.measureDataType == DataTypes.POLYGON && this.measureGeometry instanceof Polygon) {
measureTextStyle.setTextDx(Quantities.getQuantity(-5, CustomUnits.PIXEL));
measureTextStyle.setTextPlacementType("vertex(n-1)");
measureTextStyle.setTextVerticalAlignment("middle");
textPoint = this.measureGeometry.getToVertex(0, 1);
} else {
measureTextStyle.setTextDx(Quantities.getQuantity(-7, CustomUnits.PIXEL));
measureTextStyle.setTextDy(Quantities.getQuantity(-2, CustomUnits.PIXEL));
measureTextStyle.setTextPlacementType("vertex(n)");
measureTextStyle.setTextVerticalAlignment("top");
textPoint = this.measureGeometry.getToVertex(0);
}
TextStyleRenderer.renderText(viewport, graphics, this.measureLabel, textPoint, measureTextStyle);
}
}
drawXorGeometry(graphics);
}
use of com.revolsys.geometry.model.Polygon 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;
}
Aggregations