Skip to content

Instantly share code, notes, and snippets.

@vpipkt
Last active June 8, 2017 12:13
Show Gist options
  • Save vpipkt/8bd2d06b895958a8148400355dbf54a9 to your computer and use it in GitHub Desktop.
Save vpipkt/8bd2d06b895958a8148400355dbf54a9 to your computer and use it in GitHub Desktop.
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;
}
@vpipkt
Copy link
Author

vpipkt commented Jun 8, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment