use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class MeasureOverlay method setMeasureGeometry.
public void setMeasureGeometry(Geometry measureGeometry) {
if (measureGeometry == null) {
measureGeometry = EMPTY_GEOMETRY;
}
if (measureGeometry != this.measureGeometry) {
this.measureGeometry = measureGeometry;
if (measureGeometry == null) {
this.measureLabel = "";
} else {
Unit<Length> lengthUnit = Units.METRE;
final CoordinateSystem coordinateSystem = measureGeometry.getCoordinateSystem();
if (coordinateSystem instanceof ProjectedCoordinateSystem) {
lengthUnit = coordinateSystem.getLengthUnit();
}
final double length = measureGeometry.getLength(lengthUnit);
@SuppressWarnings("unchecked") final Unit<Area> areaUnit = (Unit<Area>) lengthUnit.multiply(lengthUnit);
final double area = measureGeometry.getArea(areaUnit);
final String unitString = lengthUnit.toString();
synchronized (MEASURE_FORMAT) {
final StringBuilder label = new StringBuilder();
final String lengthString = MEASURE_FORMAT.format(Doubles.makePrecise(100, length));
label.append(lengthString);
label.append(unitString);
if (this.measureDataType == DataTypes.POLYGON && measureGeometry instanceof Polygon) {
final String areaString = MEASURE_FORMAT.format(Doubles.makePrecise(100, area));
label.append(" \n");
label.append(areaString);
label.append(unitString);
label.append('\u00B2');
}
this.measureLabel = label.toString();
}
}
setXorGeometry(null);
}
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class GridLayerRenderer method render.
@Override
public void render(final Viewport2D viewport, final Cancellable cancellable, final GridLayer layer) {
try {
final double scaleForVisible = viewport.getScaleForVisible();
if (layer.isVisible(scaleForVisible)) {
final BoundingBox boundingBox = viewport.getBoundingBox();
final RectangularMapGrid grid = layer.getGrid();
final List<RectangularMapTile> tiles = grid.getTiles(boundingBox);
final Graphics2D graphics = viewport.getGraphics();
if (graphics != null) {
final Font font = graphics.getFont();
for (final RectangularMapTile tile : cancellable.cancellable(tiles)) {
final BoundingBox tileBoundingBox = tile.getBoundingBox();
final BoundingBox intersectBoundingBox = boundingBox.intersection(tileBoundingBox);
if (!intersectBoundingBox.isEmpty()) {
final GeometryFactory geometryFactory = viewport.getGeometryFactory();
final Polygon polygon = tile.getPolygon(geometryFactory, 50);
try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
viewport.drawGeometryOutline(polygon, this.geometryStyle);
}
try (BaseCloseable transformClosable = viewport.setUseModelCoordinates(false)) {
viewport.drawText(tile, polygon, this.textStyle);
}
}
graphics.setFont(font);
}
}
}
} catch (final IllegalArgumentException e) {
}
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class PointCloudLayerRenderer method render.
@Override
public void render(final Viewport2D viewport, final Cancellable cancellable, final PointCloudLayer layer) {
// TODO cancellable
final double scaleForVisible = viewport.getScaleForVisible();
if (layer.isVisible(scaleForVisible)) {
if (!layer.isEditable()) {
final PointCloud<?> pointCloud = layer.getPointCloud();
if (pointCloud != null) {
final BoundingBox boundingBox = layer.getBoundingBox();
final Graphics2D graphics = viewport.getGraphics();
if (graphics != null) {
try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(true)) {
final Polygon polygon = boundingBox.toPolygon(0);
viewport.drawGeometryOutline(polygon, STYLE_BOUNDING_BOX);
}
}
}
}
}
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class EditGeoreferencedImageOverlay method paintComponent.
@Override
protected void paintComponent(final Viewport2D viewport, final Graphics2D graphics) {
super.paintComponent(viewport, graphics);
final GeoreferencedImageLayer layer = this.layer;
final GeoreferencedImage image = this.image;
final BoundingBox moveImageBoundingBox = this.moveImageBoundingBox;
if (layer != null && layer.isVisible() && layer.isExists() && image != null) {
try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
final GeometryFactory viewportGeometryFactory = viewport.getGeometryFactory();
final boolean showOriginalImage = layer.isShowOriginalImage();
final BoundingBox imageBoundingBox = getImageBoundingBox();
BoundingBox boundingBox = imageBoundingBox;
BoundingBox outlineBoundingBox = boundingBox;
if (moveImageBoundingBox != null) {
if (showOriginalImage) {
boundingBox = moveImageBoundingBox;
}
outlineBoundingBox = moveImageBoundingBox;
}
final GeoreferencedImage cachedImage = getCachedImage(boundingBox);
GeoreferencedImageLayerRenderer.renderAlpha(viewport, graphics, cachedImage, false, layer.getOpacity() / 255.0, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
GeoreferencedImageLayerRenderer.renderDifferentCoordinateSystem(viewport, graphics, imageBoundingBox);
if (outlineBoundingBox != null && !outlineBoundingBox.isEmpty()) {
final Polygon imageBoundary = outlineBoundingBox.convert(getViewportGeometryFactory()).toPolygon(1);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
viewport.drawGeometryOutline(imageBoundary, STYLE_BOX_OUTLINE);
MarkerStyleRenderer.renderMarkerVertices(viewport, graphics, imageBoundary, STYLE_BOX_CORNER);
final List<MappedLocation> tiePoints = image.getTiePoints();
final int tiePointCount = tiePoints.size();
final GeometryFactory viewGeometryFactory = getGeometryFactory();
if (tiePointCount > 0) {
for (final MappedLocation mappedLocation : tiePoints) {
LineString line = mappedLocation.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
if (line != null) {
line = line.convertGeometry(viewportGeometryFactory);
try (BaseCloseable transformCloseable1 = viewport.setUseModelCoordinates(graphics, true)) {
TIE_POINT_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, line);
}
}
}
for (final MappedLocation mappedLocation : tiePoints) {
LineString line = mappedLocation.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
if (line != null) {
line = line.convertGeometry(viewportGeometryFactory);
TIE_POINT_VERTEX_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, line);
}
}
}
if (!showOriginalImage) {
final double width = image.getImageWidth() - 1;
final double height = image.getImageHeight() - 1;
final double[] targetCoordinates = MappedLocation.toModelCoordinates(image, boundingBox, true, 0, height, width, height, width, 0, 0, 0, 0, height);
final LineString line = viewGeometryFactory.lineString(2, targetCoordinates);
GeometryStyleRenderer.renderLineString(viewport, graphics, line, STYLE_IMAGE_LINE);
}
}
final MappedLocation moveTiePoint = getMoveTiePoint();
if (moveTiePoint != null) {
final LineString line = moveTiePoint.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
Vertex vertex;
if (this.moveTiePointSource) {
vertex = line.getVertex(0);
} else {
vertex = line.getToVertex(0);
}
TIE_POINT_CLOSE_VERTEX_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, vertex);
}
}
}
drawXorGeometry(graphics);
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class MarkerStyleRenderer method renderMarker.
public static void renderMarker(final Viewport2D viewport, final Geometry geometry, final MarkerStyle style) {
try (BaseCloseable transformClosable = viewport.setUseModelCoordinates(false)) {
@SuppressWarnings("deprecation") final Graphics2D graphics = viewport.getGraphics();
if (graphics != null && geometry != null) {
if ("vertices".equals(style.getMarkerPlacementType())) {
renderMarkerVertices(viewport, graphics, geometry, style);
} else if ("segments".equals(style.getMarkerPlacementType())) {
renderMarkerSegments(viewport, graphics, geometry, style);
} else {
for (int i = 0; i < geometry.getGeometryCount(); i++) {
final Geometry part = geometry.getGeometry(i);
if (part instanceof Point) {
final Point point = (Point) part;
renderMarker(viewport, graphics, point, style, 0);
} else if (part instanceof LineString) {
final LineString line = (LineString) part;
renderMarker(viewport, graphics, line, style);
} else if (part instanceof Polygon) {
final Polygon polygon = (Polygon) part;
renderMarker(viewport, graphics, polygon, style);
}
}
}
}
}
}
Aggregations