Example #1
0
 public static void computeDistance(LineString line, Coordinate pt, PointPairDistance ptDist) {
   LineSegment tempSegment = new LineSegment();
   Coordinate[] coords = line.getCoordinates();
   for (int i = 0; i < coords.length - 1; i++) {
     tempSegment.setCoordinates(coords[i], coords[i + 1]);
     // this is somewhat inefficient - could do better
     Coordinate closestPt = tempSegment.closestPoint(pt);
     ptDist.setMinimum(closestPt, pt);
   }
 }
Example #2
0
 public static void computeDistance(Geometry geom, Coordinate pt, PointPairDistance ptDist) {
   if (geom instanceof LineString) {
     computeDistance((LineString) geom, pt, ptDist);
   } else if (geom instanceof Polygon) {
     computeDistance((Polygon) geom, pt, ptDist);
   } else if (geom instanceof GeometryCollection) {
     GeometryCollection gc = (GeometryCollection) geom;
     for (int i = 0; i < gc.getNumGeometries(); i++) {
       Geometry g = gc.getGeometryN(i);
       computeDistance(g, pt, ptDist);
     }
   } else { // assume geom is Point
     ptDist.setMinimum(geom.getCoordinate(), pt);
   }
 }
Example #3
0
 public static void computeDistance(LineSegment segment, Coordinate pt, PointPairDistance ptDist) {
   Coordinate closestPt = segment.closestPoint(pt);
   ptDist.setMinimum(closestPt, pt);
 }