shp面要素wgs84坐标转火星坐标(gcj)方法

直入正题,说一下大概思路

1.将shp转为geojson格式

2.将geojson里面的坐标串进行坐标转换

3.将转换好的新的geojson重新生成shp格式

下面我们具体说明操作步骤

1.利用https://mapshaper.org/工具,将shp转geojson

点击Export,导出geojson

2.利用JAVA+fastjson对geojson进行修改和编辑

主要代码如下:

package com.company;
import java.io.*;
import java.math.BigDecimal;
import java.util.ArrayList;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONArray;
public class Main {

    public static String readJsonFile(String fileName) {
        String jsonStr = "";
        try {
            File jsonFile = new File(fileName);
            FileReader fileReader = new FileReader(jsonFile);
            Reader reader = new InputStreamReader(new FileInputStream(jsonFile),"utf-8");
            int ch = 0;
            StringBuffer sb = new StringBuffer();
            while ((ch = reader.read()) != -1) {
                sb.append((char) ch);
            }
            fileReader.close();
            reader.close();
            jsonStr = sb.toString();
            return jsonStr;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
    public  static void readJson(String jsonPath) throws IOException {
        String s = readJsonFile(jsonPath);

        //GeometryCollection geometryCollection = JSONObject.parseObject(s, GeometryCollection.class);
        JSONObject jobj = JSON.parseObject(s);
        JSONArray arr = jobj.getJSONArray("features");//构建JSONArray数组

        ArrayList<JSONObject> geoList=new ArrayList<JSONObject>();
        ArrayList<JSONObject> tobj=new ArrayList<JSONObject>();
        for(int i=0;i<arr.size();i++){
            JSONObject JO = (JSONObject)arr.get(i);
            JSONObject ar=(JSONObject)JO.get("geometry");
            if(ar==null)
            {
                continue;
            }

            String typ=(String)ar.get("type");
            if(typ.equals("MultiPolygon")){
                continue;
            }
            JSONArray nar1=(JSONArray)ar.get("coordinates");
            JSONArray nar=(JSONArray)nar1.get(0);

            JSONObject pro=(JSONObject)JO.get("properties");
            //写json
            JSONObject polyobj = new JSONObject();
            //polyobj.put("coordinates",Polygon.class);
            String strSum="";
            ArrayList<double[]> corlist=new ArrayList<double[]>();
            ArrayList<ArrayList> t=new ArrayList<ArrayList>();
            if(i==2727){
                System.out.print(i+"xiao");
            }
            for(int j=0;j<nar.size();j++){
                JSONArray dt=(JSONArray)nar.get(j);
                System.out.print(i+"xiao"+j+'\t');
                //JSONArray xyArr=(JSONArray)dt.get(0);
                BigDecimal x1=(BigDecimal)dt.get(0);
                double x=x1.doubleValue();
                BigDecimal y2=(BigDecimal)dt.get(1);
                double y=y2.doubleValue();
                double[] dtar=WGS_Encrypt.WGS2Mars(y,x);
                corlist.add(dtar);
            }
            t.add(corlist);
            JSONObject corobj = new JSONObject();
            corobj.put("type","Polygon");
            corobj.put("coordinates",t);

            //geoList.add(corobj);

            JSONObject corobj2 = new JSONObject();
            corobj2.put("type","Feature");
            corobj2.put("geometry",corobj);
            corobj2.put("properties",pro);
            tobj.add(corobj2);
            //JSONArray ar=(JSONArray) arr.get(i);
        }
        //写JSON
        JSONObject wrobj = new JSONObject();
        wrobj.put("type","FeatureCollection");
        wrobj.put("features",tobj);
        String result=wrobj.toString();
        FileWriter fw = new FileWriter("D:\\temp\\outhfnew.json");
        PrintWriter out = new PrintWriter(fw);
        out.write(result);
        out.println();
        fw.close();
        out.close();
    }
    public static void main(String[] args) throws Exception {
        readJson("F:\\BaiduNetdiskDownload\\hfnew.json");
    }
}

3.形成新的geojson后,再通过https://mapshaper.org/工具,转成shp

4.用cesiumlab工具将shp转成3dtiles

5.加载数据,我们可以看到建筑面数据已经成功转换完成。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值