GeoTools introduction, installation environment, read and display file shp

GeoTools is an open source (LGPL) Java code library, which provides a standard way to handle geospatial data, such as geographic information systems to achieve (GIS). GeoTools library implements Open Geospatial Consortium (OGC) specifications.

  • Geotools provides a variety of GIS algorithms, to read and write, and displays various data formats.
  • In the display area to be worse, but with Swing achieve a map viewing and simple operation.
  • Users can implement their own map visualization algorithm based on Geotools provided. OpenJump and udig is based on the Geotools.
  • Most of the current open-source software, such as udig, geoserver such as the handling of spatial data are supported by the geotools do.
  • web services, desktop applications and command line tools can be implemented by geotools.
  • Is built on OGC standards, OGC is an idea implementation. The OGC is an international standard, so geotools the future will become the main tool for open source spatial data processing,
  • Two of the more important open source GIS toolkit is used Geotools JTS and GeoAPI. The former is to achieve a variety of GIS topology algorithm, it is also based on the GeoAPI.
  • Geotools now only based 2D graphics, lack of support for spatial data algorithms and 3D display.

Geotools supported data formats

  1. arcsdearcgridgeotiffgrassrastergtopo30image(JPEGTIFFGIFPNG),imageio-ext-gdalimagemoasaicimagepyramidJP2K,matlab

  2. Supported databases "jdbc-ng": db2h2mysqloraclepostgisspatialite, sqlserver;

  3. 支持的矢量格式和数据访问:app-schemaarcsdecsvdxfedigeoexcel,geojson,orgpropertyshapefilewfs

  4. XML绑定。基于xml的Java数据结构和绑定提供了如下格式xsd-core (xml simple types),fes,filtergml2gml3kmlowssldwcswfswmswpsvpf。对于额外的geometrysldfilter的编码和解析可以通过domsax程序。

     

    支持大部分的OGC标准

  5. OGC中的sld/SE和渲染引擎;

  6. OGC一般要素模型包括简单要素支持;

  7. OGC中栅格信息的网格影像表达;

  8. OGC中WFS,WMS和额外的WPS;

  9. ISO 19107 geometry规范;

Geotools依赖的开源项目

  1. JTS:JTS是加拿大的 Vivid Solutions 做的一套开放源码的 Java API。它提供了一套空间数据操作的核心算法,为在兼容OGC标准的空间对象模型中进行基础的几何操作提供2D空间谓词API。
  2. 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之家小专栏

对本专栏感兴趣的话,可以关注一波

Guess you like

Origin www.cnblogs.com/giserhome/p/11640737.html