java 实现台风预测包络线缓冲区

我们经常会看到台风路径这样的预测路径,这个肉色多边形范围其实叫可能路径范围或者叫预报误差范围,会随着预测时间的增加而扩大,我们用java来怎么实现呢

//根据预报时刻模拟生成最大误差半径,已知24h=70km
        double avg_max_error = 70.0/24;
        Geometry polygon = null;
        Point prevPoint = null;
        //最后一个点
        List<Geometry> geometryList = new ArrayList<>();
        Point lastPoint = new Point(centerCoords.get(0).getCoordinate().y,centerCoords.get(0).getCoordinate().x);
        for (int i = 0; i < centerCoords.size(); i++) {
            Point point = new Point(centerCoords.get(i).getCoordinate().y,centerCoords.get(i).getCoordinate().x);
            if(Objects.isNull(polygon)){
                //前一个点
                prevPoint = point;
                double error_radius = avg_max_error*Long.valueOf(centerCoords.get(i).getYbsk());
                String circleGeoJson = TurfTransformation.circle(com.mapbox.geojson.Point.fromLngLat(prevPoint.getLon(),prevPoint.getLat()),error_radius,32, TurfConstants.UNIT_KILOMETERS).toJson();
                polygon = GeoDataTypeConvertUtils.geoJsonToGeometry(circleGeoJson);
                geometryList.add(polygon);
                CheapRuler ruler = CheapRuler.fromLatitude(prevPoint.getLat(), Unit.KILOMETERS);
                double bearing = ruler.bearing(lastPoint,prevPoint);
                Point p1 = ruler.destination(point,error_radius,bearing+90);
                Point p4 = ruler.destination(point,error_radius,bearing-90);
                String polygonStr = "{\"geometry\":{\"coordinates\":[["+lastPoint.toArray()+","+p1.toArray()+","+p4.toArray()+","+lastPoint.toArray()+"]],\"type\":\"Polygon\"},\"type\":\"Feature\"}";
                Geometry polygonGeometry = GeoDataTypeConvertUtils.geoJsonToGeometry(polygonStr);
                geometryList.add(polygonGeometry);
                polygon = polygon.union(polygonGeometry);
                continue;
            }

            double pre_error_radius = avg_max_error * Long.valueOf(centerCoords.get(i-1).getYbsk());
            double error_radius = avg_max_error * Long.valueOf(centerCoords.get(i).getYbsk());
            CheapRuler ruler = CheapRuler.fromLatitude(centerCoords.get(i).getCoordinate().y, Unit.KILOMETERS);
            String circleGeoJson = "";

            circleGeoJson = TurfTransformation.circle(com.mapbox.geojson.Point.fromLngLat(centerCoords.get(i).getCoordinate().x,centerCoords.get(i).getCoordinate().y),error_radius,32, TurfConstants.UNIT_KILOMETERS).toJson();
            Geometry circleGeometry = GeoDataTypeConvertUtils.geoJsonToGeometry(circleGeoJson);
            geometryList.add(circleGeometry);

            //计算当前点到第一个历史点
            double bearing = ruler.bearing(prevPoint,point);
            Point p1 = ruler.destination(point,error_radius,bearing+90);
            Point p2 = ruler.destination(prevPoint,pre_error_radius,bearing+90);
            Point p3 = ruler.destination(prevPoint,pre_error_radius,bearing-90);
            Point p4 = ruler.destination(point,error_radius,bearing-90);
            PrecisionModel precisionModel = new PrecisionModel(10);
            GeometryFactory geometryFactory1 = new GeometryFactory(precisionModel);
            String polygonStr = "{\"geometry\":{\"coordinates\":[["+p1.toArray()+","+p2.toArray()+","+p3.toArray()+","+p4.toArray()+","+p1.toArray()+"]],\"type\":\"Polygon\"},\"type\":\"Feature\"}";
            System.out.println("===polygonStr==="+polygonStr);
            Geometry polygonGeometry = GeoDataTypeConvertUtils.geoJsonToGeometry(polygonStr);
            geometryList.add(polygonGeometry);
            GeometryCollection geometryCollection = geometryFactory1.createGeometryCollection(geometryList.toArray(new Geometry[geometryList.size()]));
            polygon = polygon.union(geometryCollection.union());
            prevPoint = point;
        }

画出来的效果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值