Search in sources :

Example 81 with BoundingBox

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

the class GeoreferencedImage method drawImage.

default void drawImage(final Graphics2D graphics, final BoundingBox viewBoundingBox, final int viewWidth, final int viewHeight, final boolean useTransform, final Object interpolationMethod) {
    final BoundingBox imageBoundingBox = getBoundingBox();
    if (viewBoundingBox.intersects(imageBoundingBox) && viewWidth > 0 && viewHeight > 0) {
        final RenderedImage renderedImage = getRenderedImage();
        drawRenderedImage(renderedImage, graphics, viewBoundingBox, viewWidth, viewHeight, useTransform, interpolationMethod);
    }
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) RenderedImage(java.awt.image.RenderedImage)

Example 82 with BoundingBox

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

the class PdfUtil method getViewportBoundingBox.

public static BoundingBox getViewportBoundingBox(final COSDictionary viewport) {
    if (hasNameValue(viewport, "Type", "Viewport")) {
        final COSDictionary measure = PdfUtil.getDictionary(viewport, "Measure");
        if (PdfUtil.hasNameValue(measure, "Type", "Measure")) {
            if (PdfUtil.hasNameValue(measure, "Subtype", "GEO")) {
                final COSDictionary gcs = PdfUtil.getDictionary(measure, "GCS");
                if (gcs != null) {
                    GeometryFactory geometryFactory = GeometryFactory.DEFAULT_3D;
                    final int srid = gcs.getInt("EPSG");
                    if (srid == -1) {
                        final String wkt = gcs.getString("WKT");
                        if (Property.hasValue(wkt)) {
                            geometryFactory = GeometryFactory.floating3d(wkt);
                        }
                    } else {
                        geometryFactory = GeometryFactory.floating3d(srid);
                    }
                    final GeometryFactory geoGeometryFactory = geometryFactory.getGeographicGeometryFactory();
                    BoundingBox boundingBox = geometryFactory.newBoundingBoxEmpty();
                    final COSArray geoPoints = PdfUtil.findArray(measure, "GPTS");
                    for (int i = 0; i < geoPoints.size(); i++) {
                        final float lat = PdfUtil.getFloat(geoPoints, i++);
                        final float lon = PdfUtil.getFloat(geoPoints, i);
                        final Point geoPoint = geoGeometryFactory.point(lon, lat);
                        boundingBox = boundingBox.expandToInclude(geoPoint);
                    }
                    return boundingBox;
                }
            }
        }
    }
    return BoundingBox.empty();
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) COSDictionary(org.apache.pdfbox.cos.COSDictionary) COSArray(org.apache.pdfbox.cos.COSArray) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 83 with BoundingBox

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

the class ShapefileGeometryUtil method writePolyline.

private void writePolyline(final EndianOutput out, final Geometry geometry, final int shapeType, final int wordsPerPoint) throws IOException {
    if (geometry instanceof Lineal) {
        final int numCoordinates = geometry.getVertexCount();
        final int numGeometries = geometry.getGeometryCount();
        final BoundingBox envelope = geometry.getBoundingBox();
        if (this.writeLength) {
            // final int recordLength = ((3 + numGeometries) * BYTES_IN_INT + (4 + 2
            // * numCoordinates)
            // * BYTES_IN_DOUBLE) / 2;
            final int recordLength = 22 + numGeometries * 2 + numCoordinates * wordsPerPoint;
            out.writeInt(recordLength);
        }
        out.writeLEInt(shapeType);
        writeEnvelope(out, envelope);
        out.writeLEInt(numGeometries);
        out.writeLEInt(numCoordinates);
        writePolylinePartIndexes(out, geometry);
        writeXYCoordinates(out, geometry);
    } else {
        throw new IllegalArgumentException("Expecting Lineal geometry got " + geometry.getGeometryType() + "\n" + geometry);
    }
}
Also used : Lineal(com.revolsys.geometry.model.Lineal) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point)

Example 84 with BoundingBox

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

the class TriangulationVisualization method displayTin.

