GeoTools是一個開放源代碼(LGPL)Java代碼庫,它提供了符合標準的方法來處理地理空間數據,例如實現地理信息系統(GIS)。GeoTools庫實現了開放地理空間聯盟(OGC)規範。html
arcsde
, arcgrid
, geotiff
, grassraster
, gtopo30
, image
(JPEG
, TIFF
, GIF
, PNG
),imageio-ext-gdal
, imagemoasaic
, imagepyramid
, JP2K
,matlab
;java
支持的數據庫「jdbc-ng」:db2
, h2
, mysql
, oracle
, postgis
, spatialite
,sqlserver
;mysql
支持的矢量格式和數據訪問:app-schema
, arcsde
, csv
, dxf
, edigeo
, excel
,geojson
,org
, property
, shapefile
, wfs
;git
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
程序。github
支持大部分的OGC標準web
OGC中的sld/SE和渲染引擎;redis
OGC通常要素模型包括簡單要素支持;算法
OGC中柵格信息的網格影像表達;sql
OGC中WFS,WMS和額外的WPS;數據庫
ISO 19107 geometry規範;
在本文最後的github項目中有安裝介紹和遇到的坑。
其實就是官網的入門案例。查看本文下面的 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之家小專欄
對本專欄感興趣的話,能夠關注一波