Search in sources :

Example 96 with PointDoubleXY

use of com.revolsys.geometry.model.impl.PointDoubleXY in project com.revolsys.open by revolsys.

the class AbstractGeoreferencedImage method loadAuxXmlFile.

protected void loadAuxXmlFile(final long modifiedTime) {
    final Resource resource = getImageResource();
    final String extension = resource.getFileNameExtension();
    final Resource auxFile = resource.newResourceChangeExtension(extension + ".aux.xml");
    if (auxFile.exists() && auxFile.getLastModified() > modifiedTime) {
        loadWorldFileX();
        final int[] dpi = getDpi();
        try {
            int srid = 0;
            final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            final DocumentBuilder builder = factory.newDocumentBuilder();
            final InputStream in = auxFile.getInputStream();
            try {
                final Document doc = builder.parse(in);
                final NodeList spatialReferences = doc.getElementsByTagName("SpatialReference");
                for (int i = 0; i < spatialReferences.getLength() && srid == 0; i++) {
                    final Node spatialReference = spatialReferences.item(i);
                    Element sridElement = DomUtil.getFirstChildElement(spatialReference, "LatestWKID");
                    if (sridElement == null) {
                        sridElement = DomUtil.getFirstChildElement(spatialReference, "WKID");
                    }
                    if (sridElement != null) {
                        srid = DomUtil.getInteger(sridElement);
                    }
                }
                GeometryFactory geometryFactory = GeometryFactory.floating2d(srid);
                if (srid == 0) {
                    final NodeList srsList = doc.getElementsByTagName("SRS");
                    for (int i = 0; i < srsList.getLength() && srid == 0; i++) {
                        final Node srsNode = srsList.item(i);
                        final String srsWkt = srsNode.getTextContent();
                        geometryFactory = GeometryFactory.floating2d(srsWkt);
                    }
                }
                setGeometryFactory(geometryFactory);
                final List<Double> sourceControlPoints = DomUtil.getDoubleList(doc, "SourceGCPs");
                final List<Double> targetControlPoints = DomUtil.getDoubleList(doc, "TargetGCPs");
                if (sourceControlPoints.size() > 0 && targetControlPoints.size() > 0) {
                    final List<MappedLocation> tiePoints = new ArrayList<>();
                    for (int i = 0; i < sourceControlPoints.size() && i < targetControlPoints.size(); i += 2) {
                        final double imageX = sourceControlPoints.get(i) * dpi[0];
                        final double imageY = sourceControlPoints.get(i + 1) * dpi[1];
                        final Point sourcePixel = new PointDoubleXY(imageX, imageY);
                        final double x = targetControlPoints.get(i);
                        final double y = targetControlPoints.get(i + 1);
                        final Point targetPoint = geometryFactory.point(x, y);
                        final MappedLocation tiePoint = new MappedLocation(sourcePixel, targetPoint);
                        tiePoints.add(tiePoint);
                    }
                    setTiePoints(tiePoints);
                }
            } finally {
                FileUtil.closeSilent(in);
            }
        } catch (final Throwable e) {
            Logs.error(this, "Unable to read: " + auxFile, e);
        }
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ImageInputStream(javax.imageio.stream.ImageInputStream) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Resource(com.revolsys.spring.resource.Resource) ArrayList(java.util.ArrayList) PropertyChangeArrayList(com.revolsys.collection.PropertyChangeArrayList) Point(com.revolsys.geometry.model.Point) Document(org.w3c.dom.Document) Point(com.revolsys.geometry.model.Point) DocumentBuilder(javax.xml.parsers.DocumentBuilder) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 97 with PointDoubleXY

use of com.revolsys.geometry.model.impl.PointDoubleXY in project com.revolsys.open by revolsys.

the class ConvexHullTest method testManyIdenticalPoints.

public void testManyIdenticalPoints() throws Exception {
    final List<Point> points = new ArrayList<>();
    for (int i = 0; i < 99; i++) {
        points.add(new PointDoubleXY(0.0, 0));
    }
    points.add(new PointDoubleXY(1.0, 1));
    final Geometry actualGeometry = ConvexHull.convexHull(this.geometryFactory, points);
    final Geometry expectedGeometry = this.geometryFactory.geometry("LINESTRING(0 0,1 1)");
    assertTrue(expectedGeometry.equals(2, actualGeometry));
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Point(com.revolsys.geometry.model.Point)

Example 98 with PointDoubleXY

use of com.revolsys.geometry.model.impl.PointDoubleXY in project com.revolsys.open by revolsys.

the class RandomOffsetLineStringGenerator method generate.

public Geometry generate(final GeometryFactory fact) {
    this.pts = new Point[this.numPts];
    this.pts[0] = GeometryFactory.DEFAULT_3D.point();
    final double ang = Math.PI * Math.random();
    this.endPoint = new PointDoubleXY(this.maxSegLen * Math.cos(ang), this.maxSegLen * Math.sin(ang));
    this.pts[this.numPts - 1] = this.endPoint;
    int interval = this.numPts / 2;
    while (interval >= 1) {
        newRandomOffsets(interval);
        interval /= 2;
    }
    return fact.lineString(this.pts);
}
Also used : PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Point(com.revolsys.geometry.model.Point)

Example 99 with PointDoubleXY

use of com.revolsys.geometry.model.impl.PointDoubleXY in project com.revolsys.open by revolsys.

the class TestPerfDistanceGeomPair method newCircles.

Geometry[] newCircles(final int nPts) {
    final GeometricShapeFactory gsf = new GeometricShapeFactory();
    gsf.setCentre(new PointDoubleXY(0, 0));
    gsf.setSize(100);
    gsf.setNumPoints(nPts);
    final Polygon gRect = gsf.newCircle();
    gsf.setCentre(new PointDoubleXY(0, this.separationDist));
    final Polygon gRect2 = gsf.newCircle();
    return new Geometry[] { gRect, gRect2 };
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometricShapeFactory(com.revolsys.geometry.util.GeometricShapeFactory) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Polygon(com.revolsys.geometry.model.Polygon)

Example 100 with PointDoubleXY

use of com.revolsys.geometry.model.impl.PointDoubleXY in project com.revolsys.open by revolsys.

the class TestPerfDistanceLinesPoints method newDiagonalCircles.

Geometry newDiagonalCircles(final double extent, final int nSegs) {
    final Polygon[] circles = new Polygon[nSegs];
    final double inc = extent / nSegs;
    for (int i = 0; i < nSegs; i++) {
        final double ord = i * inc;
        final Point p = new PointDoubleXY(ord, ord);
        final Geometry pt = geomFact.point(p);
        circles[i] = (Polygon) pt.buffer(inc / 2);
    }
    return geomFact.polygonal(circles);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Aggregations

PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)138 Point (com.revolsys.geometry.model.Point)91 Geometry (com.revolsys.geometry.model.Geometry)36 ArrayList (java.util.ArrayList)19 BoundingBox (com.revolsys.geometry.model.BoundingBox)10 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)10 List (java.util.List)9 LineString (com.revolsys.geometry.model.LineString)8 Polygon (com.revolsys.geometry.model.Polygon)6 RobustLineIntersector (com.revolsys.geometry.algorithm.RobustLineIntersector)5 LengthIndexedLine (com.revolsys.geometry.linearref.LengthIndexedLine)5 LinearLocation (com.revolsys.geometry.linearref.LinearLocation)5 LocationIndexedLine (com.revolsys.geometry.linearref.LocationIndexedLine)5 LineSegmentDouble (com.revolsys.geometry.model.segment.LineSegmentDouble)5 PointDoubleXYZ (com.revolsys.geometry.model.impl.PointDoubleXYZ)4 LineSegment (com.revolsys.geometry.model.segment.LineSegment)4 AffineTransformation (com.revolsys.geometry.model.util.AffineTransformation)4 GeometricShapeFactory (com.revolsys.geometry.util.GeometricShapeFactory)4 Vertex (com.revolsys.geometry.model.vertex.Vertex)3 KdNode (com.revolsys.geometry.index.kdtree.KdNode)2