GeoTools系列(1)——关于GeoTools

Geotools是Java语言编写的开源GIS工具包。该项目已有十多年历史,生命力旺盛,代码非常丰富,包含多个开源GIS项目,并且基于标准的GIS接口。Geotools主要提供各种GIS算法,各种数据格式的读写和显示。在显示方面要差一些,只是用Swing实现了地图的简单查看和操作。但是用户可以根据Geotools提供的算法自己实现地图的可视化。OpenJump和udig就是基于Geotools的。
Geotools用到的两个较重要的开源GIS工具包是JTS和GeoAPI。前者主要是实现各种GIS拓扑算法,也是基于GeoAPI的。但是由于两个工具包的GeoAPI分别采用不同的Java代码实现,所以在使用时需要相互转化。Geotools又根据两者定义了部分自己的GeoAPI,所以代码显得臃肿,有时容易混淆。由于GeoAPI进展缓慢,Geotools自己对其进行了扩充。另外,Geotools现在还只是基于2D图形的,缺乏对3D空间数据算法和显示的支持。

一、Geotools The Open Source Java GIS Toolkit

http://geotools.org/  Geotools官方网站
http://docs.geotools.org/stable/javadocs/index.html?overview-summary.html Geotools API在线文档
http://docs.geotools.org/latest/userguide/tutorial/index.html Geotools教程
https://mvnrepository.com/                           maven仓库地址查询
http://download.osgeo.org/webdav/geotools/      maven仓库地址

 

二、OpenGIS 软件架构

org.geotools.data 负责地理数据的读写(如:ShapefileReader用于读取shpfile数据)
org.geotools.geometry 负责提供对JTs的调用接口,以将地理数据封装成JTS中定义的几何对象(Geometry)
org.geotools.feature 负责封装空间几何要素对象(Feature),对应于地图中一个实体,包含:空间数据(Geometry)、属性数据(Aitribute)、参考坐标系(Refereneedsystem)、最小外包矩形(EnveloPe)等属性,是Gls操作的核心数据模型。

几个工具类:

org.geotools.data.DataUtilities
a facade classes which can help simplify common data wrangling chores  简化繁琐的通用数据
(1)、定义属性
FeatureType TYPE = DataUtilities.createType("Location","location:Point," + "NAME:String," + "INFO:String,"+ "OWNER:String");

(2) DataUtilities.schema
You can use this method to quickly get a representation of a FeatureType  返回FeatureType的schema
//返回schema
DataUtilities.spec(featureType))

(3) DataUtilities.collection   Feature数组转换为Feature集合
DataUtilities has helper methods to turn almost anything into a FeatureCollection
Feature[] array; 
....
return DataUtilties.collection( array );

(4) DataUtilities.reader 格式化
convert a perfectly good collection to  FeatureReader format.
FeatureCollection collection;
FeatureReader reader = DataUtilities.reader( collection );

附:shp 格式文件介绍

Shapefile file extensions
.shp—The main file that stores the feature geometry. Required.
.shx—The index file that stores the index of the feature geometry. Required.
.dbf—The dBASE table that stores the attribute information of features. Required.There is a one-to-one relationship between geometry and attributes, which is based on record number.
.prj—The file that stores the coordinate system information. Used by ArcGIS.

DBF文件中的数据类型FieldType
代码 数据类型 允许输入的数据
B  二进制型 各种字符。
C  字符型   各种字符。
D  日期型   用于区分年、月、日的数字和一个字符,内部存储按照YYYYMMDD格式。
G  (Generalor OLE)    各种字符。
N   数值型(Numeric)    – . 0 1 2 3 4 5 6 7 8 9
L   逻辑型(Logical)? Y y N n T t F f (? 表示没有初始化)。
M   (Memo)   各种字符。

转载自:https://blog.csdn.net/kone0611/article/details/83539014

You may also like...