长江流域9省2市可视化(不展示业务信息水质及真实断面)

一、处理9省+2市地理信息为geojson集成到项目

 shp转geojson关键Java代码

/**
 * shp转换为Geojson
 * @param shpPath
 * @return
 */
public static Map shape2Geojson(String shpPath,String filePath){
    Map map = new HashMap();

    FeatureJSON fjson = new FeatureJSON();

    try{
        StringBuffer sb = new StringBuffer();
        sb.append("{\"type\": \"FeatureCollection\",\"features\": ");

        File file = new File(shpPath);
        ShapefileDataStore shpDataStore = null;

        shpDataStore = new ShapefileDataStore(file.toURL());
        //设置编码
        Charset charset = Charset.forName("utf-8");
        shpDataStore.setCharset(charset);
        String typeName = shpDataStore.getTypeNames()[0];
        SimpleFeatureSource featureSource = null;
        featureSource =  shpDataStore.getFeatureSource (typeName);
        SimpleFeatureCollection result = featureSource.getFeatures();
        SimpleFeatureIterator itertor = result.features();
        JSONArray array = new JSONArray();
        while (itertor.hasNext())
        {
            SimpleFeature feature = itertor.next();
            StringWriter writer = new StringWriter();
            fjson.writeFeature(feature, writer);
            JSONObject json = new JSONObject(writer.toString());
            array.put(json);
        }
        itertor.close();
        sb.append(array.toString());
        sb.append("}");

        //写入文件
        try {
            File geofile = new File(filePath);
            PrintStream ps = new PrintStream(new FileOutputStream(geofile));
            ps.println( sb.toString());// 往文件里写入字符串
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        map.put("status", "success");
        map.put("message", sb.toString());
    }
    catch(Exception e){
        map.put("status", "failure");
        map.put("message", e.getMessage());
        e.printStackTrace();

    }
    return map;
}

二、配置可视化展示图层信息

前端架构设计实现可参照:iClientOL实现前端gis开发架构_兴诚的博客-CSDN博客

import { Layersymbols } from '../SymbolsInfo/mapSymbols'
import GeoJSON from 'ol/format/GeoJSON'
import {getLyaerRenderSymbol} from '../MapCommon'
import {LayersRenderSet} from '../RendersInfo/LayersRenderSet'

export let layersInfo = {
  wyl: {
    layerCode:'wyl',
    sourceType:'ArcgisTile',
    title:'午夜蓝',
    url:'http://cache1.arcgisonline.cn/arcgis/rest/services/ChinaOnlineStreetPurplishBlue/MapServer',
    visible:false
  },
  XZQHRegion: {
    layerCode:'XZQHRegion',
    isRLayerPanel: true,
    sourceType: 'Vector',
    title: '行政区划',
    url: '/static/geojson/changjiangRegion/510000/bound.json',
    dataPath:'',
    geoType: 'geojson',
    wrapX: false,
    opacity: 1,
    location: {longitude: 109.46198629061443, latitude: 29.504518455495273, level: 5.64688833592623},
    visible: true
  },
  shanghaiRegion: {
    layerCode:'shanghaiRegion',
    isRLayerPanel: true,
    sourceType:'GeoVector',
    url:'/static/geojson/changjiangRegion/310000/bound.json',
    title:'上海市',
    style:Layersymbols.areaRegionSymbol,
    format: new GeoJSON(),
    wrapX: false,
    opacity: 1,
    location: {longitude: 115.783878, latitude: 34.308761, level: 8},
    visible:true
  },
  jiangsuRegion: {
    layerCode:'jiangsuRegion',
    isRLayerPanel: true,
    sourceType:'GeoVector',
    url:'/static/geojson/changjiangRegion/320000/bound.json',
    title:'江苏省',
    style:Layersymbols.areaRegionSymbol,
    format: new GeoJSON(),
    wrapX: false,
    opacity: 1,
    location: {longitude: 115.783878, latitude: 34.308761, level: 8},
    visible:true
  },
  zhejiangRegion: {
    layerCode:'zhejiangRegion',
    isRLayerPanel: true,
    sourceType:'GeoVector',
    url:'/static/geojson/changjiangRegion/330000/bound.json',
    title:'浙江省',
    style:Layersymbols.areaRegionSymbol,
    format: new GeoJSON(),
    wrapX: false,
    opacity: 1,
    location: {longitude: 115.783878, latitude: 34.308761, level: 8},
    visible:true
  },
  anhuiRegion: {
    layerCode:'anhuiRegion',
    isRLayerPanel: true,
    sourceType:'GeoVector',
    url:'/static/geojson/changjiangRegion/340000/bound.json',
    title:'安徽省',
    style:Layersymbols.areaRegionSymbol,
    format: new GeoJSON(),
    wrapX: false,
    opacity: 1,
    location: {longitude: 115.783878, latitude: 34.308761, level: 8},
    visible:true
  },
  jiangxiRegion: {
    layerCode:'jiangxiRegion',
    isRLayerPanel: true,
    sourceType:'GeoVector',
    url:'/static/geojson/changjiangRegion/360000/bound.json',
    title:'江西省',
    style:Layersymbols.areaRegionSymbol,
    format: new GeoJSON(),
    wrapX: false,
    opacity: 1,
    location: {longitude: 115.783878, latitude: 34.308761, level: 8},
    visible:true
  },
  hubeiRegion: {
    layerCode:'hubeiRegion',
    isRLayerPanel: true,
    sourceType:'GeoVector',
    url:'/static/geojson/changjiangRegion/420000/bound.json',
    title:'湖北省',
    style:Layersymbols.areaRegionSymbol,
    format: new GeoJSON(),
    wrapX: false,
    opacity: 1,
    location: {longitude: 115.783878, latitude: 34.308761, level: 8},
    visible:true
  },
  hunanRegion: {
    layerCode:'hunanRegion',
    isRLayerPanel: true,
    sourceType:'GeoVector',
    url:'/static/geojson/changjiangRegion/430000/bound.json',
    title:'湖南省',
    style:Layersymbols.areaRegionSymbol,
    format: new GeoJSON(),
    wrapX: false,
    opacity: 1,
    location: {longitude: 115.783878, latitude: 34.308761, level: 8},
    visible:true
  },
  chongqingRegion: {
    layerCode:'chongqingRegion',
    isRLayerPanel: true,
    sourceType:'GeoVector',
    url:'/static/geojson/changjiangRegion/500000/bound.json',
    title:'重庆市',
    style:Layersymbols.areaRegionSymbol,
    format: new GeoJSON(),
    wrapX: false,
    opacity: 1,
    location: {longitude: 115.783878, latitude: 34.308761, level: 8},
    visible:true
  },
  sichuanRegion: {
    layerCode:'sichuanRegion',
    isRLayerPanel: true,
    sourceType:'GeoVector',
    url:'/static/geojson/changjiangRegion/510000/bound.json',
    title:'四川省',
    style:Layersymbols.areaRegionSymbol,
    format: new GeoJSON(),
    wrapX: false,
    opacity: 1,
    location: {longitude: 115.783878, latitude: 34.308761, level: 8},
    visible:true
  },
  yunnanRegion: {
    layerCode:'yunnanRegion',
    isRLayerPanel: true,
    sourceType:'GeoVector',
    url:'/static/geojson/changjiangRegion/530000/bound.json',
    title:'云南省',
    style:Layersymbols.areaRegionSymbol,
    format: new GeoJSON(),
    wrapX: false,
    opacity: 1,
    location: {longitude: 115.783878, latitude: 34.308761, level: 8},
    visible:true
  },
  guizhouRegion: {
    layerCode:'guizhouRegion',
    isRLayerPanel: true,
    sourceType:'GeoVector',
    url:'/static/geojson/changjiangRegion/520000/bound.json',
    title:'贵州省',
    style:Layersymbols.areaRegionSymbol,
    format: new GeoJSON(),
    wrapX: false,
    opacity: 1,
    location: {longitude: 115.783878, latitude: 34.308761, level: 8},
    visible:true
  },
  changjiangLine: {
    layerCode: 'changjiangLine',
    isRLayerPanel: true,
    sourceType: 'Vector',
    title: '长江',
    url: '/static/geojson/changjiangRegion/riverL1.json',
    dataPath:'',
    // labelField: 'NAME',
    geoType: 'geojson',
    maxZoom: Infinity,
    minZoom: -Infinity,
    wrapX: false,
    opacity: 1,
    location: {longitude: 109.46198629061443, latitude: 29.504518455495273, level: 5.64688833592623},
    visible: true
  },
  geoJsonFe1: {
    layerCode: 'geoJsonFe1',
    isRLayerPanel: true,
    sourceType: 'Vector',
    title: '断面',
    url: '/static/geojson/changjiangRegion/duanmian.json',
    dataPath:'',
    floatLabelInfo: {floatLabelField: 'val', offsetX: 8, offsetY: -16},
    geoType: 'geojson',
    maxZoom: Infinity,
    minZoom: -Infinity,
    wrapX: false,
    opacity: 1,
    location: {longitude: 109.46198629061443, latitude: 29.504518455495273, level: 5.64688833592623},
    visible: true
  },
  CRegion: {
    layerCode: 'CRegion',
    sourceType: 'Vector',
    title: '绘制区域',
    wrapX: false,
    isModify: true,
    opacity: 1,
    visible: false
  },
  LS: {
    layerCode:'LS',
    sourceType:'Vector',
    title:'临时',
    wrapX:false,
    opacity: 1,
    visible:true
  }
}

三、行政区划刷新关键前端代码

refreshXZQH(regionCode){
  commonRefreshVectorGeojsonLayer('/static/geojson/changjiangRegion/'+regionCode+'/XZQH.json',layersInfo,'XZQHRegion',this.smap)
}

四、可视化效果

如果对恁有帮助,请点赞打赏支持! 

技术合作交流qq:2401315930

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

兴诚

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值