Jer*_*ook 1 java latitude-longitude geotools
我目前正在使用以下代码创建 GeoJson 多边形。这给我带来了一个无效的坏循环......
在本例中RADIUS = 1609.34 ,即 1 英里(以米为单位)。
public GeoJsonPolygon createRadiusPolygon( Point point,double RADIUS) {
GeometricShapeFactory shapeFactory = new GeometricShapeFactory();
shapeFactory.setNumPoints(32);
shapeFactory.setCentre(new com.vividsolutions.jts.geom.Coordinate(point.getX(), point.getY()));
shapeFactory.setSize(RADIUS * 2);
com.vividsolutions.jts.geom.Geometry circle = shapeFactory.createCircle();
List<Point> points = new ArrayList<Point>();
for (com.vividsolutions.jts.geom.Coordinate coordinate : circle.getCoordinates()) {
Point lngLatAtl = new Point(coordinate.x, coordinate.y);
points.add(lngLatAtl);
}
Collections.reverse(points);
return new GeoJsonPolygon(points);
}
Run Code Online (Sandbox Code Playgroud)
参考: http ://docs.geotools.org/stable/userguide/library/jts/geometry.html
目前,如果我使用 Point(-73.87,40.84) RADIUS = 1609.34,我会得到以下链接。 https://gist.githubusercontent.com/VanitySoft/56c4ce0f5c1c7e7fe0461ed46fd5ed11/raw/94544750a140d81780ebe9206395a21ab88bb1f7/circle
===已解决== 来自@Ian 的回答:在他的回答中使用方法。RADIUS 以英里为单位,用于获取用于创建 GeoJson 的圆。
...
com.vividsolutions.jts.geom.Point jtsPoint = new GeometryFactory().createPoint(new com.vividsolutions.jts.geom.Coordinate(point.getY(), point.getX()));
javax.measure.Measure measure = Measure.valueOf(RADIUS, NonSI.MILE);
com.vividsolutions.jts.geom.Geometry circle = createCircleRadis(measure,CRS.decode("epsg:4326"),jtsPoint );
...
Run Code Online (Sandbox Code Playgroud)
...
double latitude = 40.689234d;\n double longitude = -74.044598d;\n double diameterInMeters = 2000d; //2km\n\n GeometricShapeFactory shapeFactory = new GeometricShapeFactory();\n shapeFactory.setNumPoints(64); // adjustable\n shapeFactory.setCentre(new Coordinate(latitude, longitude));\n // Length in meters of 1\xc2\xb0 of latitude = always 111.32 km\n shapeFactory.setWidth(diameterInMeters/111320d);\n // Length in meters of 1\xc2\xb0 of longitude = 40075 km * cos( latitude ) / 360\n shapeFactory.setHeight(diameterInMeters / (40075000 * Math.cos(Math.toRadians(latitude)) / 360));\n\n Polygon circle = shapeFactory.createEllipse();\nRun Code Online (Sandbox Code Playgroud)\n\n
| 归档时间: |
|
| 查看次数: |
8049 次 |
| 最近记录: |