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

二次信任 提交于 2019-11-27 06:11:25
Clint

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

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

There is GeoTools, or more exactly this class ShapefileDataStore.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!