public static void displayTin(final TriangulatedIrregularNetwork tin) {
    BoundingBox boundingBox = tin.getBoundingBox();
    double mapWidth = boundingBox.getWidth() + 4;
    double mapHeight = boundingBox.getHeight() + 4;
    if (mapHeight > mapWidth) {
        boundingBox = boundingBox.expand((mapHeight - mapWidth) / 2, 0);
        mapWidth = boundingBox.getWidth();
    } else if (mapHeight < mapWidth) {
        boundingBox = boundingBox.expand(0, (mapWidth - mapHeight) / 2);
        mapHeight = boundingBox.getHeight();
    }
    final AffineTransform transform = new AffineTransform();
    final double pixelsPerXUnit = 800 / mapWidth;
    final double pixelsPerYUnit = -800 / mapHeight;
    final double originX = boundingBox.getMinX() - 2;
    final double originY = boundingBox.getMaxY() + 2;
    transform.concatenate(AffineTransform.getScaleInstance(pixelsPerXUnit, pixelsPerYUnit));
    transform.concatenate(AffineTransform.getTranslateInstance(-originX, -originY));
    SwingUtilities.invokeLater(() -> {
        final JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(850, 850);
        frame.setVisible(true);
        frame.setLayout(new BorderLayout());
        frame.add(new JPanel() {

            /**
             */
            private static final long serialVersionUID = 1L;

            @Override
            public void paint(final Graphics graphics) {
                final Graphics2D g2 = (Graphics2D) graphics;
                g2.setPaint(WebColors.White);
                g2.fillRect(0, 0, 800, 800);
                final AffineTransform oldTransform = g2.getTransform();
                g2.transform(transform);
                synchronized (tin) {
                    g2.setStroke(new BasicStroke((float) (1 / pixelsPerXUnit)));
                    tin.forEachTriangle((triangle) -> {
                        g2.setPaint(WebColors.newAlpha(WebColors.Aqua, 25));
                        g2.fill(triangle);
                        g2.setColor(WebColors.Black);
                        g2.draw(triangle);
                    });
                    if (showCircumcircle) {
                        tin.forEachTriangle((triangle) -> {
                            final double x1 = triangle.getX(1);
                            final double x2 = triangle.getY(1);
                            final double[] centre = Triangle.getCircumcentreCoordinates(triangle.getX(0), triangle.getY(0), x1, x2, triangle.getX(2), triangle.getY(2));
                            final double centreX = centre[0];
                            final double centreY = centre[1];
                            final double size = 7;
                            final double half = size / 2;
                            final Ellipse2D.Double shape = new Ellipse2D.Double(centreX - half / pixelsPerXUnit, centreY - half / pixelsPerXUnit, size / pixelsPerXUnit, size / pixelsPerXUnit);
                            g2.setPaint(WebColors.Yellow);
                            g2.fill(shape);
                            g2.setColor(WebColors.Black);
                            g2.draw(shape);
                        });
                        tin.forEachTriangle((triangle) -> {
                            final double x1 = triangle.getX(1);
                            final double x2 = triangle.getY(1);
                            final double[] centre = Triangle.getCircumcentreCoordinates(triangle.getX(0), triangle.getY(0), x1, x2, triangle.getX(2), triangle.getY(2));
                            final Circle circle = triangle.getCircumcircle();
                            final double centreX = centre[0];
                            final double centreY = centre[1];
                            final double radius = circle.getRadius();
                            final Ellipse2D ellipse = new Ellipse2D.Double(centreX - radius, centreY - radius, radius * 2, radius * 2);
                            g2.setColor(WebColors.Red);
                            g2.draw(ellipse);
                        });
                    }
                // for (int vertexIndex = 0; vertexIndex < tin.getVertexCount(); vertexIndex++) {
                // final Point point = tin.getVertex(vertexIndex);
                // final double x = point.getX();
                // final double y = point.getY();
                // final double size = 7;
                // final double half = size / 2;
                // final Ellipse2D.Double shape = new Ellipse2D.Double(x - half / pixelsPerXUnit,
                // y - half / pixelsPerXUnit, size / pixelsPerXUnit, size / pixelsPerXUnit);
                // g2.setPaint(WebColors.Yellow);
                // g2.fill(shape);
                // g2.setColor(WebColors.Black);
                // g2.draw(shape);
                // }
                // {
                // final Point point = pointHolder.getValue();
                // if (point != null) {
                // g2.setPaint(WebColors.Red);
                // final double x = point.getX();
                // final double y = point.getY();
                // final double size = 9;
                // final double half = size / 2;
                // g2.fill(new Ellipse2D.Double(x - half / pixelsPerXUnit, y - half / pixelsPerXUnit,
                // size / pixelsPerXUnit, size / pixelsPerXUnit));
                // }
                // }
                // g2.setTransform(oldTransform);
                // g2.translate(0, 800);
                // g2.setPaint(WebColors.Green);
                // for (int vertexIndex = 0; vertexIndex < tin.getVertexCount(); vertexIndex++) {
                // final Point point = tin.getVertex(vertexIndex);
                // final double x = point.getX();
                // final double y = point.getY();
                // final int screenX = (int)((x + 2) * pixelsPerXUnit);
                // final int screenY = (int)((y + 2) * pixelsPerYUnit);
                // g2.drawString(Integer.toString(vertexIndex), screenX + 5, screenY);
                // }
                }
            }
        }, BorderLayout.CENTER);
    });
}
Also used : BasicStroke(java.awt.BasicStroke) LasPointCloud(com.revolsys.elevation.cloud.las.LasPointCloud) PathResource(com.revolsys.spring.resource.PathResource) AffineTransform(java.awt.geom.AffineTransform) ArrayList(java.util.ArrayList) WebColors(com.revolsys.awt.WebColors) List(java.util.List) SwingUtilities(javax.swing.SwingUtilities) TriangulatedIrregularNetwork(com.revolsys.elevation.tin.TriangulatedIrregularNetwork) Ellipse2D(java.awt.geom.Ellipse2D) Triangle(com.revolsys.geometry.model.Triangle) Graphics2D(java.awt.Graphics2D) PointCloud(com.revolsys.elevation.cloud.PointCloud) Circle(com.revolsys.geometry.model.impl.Circle) Graphics(java.awt.Graphics) QuadEdgeDelaunayTinBuilder(com.revolsys.elevation.tin.quadedge.QuadEdgeDelaunayTinBuilder) BasicStroke(java.awt.BasicStroke) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) JPanel(javax.swing.JPanel) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) JPanel(javax.swing.JPanel) Circle(com.revolsys.geometry.model.impl.Circle) Ellipse2D(java.awt.geom.Ellipse2D) Graphics2D(java.awt.Graphics2D) Graphics(java.awt.Graphics) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) BoundingBox(com.revolsys.geometry.model.BoundingBox) AffineTransform(java.awt.geom.AffineTransform)

