
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 shapefilesFile 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 itMapContent map = new MapContent();map.setTitle("Quickstart"); Style style = SLD.createSimpleStyle(featureSource.getSchema()); Layer layer = new FeatureLayer(featureSource, style);map.addLayer(layer); // Now display the mapJMapFrame.showMap(map);} }
關注geotools-book查看原始碼和介紹,
本文參考
- Geotools應用簡要指南
原文鏈接:GIS之家小專欄
對本專欄感興趣的話,可以關注一波
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/3964.html
標籤:GIS
