Geotools系列之Geotools DataStore

  • GeoTools

  GeoTools is an open source (LGPL) Java code library which provides standards compliant methods for the manipulation of geospatial data, for example to implement Geographic Information Systems (GIS). The GeoTools library implements Open Geospatial Consortium (OGC) specifications as they are developed.

  • DataStore

  A DataStore is used to access and store geospatial data in a range of vector formats including shapefiles, GML files, databases, Web Feature Servers, and other formats.

  

  上面是官方解释,简言之,Geotools是一个开源的Java代码库,提供一些处理地理空间数据的方法;DataStore主要用于访问和存储矢量格式的地理空间数据。

  矢量格式的数据的存储格式有多种,比如存在shapefiles、数据库、elasticsearch(Hadoop)或者其他格式,数据库又有很多种,比如说postGIS、Hbase、Geopackage,但是在进行数据访问或者存储时,Geotools提供了统一的访问接口。其中数据访问主要涉及的就是DataAccessFinder工厂类,数据存储主要涉及的就是DataStoreFinder工厂类

  Geotools DataStore使用了Java的SPI机制,这样就可以动态的获取到当前可以访问的数据格式。

  关于Java SPI机制的原理见本人的另外一篇随笔https://www.cnblogs.com/mohanchen/p/10792677.html

  具体使用方法如下:

//Finds all implemtaions of DataStoreFactory which have registered using the services mechanism, 
// regardless weather it has the appropriate libraries on the classpath.
Iterator<DataStoreFactorySpi> availableDataStores = DataStoreFinder.getAvailableDataStores();

  DataStoreFactorySpi用于从一组参数构造一个DataStore实例,它还提供了构造实例时的参数列表,获取方法为:

//获取参数列表
DataAccessFactory.Param[] parametersInfo = dataStoreFactorySpi.getParametersInfo();

  使用SPI的一个好处就是,如果想新增一个新的矢量格式或者数据库格式,只需要实现一遍DataStoreFactorySpi,可以根据DataStoreFactorySpi获取到够造DataStore需要的参数列表,我们的客户端可以根据这个参数列表动态的构造参数输入GUI;这样在不修改客户端的情况下就可很好的实现支持格式的伸缩,即想支持某种格式,就把实现该格式对应DataStoreFactorySpi的依赖jar包加进来,不想支持某种格式去掉依赖即可,客户端不需要做任何更改。

下面是对PostGIS和Hbase两种格式数据的动态解析。

  下一节开始介绍数据访问。

 



 

posted @ 2019-05-06 20:21  王小豆又叫小王子  阅读(2358)  评论(1编辑  收藏  举报