有谁知道可以解析 ESRI Shapefiles 的 Java 库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2044876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 02:58:00  来源:igfitidea点击:

Does anyone know of a library in Java that can parse ESRI Shapefiles?

javashapefilegeotools

提问by KingNestor

I'm interested in writing a visualization program for the road data in the 2009 Tiger/Line Shapefiles. I'd like to draw the line data to display all the roads for my county.

我有兴趣为2009 Tiger/Line Shapefiles 中的道路数据编写可视化程序。我想绘制线数据以显示我所在县的所有道路。

The ESRI Shapefile or simply a shapefile is a popular geospatial vector data format for geographic information systems software. It is developed and regulated by ESRI as a (mostly) open specification for data interoperability among ESRI and other software products.1A "shapefile" commonly refers to a collection of files with ".shp", ".shx", ".dbf", and other extensions on a common prefix name (e.g., "lakes.*"). The actual shapefile relates specifically to files with the ".shp" extension, however this file alone is incomplete for distribution, as the other supporting files are required.

ESRI Shapefile 或简称为 shapefile 是地理信息系统软件的流行地理空间矢量数据格式。它由 ESRI 开发和监管,作为 ESRI 和其他软件产品之间数据互操作性的(主要)开放规范。1“shapefile”通常是指在公共前缀名称(例如,“lakes.*”)上带有“.shp”、“.shx”、“.dbf”和其他扩展名的文件集合。实际的 shapefile 专门与具有“.shp”扩展名的文件相关,但仅此文件不足以分发,因为需要其他支持文件。

Does anyone know of existing libraries for parsing and reading in the line data for Shapefiles?

有谁知道用于解析和读取Shapefiles行数据的现有库?

回答by adrian.tarau

There is GeoTools, or more exactly this class ShapefileDataStore.

GeoTools,或者更确切地说是这个类ShapefileDataStore

回答by Robert Christie

Openmaphas a Java APIthat provides read and write access to ESRI files.

Openmap有一个Java API,它提供对 ESRI 文件的读写访问。

回答by Clint

GeoToolswill do it. There are a ton of jars and you don't need most of them. However, reading the shapefile is just a few lines.

GeoTools会做到的。有很多罐子,你不需要其中的大部分。但是,读取 shapefile 只是几行。

File file = new File("mayshapefile.shp");

try {
  Map<String, String> connect = new HashMap();
  connect.put("url", file.toURI().toString());

  DataStore dataStore = DataStoreFinder.getDataStore(connect);
  String[] typeNames = dataStore.getTypeNames();
  String typeName = typeNames[0];

  System.out.println("Reading content " + typeName);

  FeatureSource featureSource = dataStore.getFeatureSource(typeName);
  FeatureCollection collection = featureSource.getFeatures();
  FeatureIterator iterator = collection.features();


  try {
    while (iterator.hasNext()) {
      Feature feature = iterator.next();
      GeometryAttribute sourceGeometry = feature.getDefaultGeometryProperty();
    }
  } finally {
    iterator.close();
  }

} catch (Throwable e) {}

回答by Ivan Mushketyk

You could try to use Java ESRI Shape File Readerlibrary. It's small, easy to install and has very simple API. The only drawback is that it does not read other mandatory and optional files (.shx, .dbf, etc.) that are usually shipped with a shape file.

您可以尝试使用Java ESRI Shape File Reader库。它体积小、易于安装并且具有非常简单的 API。唯一的缺点是它不读取通常随形状文件一起提供的其他强制和可选文件(.shx、.dbf 等)。

回答by user3577609

You can directly use GUI GIS tools so that their is no need of changing the source code of GeoTools.

您可以直接使用 GUI GIS 工具,无需更改 GeoTools 的源代码。

I use QGIS which does all operations(even more) than GeoTools.

我使用 QGIS,它比 GeoTools 执行所有操作(甚至更多)。

Quantum GIS- An open source Geographic Information System for editing, merging and simplifying shapefile maps. See also: creating maps with multiple layers using Quantum GIS.

Quantum GIS- 用于编辑、合并和简化 shapefile 地图的开源地理信息系统。另请参阅:使用 Quantum GIS 创建具有多个图层的地图。