20.基于java-geotools对shp的创建及增删改

该博客主要介绍了使用Java结合ArcGIS对shp文件进行数据操作。涵盖创建shp文件并添加数据、在已有shp文件中新增数据、更新shp文件数据以及移除shp文件数据等内容,每个操作都包含数据准备和具体执行步骤。

查询

创建shp

数据准备

let param={
   
   code: "utf-8", 
        datalist: [ 
        {
   
   name:"地方",type:0,heigh:2.5,geom:"POINT(109.588 34.645)"}, 
        {
   
   name:"煽动反",type:2,heigh:3.2,geom:"POINT(109.588 34.645)"} 
        ], 
        filepath: "D:gisdata/gp/aaa/sx_test.shp", 
        geomfiled: "geom", 
        keylist: [ 
        {
   
    
            filedname: "name", 
            type: "string" 
        },{
   
    
            filedname: "type", 
            type: "int" 
        },{
   
    
            filedname: "heigh", 
            type: "double" 
        } 
        ], 
        type: "Point" 
        }

shp文件创建及添加数据

 /**
* 生成shape文件
*
* @param shpPath  生成shape文件路径(包含文件名称) filepath
* @param encode   编码 code
* @param geoType  图幅类型,Point和Rolygon
* @param shpKey   data中图幅的key  geomfiled
* @param attrKeys 属性key集合 keylist
* @param data     图幅和属性集合 datalist
*/
public  void write2Shape(String shpPath, String encode, String geoType, String shpKey, List<ShpFiled> attrKeys, List<Map<String, Object>> data) {
   
   
       WKTReader reader = new WKTReader();
   try {
   
   
       //创建shape文件对象
       File file = new File(shpPath);
       Map<String, Serializable> params = new HashMap<>();
       params.put(ShapefileDataStoreFactory.URLP.key, file.toURI().toURL());
       ShapefileDataStore ds = (ShapefileDataStore) new ShapefileDataStoreFactory().createNewDataStore(params);

       //定义图形信息和属性信息
       SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
       tb.setCRS(DefaultGeographicCRS.WGS84);
       tb.setName("sx_test");
       tb.add("the_geom", getClass(geoType));
       for (ShpFiled field : attrKeys) {
   
   
           tb.add(field.getFiledname().toUpperCase(), getClass(field.getType()));
       }
       ds.createSchema(tb.buildFeatureType(
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

紫雪giser

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

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

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

打赏作者

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

抵扣说明:

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

余额充值