java读取shp的几何类型及字段

目录

一.GeoTools介绍

二.背景

三.实现代码


一.GeoTools介绍

GeoTools是一套操作和显示地图的开源Java 代码库,提供了一系列符合规范的操作地理空间数据的方法,GeoTools被许多项目使用,在地理信息领域有着广泛的应用。

二.背景

在后端GIS开发中经常需要读取shp数据,本文介绍使用geotools读取shp的几何类型以及数据的方法。

三.实现代码

这里编写了一个读取shp几何类型的getShpGeomType()方法和读取shp字段属性的getShpFieldMap()方法。

/**
 * 获取shp几何类型
 *
 * @param dataStore shp文件数据存储
 * @return
 * @throws IOException
 */
public static String getShpGeomType(ShapefileDataStore dataStore) throws IOException {
    if (dataStore == null) {
        return "empty";
    }
    String type = dataStore.getSchema().getGeometryDescriptor().getType().getName().getLocalPart();
    if (StringUtil.isEmpty(type)) {
        type = "empty";
    }
    return type;
}





/**
 * 获取shp字段map
 *
 * @param dataStore shp文件数据存储
 * @return key--字段名,value--字段类型
 * @throws IOException
 */
public static Map<String, String> getShpFieldMap(ShapefileDataStore dataStore) throws IOException {
    List<AttributeDescriptor> attributeDescriptors = dataStore.getSchema().getAttributeDescriptors();
    Map<String, String> map = new HashMap<>();
    for (AttributeDescriptor attributeDescriptor : attributeDescriptors) {
        String key = attributeDescriptor.getLocalName();
        String value = attributeDescriptor.getType().getBinding().getName();
        map.put(key, value);
    }
    return map;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

会跑的小鹿

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

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

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

打赏作者

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

抵扣说明:

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

余额充值