@Test public void test() throws NoSuchAuthorityCodeException, FactoryException, TransformException { final CoordinateReferenceSystem crs = CRS.decode("EPSG:4326", true); final GeometryCalculations calculator = new GeometryCalculations(crs); List<Geometry> geos = calculator.buildSurroundingGeometries( new double[] {50000, 50000}, Units.METRE, new Coordinate(30, 30)); assertEquals(1, geos.size()); Geometry geo = geos.get(0); double lastDist = Double.NaN; Coordinate lastCoord = null; for (final Coordinate coord : geo.getCoordinates()) { if (lastCoord != null) { final double dist = JTS.orthodromicDistance(lastCoord, coord, crs); assertEquals(Math.abs(dist), 100000, 500); } final double dist = JTS.orthodromicDistance(geo.getCentroid().getCoordinate(), coord, crs); if (!Double.isNaN(lastDist)) { assertTrue(Math.abs(dist - lastDist) < 200); } lastDist = dist; lastCoord = coord; } Envelope envelope = geo.getEnvelopeInternal(); assertTrue(envelope.getMaxX() > 30); assertTrue(envelope.getMinX() < 30); assertTrue(envelope.getMaxY() > 30); assertTrue(envelope.getMinX() < 30); geos = calculator.buildSurroundingGeometries( new double[] {100000, 100000}, Units.METRE, new Coordinate(179.9999999996, 0)); assertEquals(2, geos.size()); geo = geos.get(0); envelope = geo.getEnvelopeInternal(); assertTrue((envelope.getMaxX() < -179) && (envelope.getMaxX() > -180)); assertEquals(-180.0, envelope.getMinX(), 0.0000001); geo = geos.get(1); envelope = geo.getEnvelopeInternal(); assertTrue((envelope.getMinX() < 180) && (envelope.getMinX() > 179)); assertEquals(180.0, envelope.getMaxX(), 0.0000001); }
public List<Geometry> buildSurroundingGeometries( final double[] distances, final Unit<Length> unit, final Coordinate coordinate) { final List<Geometry> geos = new LinkedList<>(); final GeodeticCalculator geoCalc = new GeodeticCalculator(); geoCalc.setStartingGeographicPoint(coordinate.x, coordinate.y); try { geoCalc.setDirection(0, unit.getConverterTo(Units.METRE).convert(distances[1])); final DirectPosition north = geoCalc.getDestinationPosition(); geoCalc.setDirection(90, unit.getConverterTo(Units.METRE).convert(distances[0])); final DirectPosition east = geoCalc.getDestinationPosition(); geoCalc.setStartingGeographicPoint(coordinate.x, coordinate.y); geoCalc.setDirection(-90, unit.getConverterTo(Units.METRE).convert(distances[0])); final DirectPosition west = geoCalc.getDestinationPosition(); geoCalc.setDirection(180, unit.getConverterTo(Units.METRE).convert(distances[1])); final DirectPosition south = geoCalc.getDestinationPosition(); final double x1 = west.getOrdinate(0); final double x2 = east.getOrdinate(0); final double y1 = north.getOrdinate(1); final double y2 = south.getOrdinate(1); handleBoundaries(geos, coordinate, x1, x2, y1, y2); return geos; } catch (final TransformException ex) { LOGGER.error("Unable to build geometry", ex); } return null; }
GeometryCalculations { public List<Geometry> buildSurroundingGeometries( final double[] distances, final Unit<Length> unit, final Coordinate coordinate) { final List<Geometry> geos = new LinkedList<>(); final GeodeticCalculator geoCalc = new GeodeticCalculator(); geoCalc.setStartingGeographicPoint(coordinate.x, coordinate.y); try { geoCalc.setDirection(0, unit.getConverterTo(Units.METRE).convert(distances[1])); final DirectPosition north = geoCalc.getDestinationPosition(); geoCalc.setDirection(90, unit.getConverterTo(Units.METRE).convert(distances[0])); final DirectPosition east = geoCalc.getDestinationPosition(); geoCalc.setStartingGeographicPoint(coordinate.x, coordinate.y); geoCalc.setDirection(-90, unit.getConverterTo(Units.METRE).convert(distances[0])); final DirectPosition west = geoCalc.getDestinationPosition(); geoCalc.setDirection(180, unit.getConverterTo(Units.METRE).convert(distances[1])); final DirectPosition south = geoCalc.getDestinationPosition(); final double x1 = west.getOrdinate(0); final double x2 = east.getOrdinate(0); final double y1 = north.getOrdinate(1); final double y2 = south.getOrdinate(1); handleBoundaries(geos, coordinate, x1, x2, y1, y2); return geos; } catch (final TransformException ex) { LOGGER.error("Unable to build geometry", ex); } return null; } }
GeometryCalculations { public List<Geometry> buildSurroundingGeometries( final double[] distances, final Unit<Length> unit, final Coordinate coordinate) { final List<Geometry> geos = new LinkedList<>(); final GeodeticCalculator geoCalc = new GeodeticCalculator(); geoCalc.setStartingGeographicPoint(coordinate.x, coordinate.y); try { geoCalc.setDirection(0, unit.getConverterTo(Units.METRE).convert(distances[1])); final DirectPosition north = geoCalc.getDestinationPosition(); geoCalc.setDirection(90, unit.getConverterTo(Units.METRE).convert(distances[0])); final DirectPosition east = geoCalc.getDestinationPosition(); geoCalc.setStartingGeographicPoint(coordinate.x, coordinate.y); geoCalc.setDirection(-90, unit.getConverterTo(Units.METRE).convert(distances[0])); final DirectPosition west = geoCalc.getDestinationPosition(); geoCalc.setDirection(180, unit.getConverterTo(Units.METRE).convert(distances[1])); final DirectPosition south = geoCalc.getDestinationPosition(); final double x1 = west.getOrdinate(0); final double x2 = east.getOrdinate(0); final double y1 = north.getOrdinate(1); final double y2 = south.getOrdinate(1); handleBoundaries(geos, coordinate, x1, x2, y1, y2); return geos; } catch (final TransformException ex) { LOGGER.error("Unable to build geometry", ex); } return null; } GeometryCalculations(final CoordinateReferenceSystem crs); }
GeometryCalculations { public List<Geometry> buildSurroundingGeometries( final double[] distances, final Unit<Length> unit, final Coordinate coordinate) { final List<Geometry> geos = new LinkedList<>(); final GeodeticCalculator geoCalc = new GeodeticCalculator(); geoCalc.setStartingGeographicPoint(coordinate.x, coordinate.y); try { geoCalc.setDirection(0, unit.getConverterTo(Units.METRE).convert(distances[1])); final DirectPosition north = geoCalc.getDestinationPosition(); geoCalc.setDirection(90, unit.getConverterTo(Units.METRE).convert(distances[0])); final DirectPosition east = geoCalc.getDestinationPosition(); geoCalc.setStartingGeographicPoint(coordinate.x, coordinate.y); geoCalc.setDirection(-90, unit.getConverterTo(Units.METRE).convert(distances[0])); final DirectPosition west = geoCalc.getDestinationPosition(); geoCalc.setDirection(180, unit.getConverterTo(Units.METRE).convert(distances[1])); final DirectPosition south = geoCalc.getDestinationPosition(); final double x1 = west.getOrdinate(0); final double x2 = east.getOrdinate(0); final double y1 = north.getOrdinate(1); final double y2 = south.getOrdinate(1); handleBoundaries(geos, coordinate, x1, x2, y1, y2); return geos; } catch (final TransformException ex) { LOGGER.error("Unable to build geometry", ex); } return null; } GeometryCalculations(final CoordinateReferenceSystem crs); List<Geometry> buildSurroundingGeometries(
      final double[] distances,
      final Unit<Length> unit,
      final Coordinate coordinate); }
