GeoTools介绍、环境安装、读取shp文件并显示
GeoTools是一个开放源代码(LGPL)Java代码库,它提供了符合标准的方法来处理地理空间数据,例如实现地理信息系统(GIS)。GeoTools库实现了开放地理空间联盟(OGC)规范。
- Geotools主要提供各种GIS算法,实现各种数据格式的读写和显示。
- 在显示方面要差一些,只是用Swing实现了地图的简单查看和操作。
- 用户可以根据Geotools提供的算法自己实现地图的可视化。OpenJump和udig就是基于Geotools的。
- 目前的大部分开源软件,如udig,geoserver等,对空间数据的处理都是由geotools来做支撑。
- web服务,命令行工具和桌面程序都可以由geotools来实现。
- 是构建在OGC标准之上的,是OGC思想的一种实现。而OGC是国际标准,所以geotools将来必定会成为开源空间数据处理的主要工具,
- Geotools用到的两个较重要的开源GIS工具包是JTS和GeoAPI。前者主要是实现各种GIS拓扑算法,也是基于GeoAPI的。
- Geotools现在还只是基于2D图形的,缺乏对 3D空间数据算法和显示的支持。
Geotools支持的数据格式
-
arcsde
,arcgrid
,geotiff
,grassraster
,gtopo30
,image
(JPEG
,TIFF
,GIF
,PNG
),imageio-ext-gdal
,imagemoasaic
,imagepyramid
,JP2K
,matlab
; -
支持的数据库“jdbc-ng”:
db2
,h2
,mysql
,oracle
,postgis
,spatialite
,sqlserver
; -
支持的矢量格式和数据访问:
app-schema
,arcsde
,csv
,dxf
,edigeo
,excel
,geojson
,org
,property
,shapefile
,wfs
; -
XML
绑定。基于xml的Java数据结构和绑定提供了如下格式xsd-core
(xml simple types),fes
,filter
,gml2
,gml3
,kml
,ows
,sld
,wcs
,wfs
,wms
,wps
,vpf
。对于额外的geometry
、sld
和filter
的编码和解析可以通过dom
和sax
程序。支持大部分的OGC标准
-
OGC中的sld/SE和渲染引擎;
-
OGC一般要素模型包括简单要素支持;
-
OGC中栅格信息的网格影像表达;
-
OGC中WFS,WMS和额外的WPS;
-
ISO 19107 geometry规范;
Geotools依赖的开源项目
- JTS:JTS是加拿大的 Vivid Solutions 做的一套开放源码的 Java API。它提供了一套空间数据操作的核心算法,为在兼容OGC标准的空间对象模型中进行基础的几何操作提供2D空间谓词API。
- GeoAPI:GeoAPI为OpenGIS规范提供一组Java接口。
环境搭建
在本文最后的github项目中有安装介绍和遇到的坑。
第一个demo
其实就是官网的入门案例。查看本文下面的 github中的源码也可以。
package com.tutorial.quickstart; /* * GeoTools - The Open Source Java GIS Toolkit * http://geotools.org * * (C) 2019, Open Source Geospatial Foundation (OSGeo) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * */ import org.geotools.data.FileDataStore; import org.geotools.data.FileDataStoreFinder; import org.geotools.data.simple.SimpleFeatureSource; import org.geotools.map.FeatureLayer; import org.geotools.map.Layer; import org.geotools.map.MapContent; import org.geotools.styling.SLD; import org.geotools.styling.Style; import org.geotools.swing.JMapFrame; import org.geotools.swing.data.JFileDataStoreChooser; import java.io.File; import java.io.IOException; /** * Prompts the user for a shapefile and displays the contents on the screen in a map frame. * * <p>This is the GeoTools Quickstart application used in documentationa and tutorials. * */ public class Quickstart { /** * GeoTools Quickstart demo application. Prompts the user for a shapefile and displays its * contents on the screen in a map frame */ public static void main(String[] args) { // display a data store file chooser dialog for shapefiles File file = JFileDataStoreChooser.showOpenFile("shp", null); if (file == null) { return; } // "data/CHN_adm_shp/CHN_adm0.shp" // String path = "data/ne_50m_admin_0_countries/ne_50m_admin_0_countries.shp"; // File file = new File(path); // FileDataStoreFinder // 可以使我们轻松处理文件。另一种处理方法是使用连接参数映射。这种技术使我们对使用shapefile的方式有了更多的控制, // 还使我们可以连接到数据库和Web功能服务器。 FileDataStore store = null; try { store = FileDataStoreFinder.getDataStore(file); } catch (IOException e) { e.printStackTrace(); } SimpleFeatureSource featureSource = null; try { featureSource = store.getFeatureSource(); } catch (IOException e) { e.printStackTrace(); } // Create a map content and add our shapefile to it MapContent map = new MapContent(); map.setTitle("Quickstart"); Style style = SLD.createSimpleStyle(featureSource.getSchema()); Layer layer = new FeatureLayer(featureSource, style); map.addLayer(layer); // Now display the map JMapFrame.showMap(map); } }
关注geotools-book查看源码和介绍。
本文参考
原文链接:GIS之家小专栏
对本专栏感兴趣的话,可以关注一波
相关文章
- 【CTF MISC】文件内容反转方法-2017世安杯CTF writeup详解
- 《UNIX网络编程(第3版)》unp.h等源码文件的编译安装
- 《转载》renameTo文件在windows环境下可以,在linux中报错
- 解决wubi安装ubuntu时要下载系统映像文件问题
- Python-装饰器-案例-获取文件列表
- vuejs单文件组件:安装 webpack 和 vue-cli
- 一个好用的json文件本地查看工具 - JSON viewer
- 如何将iso文件安装到VirtualBox里的ubuntu去
- .NET平台开源项目速览(3)小巧轻量级NoSQL文件数据库LiteDB
- Angular应用的angular.json文件字段一览
- Flutter进阶第12篇: 检测应用版本号、服务器下载文件以及实现App自动升级、安装
- ML之xgboost:解读用法之xgboost库的core.py文件中的get_score(importance_type=self.importance_type)方法
- Python语言学习:Python语言学习之文件读取&写入/操作系统(OS模块详解)的简介、案例应用之详细攻略
- Android 文件大小的转换和文件日期的获取
- 安装paddle模型文件
- 安装mingw后,在命令窗体编译c文件
- C# 获取资源文件中的文件列表 及获取 读取 复制
- rootkit——一种特殊的恶意软件,它的功能是在安装目标上隐藏自身及指定的文件、进程和网络链接等信息,一般都和木马、后门等其他恶意程序结合使用
- Python pip下载的whl文件到哪里了?如何找到并使用这些whl文件?(whl离线安装包的制作过程示例)
- tsc : 无法加载文件 C:UsersLiushAppDataRoamingnpmtsc.ps1,因为在此系统上禁止运行脚本。
- labelme的安装以及如何用labelme标注的json文件转换成coco和pascal voc数据集的格式进行深度学习的训练
- Centos 7.5安装safe-rm,防止rm -rf /命令误删除文件