首页 > 编程语言 >java读取shp文件信息

java读取shp文件信息

时间:2022-11-11 11:02:43浏览次数:49  
标签:shp java 读取 shpDataStore feature System println out String

public static void importShpToPG(String shpfile,  String charsetName ) throws IOException {
    ShapefileDataStore shpDataStore = null;
    //shpfile="E:\\jinzita\\caiqie\\caiqiemian.shp";
   // charsetName="GBK";
   // TimeUtils.startTime("read Shp feature");
    try {
        File file = new File(shpfile);
        shpDataStore = new ShapefileDataStore(file.toURI().toURL());
        //设置字符编码
        Charset charset = Charset.forName(charsetName);
        shpDataStore.setCharset(charset);
        String typeName = shpDataStore.getTypeNames()[0];
        System.out.println("name: " + typeName);
        SimpleFeatureType schema = shpDataStore.getSchema(typeName);
        CoordinateReferenceSystem srs = schema.getCoordinateReferenceSystem();
        System.out.println(srs.toWKT());
        Integer epsg = CRS.lookupEpsgCode(srs, true);
        if (epsg == null) {
            epsg = 4326;
        }
        String wkid = "" + epsg;
        System.out.println("wkid:" + wkid);
        SimpleFeatureSource featureSource = null;
        featureSource = shpDataStore.getFeatureSource(typeName);
        SimpleFeatureCollection result = featureSource.getFeatures();
        System.out.println("feature size: " + result.size());
        SimpleFeatureIterator itertor = result.features();
        while (itertor.hasNext()) {
            SimpleFeature feature = itertor.next();
            Collection<Property> p = feature.getProperties();
            Iterator<Property> it = p.iterator();
            String geometry = "";
            String id = feature.getID();
            FeatureId fid = feature.getIdentifier();
            while (it.hasNext()) {
                    Property pro = it.next();
                    String type = Classes.getShortName(pro.getType().getBinding());
                System.out.println(type);
                }
            }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

说明:该实现需要Java的gdal库和jar包

连接:gdal https://www.aliyundrive.com/s/LR6boSBEFNF 点击链接保存,或者复制本段内容,打开「阿里云盘」APP ,无需下载极速在线查看,视频原画倍速播放。

 

标签:shp,java,读取,shpDataStore,feature,System,println,out,String
From: https://www.cnblogs.com/zcxxcvbn/p/16879844.html

相关文章

  • java 实现 PHP password_hash() password_verify() 单向验证
    近期一个php转java项目中遇到。写出来分享一下:javaBCrypt类库。​​https://github.com/patrickfav/bcrypt​​@TestpublicvoidtestBCrypt(){Stringp......
  • MybatisPlus Caused by: java.sql.BatchUpdateException: Field 'id' doesn't have a
    在使用MybatisPlus时,使用saveBatch()批量保存数据的时候报错Causedby:java.sql.BatchUpdateException:Field'id'doesn'thaveadefaultvalue,这是因为MybatisPlus不......
  • springBoot的java工具类
    断言是一个逻辑判断,用于检查不应该发生的情况Assert关键字在JDK1.4中引入,可通过JVM参数-enableassertions开启SpringBoot中提供了Assert断言工具类,通常用......
  • OOP下半部分-Java与生活
    目录​​面向对象三大特性:封装继承多态​​​​2-1-1需求重定义​​​​2-1-2继承​​​​2-2-2饿狼传说之多层继承​​​​2-2-3方法的重写​​​​2-2-4super啃老......
  • 0:Base API-Java API 实战
    目录​​0.1引言​​​​0.2API的定义和用处​​​​0.3Scanner(普通类)​​​​0.4Number(包装类)​​​​0.5Math(工具类)​​​​0.6Random(父子类)​​​​0.7ThreadLoca......
  • 1:Unit test and main function-Java API 实战
    目录​​1.抛出企业问题,脱离main测试,模块化编程​​​​2.Junit单元测试的含义和用途​​​​3.怎么获取各种Jar包?MavenRepository获取各类各个版本的jar,这就是仓库。......
  • 4:File-Java API 实战
    目录​​1.引言​​​​2.绝对路径和相对路径?先学送快递吧!​​​​3.绝对路径​​​​4.相对路径​​​​5.File类​​​​6.Linux上的绝对路径有所不同​​1.引言文......
  • 1:Web开发入门-Java Web
    目录​​1.1什么是Web应用程序​​​​1.2B/S架构​​​​1.3静态Web与动态Web​​​​1.4JavaEE介绍​​​​1.5JavaEE架构与组件​​​​1.6JavaEE中的容器​​......
  • 一带而过-Java与生活
    目录​​认识Java​​​​0-0前言​​​​1-1Java是怎么执行的?说好的exe呢?​​​​1-2package​​​​1-3第一个程序的讲解​​​​1-4注释和文档​​​​2-0一带而过......
  • 1:Spring框架核心-Java Spring
    目录​​1.1软件模块化​​​​1.2Spring框架介绍​​​​1.3Spring框架的配置​​​​1.4Servlet​​​​1.5Spring容器​​​​1.6SpringBean对象的注解​​​​1.......