有谁知道 Java 中有一个可以解析 ESRI Shapefiles 的库吗?

发布于 2024-08-17 20:39:44 字数 688 浏览 7 评论 0原文

我有兴趣为 2009 Tiger 中的道路数据编写可视化程序/线形状文件。我想绘制线路数据来显示我所在县的所有道路。

ESRI Shapefile 或只是一个 shapefile 是一种流行的地理空间文件 地理矢量数据格式 信息系统软件。这是 由 ESRI 开发和监管 (大部分)开放数据规范 ESRI 和其他公司之间的互操作性 软件产品。1 一个“shapefile” 通常指的是集合 带有“.shp”、“.shx”、“.dbf”的文件和 公共前缀上的其他扩展 名称(例如“湖泊。*”)。实际的 shapefile具体涉及 扩展名为“.shp”的文件, 然而这个文件本身并不完整 用于分发,与其他 需要支持文件。

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

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.

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.1 A "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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

从此见与不见 2024-08-24 20:39:44

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) {}

GeoTools will 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.

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) {}
冷默言语 2024-08-24 20:39:44

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

Openmap has a Java API that provides read and write access to ESRI files.

泛滥成性 2024-08-24 20:39:44

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

There is GeoTools, or more exactly this class ShapefileDataStore.

豆芽 2024-08-24 20:39:44

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

You could try to use Java ESRI Shape File Reader library. 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.

我不吻晚风 2024-08-24 20:39:44

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

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

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

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

I use QGIS which does all operations(even more) than 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文