Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone know of a library in Java that can parse ESRI 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?

like image 776
KingNestor Avatar asked Jan 11 '10 20:01

KingNestor


People also ask

What are .SHP files used?

A shapefile is an Esri vector data storage format for storing the location, shape, and attributes of geographic features. It is stored as a set of related files and contains one feature class.


2 Answers

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) {} 
like image 58
Clint Avatar answered Sep 21 '22 04:09

Clint


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

like image 40
Robert Christie Avatar answered Sep 21 '22 04:09

Robert Christie