From: Paulo S. <prs...@gm...> - 2008-10-21 13:00:07
|
Hi, I need to build a class to read a shape file. I am using this class listed below as example, however i can´t run the application because "Feature" Class is Deprecated. How can I solve it? I am using "GeoTools API 2.5.0". Do you have another reading shape file example ? I need also a document that contains the structures of the files related below: *.shp* . - *.shx* . - *.dbf* . - *.sbn* and *.sbx* - . - *.fbn* and *.fbx* - . - *.ain* and *.aih* - . - *.prj* - . - *.xml* Thankful. Best Regards, Paulo Roberto. ============================================================= package geotoolsPRS; import java.io.File; import java.util.Map; import java.util.HashMap; import org.geotools.data.DataStore; import org.geotools.data.DataStoreFinder; import org.geotools.data.FeatureSource; import org.geotools.feature.FeatureCollection; import org.geotools.feature.FeatureIterator; import com.vividsolutions.jts.geom.Geometry; import org.geotools.factory.GeoTools; public class ShapeFileView { public static void main(String[] args) { System.out.println("Hello GeoTools: " + GeoTools.getVersion()); try { if (args.length != 1) { System.exit(1); } File file = new File(args[0]); if (!file.exists()) { System.exit(1); } Map connect = new HashMap(); connect.put("url", file.toURL()); 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(); int length = 0; try { * while (iterator.hasNext()) { Feature feature = iterator.next(); Geometry geometry = feature.getDefaultGeometry(); length += geometry.getLength(); } * } finally { iterator.close(); } System.out.println("Total length " + length); } catch (Exception e) { e.printStackTrace(); } } } |