Example 85 with BoundingBox

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

the class CreateRandomShapeFunctions method randomSegmentsInGrid.

public static Geometry randomSegmentsInGrid(final Geometry g, final int nPts) {
    final BoundingBox env = FunctionsUtil.getEnvelopeOrDefault(g);
    final GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
    final int nCell = (int) Math.sqrt(nPts) + 1;
    final double xLen = env.getWidth() / nCell;
    final double yLen = env.getHeight() / nCell;
    final List lines = new ArrayList();
    for (int i = 0; i < nCell; i++) {
        for (int j = 0; j < nCell; j++) {
            final double x0 = env.getMinX() + i * xLen + xLen * Math.random();
            final double y0 = env.getMinY() + j * yLen + yLen * Math.random();
            final double x1 = env.getMinX() + i * xLen + xLen * Math.random();
            final double y1 = env.getMinY() + j * yLen + yLen * Math.random();
            lines.add(geomFact.lineString(2, x0, y0, x1, y1));
        }
    }
    return geomFact.buildGeometry(lines);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point)

Aggregations

BoundingBox (com.revolsys.geometry.model.BoundingBox)307 Point (com.revolsys.geometry.model.Point)83 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)76 ArrayList (java.util.ArrayList)45 Geometry (com.revolsys.geometry.model.Geometry)41 LineString (com.revolsys.geometry.model.LineString)26 List (java.util.List)26 BoundingBoxDoubleXY (com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)19 Polygon (com.revolsys.geometry.model.Polygon)14 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)14 Project (com.revolsys.swing.map.layer.Project)14 CreateListVisitor (com.revolsys.visitor.CreateListVisitor)12 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)11 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)11 Edge (com.revolsys.geometry.graph.Edge)10 HashMap (java.util.HashMap)10 Record (com.revolsys.record.Record)9 Graphics2D (java.awt.Graphics2D)9 MapEx (com.revolsys.collection.map.MapEx)8 LinearRing (com.revolsys.geometry.model.LinearRing)8