当前位置:网站首页>批量修改Shapefile属性表的一种方法(使用gdal.jar)
批量修改Shapefile属性表的一种方法(使用gdal.jar)
2022-08-09 09:29:00 【我一时想不起】
批量修改Esri Shapefile属性的方法有很多中,比如使用各类GIS软件自带的字段计算器、函数库等等。
也可以使用GDAL有关的函数库来处理矢量文件,这样操作起来应该会更自由一些、个性化可能更强大一些。GDAL是由开源地理信息基金会发布的一个开源函数库,目前有C、C++、Python、Java版本的API。可以用来做地理信息系统的开发工作。下载及介绍链接:GDAL — GDAL documentation
以下是使用gdal.jar来完成对矢量文件的操作。
public void WriteShpDbf() {
// 注册所有的驱动
ogr.RegisterAll();
// 为了支持中文路径,请添加下面这句代码
gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
// 为了使属性表字段支持中文,请添加下面这句
gdal.SetConfigOption("SHAPE_ENCODING", "");
String FileName = "F:\\test\\25.shp";
// 注意空格是必须的
String strDriverName = "ESRI Shapefile";
// 加载驱动
org.gdal.ogr.Driver oDriver = ogr.GetDriverByName(strDriverName);
if (oDriver == null) {
System.out.println("打开驱动失败!");
return;
}
// 打开文件,获取数据源
DataSource oDS = oDriver.Open(FileName, 1);
if (oDS == null) {
System.out.println("打开矢量文件【" + FileName + "】失败!\n");
return;
}
//打开图层,一般ESRI Shapefile只有一个图层
Layer oLayer = oDS.GetLayer(0);
if (oLayer == null) {
System.out.println("打开图层失败!\n");
return;
}
System.out.println("图层:" + oLayer.GetName());
int ct = (int) oLayer.GetFeatureCount();
System.out.println("要素数量" + ct);
//遍历要素,一个要素可以理解为Shapefile属性表中的一行
for (int i = 0; i < ct; i++) {
//根据下标获取要素
Feature feature = oLayer.GetFeature(i);
//给integer型字段bh赋值
feature.SetField("bh", (i + 1));
//将要素应用到图层
oLayer.SetFeature(feature);
}
//将图层数据保存到硬盘
oLayer.SyncToDisk();
}
边栏推荐
- How much do you know about the mobile APP testing process specifications and methods?
- 使用Protege4和CO-ODE工具构建OWL本体的实用指南-1.3版本(4.Building An OWL Ontology)
- Do you know the basic process and use case design method of interface testing?
- 米斗APP逆向分析
- Teach you how to get a 0.1-meter high-precision satellite map for free
- 8.Properties property collection
- goproxy.io 证书过期
- 4.泛型和工具类
- 5.转换流
- 软件测试外包公司怎么样?有什么好处和坏处?为什么没人去?
猜你喜欢

Summary of steps and methods for installing and uninstalling test cases that you must read

QT sets the icon of the exe executable

Global 19 Google Satellite Map Free View Download
软件测试面试中,面试官问你一些比较“刁难”的问题你会怎么回答

本体开发日记05-努力理解SWRL(Built-Ins)

本体开发日记01-Jena配置环境变量

你一定要看的安装及卸载测试用例的步骤及方法总结

MVCC multi-version concurrency control

接口性能测试方案设计方法有哪些?要怎么去写?

【个人学习总结】CRC校验原理及实现
随机推荐
7.FileFilter接口
JS报错-Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on...
map去重代码实现
unittest测试框架原理及测试流程解析,看完绝对有提升
China to create a domestic "Google Earth" clarity scary
本体开发日记05-努力理解SWRL(下)
【个人学习总结】CRC校验原理及实现
oracle查看表空间占用情况并删除多余表所占空间
Rights management model, ACL, RBAC and ABAC (steps)
软件测试流程包括哪些内容?测试方法有哪些?
“摄像头用不了”+win8.1+DELL+外置摄像头+USB免驱的解决办法
Command line query database
字符串
MySQL Checking and Filling Leaks (5) Unfamiliar Knowledge Points
归并排序
GBase数据库产生迁移工具假死的原因是什么?
Consolidation of Questionnaire Questions and Answers
[Pytorch] Install mish_cuda
6.Map接口与实现类
本体开发日记05-努力理解SWRL(RDF Concrete Syntax)