GeometryCalculations { public List<Geometry> buildSurroundingGeometries( final double[] distances, final Unit<Length> unit, final Coordinate coordinate) { final List<Geometry> geos = new LinkedList<>(); final GeodeticCalculator geoCalc = new GeodeticCalculator(); geoCalc.setStartingGeographicPoint(coordinate.x, coordinate.y); try { geoCalc.setDirection(0, unit.getConverterTo(Units.METRE).convert(distances[1])); final DirectPosition north = geoCalc.getDestinationPosition(); geoCalc.setDirection(90, unit.getConverterTo(Units.METRE).convert(distances[0])); final DirectPosition east = geoCalc.getDestinationPosition(); geoCalc.setStartingGeographicPoint(coordinate.x, coordinate.y); geoCalc.setDirection(-90, unit.getConverterTo(Units.METRE).convert(distances[0])); final DirectPosition west = geoCalc.getDestinationPosition(); geoCalc.setDirection(180, unit.getConverterTo(Units.METRE).convert(distances[1])); final DirectPosition south = geoCalc.getDestinationPosition(); final double x1 = west.getOrdinate(0); final double x2 = east.getOrdinate(0); final double y1 = north.getOrdinate(1); final double y2 = south.getOrdinate(1); handleBoundaries(geos, coordinate, x1, x2, y1, y2); return geos; } catch (final TransformException ex) { LOGGER.error("Unable to build geometry", ex); } return null; } GeometryCalculations(final CoordinateReferenceSystem crs); List<Geometry> buildSurroundingGeometries(
      final double[] distances,
      final Unit<Length> unit,
      final Coordinate coordinate);  }