Last active
June 8, 2017 12:13
-
-
Save vpipkt/8bd2d06b895958a8148400355dbf54a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Geometry getGeodeticLineBuf(Geometry inline, int dist) { | |
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null ); | |
GeodeticCalculator calc = new GeodeticCalculator(DefaultGeographicCRS.WGS84); | |
Coordinate[] subsat_points = inline.getCoordinates(); | |
ArrayList<Coordinate> hull_right = new ArrayList<Coordinate>(); | |
ArrayList<Coordinate> hull_left = new ArrayList<Coordinate>(); | |
for (int i = 0; i < subsat_points.length-1; i++) { | |
calc.setStartingGeographicPoint(subsat_points[i].x,subsat_points[i].y); | |
calc.setDestinationGeographicPoint(subsat_points[i+1].x,subsat_points[i+1].y); | |
double angle = calc.getAzimuth(); | |
if (angle<=-90 ){angle = angle+180;} | |
if (angle>=90 ){angle = angle-180;} | |
calc.setStartingGeographicPoint(subsat_points[i].x,subsat_points[i].y); | |
calc.setDirection(angle+90,dist); | |
Point2D dest1 = calc.getDestinationGeographicPoint(); | |
hull_right.add(new Coordinate(dest1.getX(),dest1.getY(),0)); | |
calc.setDirection(angle-90, dist); | |
Point2D dest2 = calc.getDestinationGeographicPoint(); | |
hull_left.add(new Coordinate(dest2.getX(),dest2.getY(),0)); | |
} | |
Collections.reverse(hull_left); | |
ArrayList<Coordinate> hull = new ArrayList<Coordinate>(); | |
hull.addAll(hull_right); | |
hull.addAll(hull_left); | |
hull.add(hull_right.get(0)); //close ring | |
Coordinate[] hull1 = new Coordinate[hull.size()]; | |
hull1 = hull.toArray(hull1); | |
LinearRing ring = geometryFactory.createLinearRing( hull1 ); | |
LinearRing holes[] = null; // use LinearRing[] to represent holes | |
Polygon polygon = geometryFactory.createPolygon(ring, holes ); | |
return polygon; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: https://geoaware.wordpress.com/2013/10/16/geodetic-buffers-with-geotools/