How to use GeometricShapeFactory in geoTools to create a Circle on map

前端 未结 2 907
既然无缘
既然无缘 2021-01-16 10:20

I am currently using the below code to create a GeoJson Polygon. this gives me a bad circle which is not valid...

in this case RADIUS = 1609.34 , which

2条回答
  •  情歌与酒
    2021-01-16 10:46

        double latitude = 40.689234d;
        double longitude = -74.044598d;
        double diameterInMeters = 2000d; //2km
    
        GeometricShapeFactory shapeFactory = new GeometricShapeFactory();
        shapeFactory.setNumPoints(64); // adjustable
        shapeFactory.setCentre(new Coordinate(latitude, longitude));
        // Length in meters of 1° of latitude = always 111.32 km
        shapeFactory.setWidth(diameterInMeters/111320d);
        // Length in meters of 1° of longitude = 40075 km * cos( latitude ) / 360
        shapeFactory.setHeight(diameterInMeters / (40075000 * Math.cos(Math.toRadians(latitude)) / 360));
    
        Polygon circle = shapeFactory.createEllipse();
    

    result

提交回复
热议问题