postgis转geoJSON

1.Mapeper.jar

List<Map<String,Object>> selectGeom();

2.Mapper.xml

<select id="selectGeom" resultType="java.util.HashMap">
    select st_asgeojson(geom) as geom,xzqdm,uuid from xzq_n where del_flag='0' order by id asc
  </select>

3.转geoJson

public Map<String,Object> geoJSON(List<Map<String,Object>> pointList){
        Map<String,Object> map = new HashMap<>();
        List<Map<String, Object>> features = new ArrayList<Map<String, Object>>();
        for (Map<String, Object> m : pointList) {
            Map<String, Object> feature = new HashMap<String, Object>();
            feature.put("type", "Feature");
            Map<String, Object> properties = new HashMap<String, Object>();
            //把非geojson全部放到属性里面
            Iterator<Map.Entry<String, Object>> it = m.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> en = it.next();
                if (!"geom".equals(en.getKey())) {
                    properties.put(en.getKey(), en.getValue());
                }
            }
            feature.put("properties", properties);

            feature.put("geometry", JSON.parse(m.get("geom").toString()));
            feature.put("id",m.get("uuid"));
            features.add(feature);
        }
        map.put("features", features);
        return map;
    }

4.cesium调用

let geoJson={"type": "FeatureCollection", "name": "河道线", "crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}},"features":geomList.features};
  var promise=GeoJsonDataSource.load(geoJson);
  promise.then(function(dataSource) {
    dataSource.name='SourceName'
    viewer.dataSources.add(dataSource);
    var entities = dataSource.entities.values;
    for (var i = 0; i < entities.length; i++) {
      var entity = entities[i];
      entity.polygon.outline = true;
      entity.polygon.extrudedHeight=20;
      entity.polygon.fill=false;
      entity.polygon.classificationType =ClassificationType.BOTH;
      entity.polygon.outlineColor = Color.TEAL;
    }
  });

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值