Package com.vividsolutions.jts.operation.distance

Examples of com.vividsolutions.jts.operation.distance.DistanceOp


    try {
      Geometry A = wktRdr.read(wktA);
      Geometry B = wktRdr.read(wktB);
      System.out.println("Geometry A: " + A);
      System.out.println("Geometry B: " + B);
      DistanceOp distOp = new DistanceOp(A, B);

      double distance = distOp.distance();
      System.out.println("Distance = " + distance);

      Coordinate[] closestPt = distOp.nearestPoints();
      LineString closestPtLine = fact.createLineString(closestPt);
      System.out.println("Closest points: " + closestPtLine
                         + " (distance = " + closestPtLine.getLength() + ")");
    }
    catch (Exception ex) {
View Full Code Here


                double nearestDistance = 9e9;
                double nearestBearing = 0;
                for (Iterator sItr = featuresCheck.iterator(); sItr.hasNext();) {
                    Feature f = (Feature)sItr.next();
                    if (f.getDefaultGeometry() == null) continue;
                    DistanceOp op = new DistanceOp(request.getPoint(), f.getDefaultGeometry());
                    Coordinate[] co = op.closestPoints();
                    Measure m = DefaultGeographicCRS.WGS84.distance(new double[] { co[0].x, co[0].y, }, new double[] { co[1].x, co[1].y, });
                    if (m.doubleValue() > nearestDistance) continue;
                    nearestFeature = f;
                    nearestDistance = m.doubleValue();
                    nearestBearing = calcBearing(co);
View Full Code Here

                featureIterator = featureCollection.features();
                while (featureIterator.hasNext()) {
                    SimpleFeature f = (SimpleFeature) featureIterator.next();
                    if (f.getDefaultGeometryProperty().getValue() == null)
                        continue;
                    DistanceOp op = new DistanceOp(point, (Geometry) f.getDefaultGeometryProperty()
                            .getValue());
                    Coordinate[] co = op.closestPoints();
                    double[] co0 = new double[] { co[0].x, co[0].y, };
                    double[] co1 = new double[] { co[1].x, co[1].y, };
                    double[] geo0 = new double[2];
                    double[] geo1 = new double[2];
                    crsTransform.transform(co0, 0, geo0, 0, 1);
View Full Code Here

            try {
                while (featureIterator.hasNext()) {
                    SimpleFeature f = (SimpleFeature) featureIterator.next();
                    if (f.getDefaultGeometryProperty().getValue() == null)
                        continue;
                    DistanceOp op = new DistanceOp(point, (Geometry) f.getDefaultGeometryProperty()
                            .getValue());
                    Coordinate[] co = op.closestPoints();
                    double[] co0 = new double[] { co[0].x, co[0].y, };
                    double[] co1 = new double[] { co[1].x, co[1].y, };
                    double[] geo0 = new double[2];
                    double[] geo1 = new double[2];
                    crsTransform.transform(co0, 0, geo0, 0, 1);
View Full Code Here

            try {
                while (featureIterator.hasNext()) {
                    SimpleFeature f = (SimpleFeature) featureIterator.next();
                    if (f.getDefaultGeometryProperty().getValue() == null)
                        continue;
                    DistanceOp op = new DistanceOp(point, (Geometry) f.getDefaultGeometryProperty()
                            .getValue());
                    Coordinate[] co = op.closestPoints();
                    double[] co0 = new double[] { co[0].x, co[0].y, };
                    double[] co1 = new double[] { co[1].x, co[1].y, };
                    double[] geo0 = new double[2];
                    double[] geo1 = new double[2];
                    crsTransform.transform(co0, 0, geo0, 0, 1);
View Full Code Here

                featureIterator = featureCollection.iterator();
                while (featureIterator.hasNext()) {
                    SimpleFeature f = (SimpleFeature) featureIterator.next();
                    if (f.getDefaultGeometryProperty().getValue() == null)
                        continue;
                    DistanceOp op = new DistanceOp(point, (Geometry) f.getDefaultGeometryProperty()
                            .getValue());
                    Coordinate[] co = op.closestPoints();
                    double[] co0 = new double[] { co[0].x, co[0].y, };
                    double[] co1 = new double[] { co[1].x, co[1].y, };
                    double[] geo0 = new double[2];
                    double[] geo1 = new double[2];
                    crsTransform.transform(co0, 0, geo0, 0, 1);
View Full Code Here

                featureIterator = featureCollection.iterator();
                while (featureIterator.hasNext()) {
                    SimpleFeature f = (SimpleFeature) featureIterator.next();
                    if (f.getDefaultGeometryProperty().getValue() == null)
                        continue;
                    DistanceOp op = new DistanceOp(point, (Geometry) f.getDefaultGeometryProperty()
                            .getValue());
                    Coordinate[] co = op.closestPoints();
                    double[] co0 = new double[] { co[0].x, co[0].y, };
                    double[] co1 = new double[] { co[1].x, co[1].y, };
                    double[] geo0 = new double[2];
                    double[] geo1 = new double[2];
                    crsTransform.transform(co0, 0, geo0, 0, 1);
View Full Code Here

    @Test
    public void testDistance() throws ParseException {
        WKTReader wktRdr = new WKTReader();
        Geometry A = wktRdr.read("POINT(40.00 30.00 )");
        Geometry B = wktRdr.read("POINT(40.00 40.00 )");
        DistanceOp distOp = new DistanceOp(A, B);
        assertEquals(10.0, distOp.distance(), 0);
    }
View Full Code Here

    doNearestPointsTest("POLYGON ((76 185, 125 283, 331 276, 324 122, 177 70, 184 155, 69 123, 76 185), (267 237, 148 248, 135 185, 223 189, 251 151, 286 183, 267 237))", "LINESTRING (120 215, 185 224, 209 207, 238 222, 254 186)", 0.0, new Coordinate(120, 215), new Coordinate(120, 215));
  }

  private void doNearestPointsTest(String wkt0, String wkt1, double distance,
                                   Coordinate p0, Coordinate p1) throws ParseException {
    DistanceOp op = new DistanceOp(new WKTReader().read(wkt0), new WKTReader().read(wkt1));
    double tolerance = 1E-10;
    assertEquals(distance, op.nearestPoints()[0].distance(op.nearestPoints()[1]), tolerance);
    assertEquals(p0.x, op.nearestPoints()[0].x, tolerance);
    assertEquals(p0.y, op.nearestPoints()[0].y, tolerance);
    assertEquals(p1.x, op.nearestPoints()[1].x, tolerance);
    assertEquals(p1.y, op.nearestPoints()[1].y, tolerance);   
 
View Full Code Here

TOP

Related Classes of com.vividsolutions.jts.operation.distance.DistanceOp

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.