Java Code Examples for org.locationtech.jts.geom.Geometry#distance()

The following examples show how to use org.locationtech.jts.geom.Geometry#distance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSpatialDbsMain.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testReprojectFromDb() throws Exception {

    double w = 11.143413001499738;
    double e = 11.147502220729288;
    double s = 46.62897848892326;
    double n = 46.62981208577648;

    Envelope env = new Envelope(w, e, s, n);
    
    Envelope reprojected = db.reproject(env, 4326, 32632);
    double rw = reprojected.getMinX();
    double re = reprojected.getMaxX();
    double rs = reprojected.getMinY();
    double rn = reprojected.getMaxY();
    
    assertEquals(664076.6777860201, rw, 0.001);
    assertEquals(664387.1714802807, re, 0.001);
    assertEquals(5166166.626361137, rs, 0.001);
    assertEquals(5166267.775614383, rn, 0.001);
    
    
    
    WKTReader reader = new WKTReader();
    Geometry point = reader.read("POINT (11.143413001499738 46.62897848892326)");
    Geometry reprojectedGeom = db.reproject(point, 4326, 32632);
    Geometry expected = reader.read("POINT (664076.6777860201 5166166.626361137)");
    
    double distance = reprojectedGeom.distance(expected);
    assertEquals(0.0, distance, 0.00001);
    
}
 
Example 2
Source File: GeometryUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
/**
 * Convert meters to decimal degrees based on widest point
 *
 * @throws TransformException
 */
private static double distanceToDegrees(
    final CoordinateReferenceSystem crs,
    final Geometry geometry,
    final double meters) throws TransformException {
  final GeometryFactory factory = geometry.getFactory();
  return (geometry instanceof Point)
      ? geometry.distance(farthestPoint(crs, (Point) geometry, meters))
      : distanceToDegrees(
          crs,
          geometry.getEnvelopeInternal(),
          factory == null ? new GeometryFactory() : factory,
          meters);
}
 
Example 3
Source File: GeomWithinDistance.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public boolean apply(final Geometry geom1, final Geometry geom2) {
  return geom1.distance(geom2) <= radius;
}
 
Example 4
Source File: GeomDistance.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public Double call(final Geometry leftGeom, final Geometry rightGeom) throws Exception {
  return leftGeom.distance(rightGeom);
}