[Schmitzm-commits] r1155 - trunk/src/schmitzm/geotools/io

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Oct 20 12:25:40 CEST 2010


Author: alfonx
Date: 2010-10-20 12:25:40 +0200 (Wed, 20 Oct 2010)
New Revision: 1155

Modified:
   trunk/src/schmitzm/geotools/io/GeoImportUtil.java
Log:
Updated the Shapefiles import routines to the correct and latest geotools ways... (FacotryFinder)

Modified: trunk/src/schmitzm/geotools/io/GeoImportUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/io/GeoImportUtil.java	2010-10-20 10:13:44 UTC (rev 1154)
+++ trunk/src/schmitzm/geotools/io/GeoImportUtil.java	2010-10-20 10:25:40 UTC (rev 1155)
@@ -62,12 +62,14 @@
 import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
 import org.geotools.data.DataSourceException;
 import org.geotools.data.DataStore;
+import org.geotools.data.DataStoreFinder;
 import org.geotools.data.DataUtilities;
 import org.geotools.data.shapefile.ShapefileDataStore;
 import org.geotools.data.shapefile.ShpFiles;
 import org.geotools.data.shapefile.indexed.IndexType;
 import org.geotools.data.shapefile.indexed.IndexedShapefileDataStore;
 import org.geotools.data.shapefile.shp.ShapefileReader;
+import org.geotools.factory.FactoryFinder;
 import org.geotools.factory.Hints;
 import org.geotools.feature.FeatureCollection;
 import org.geotools.feature.FeatureCollections;
@@ -255,7 +257,7 @@
 	 * speichert diese in einer
 	 * <code>org.geotools.feature.FeatureCollection</code>.<br>
 	 * 
-	 * @param url
+	 * @param shpURL
 	 *            {@link URL} to Shape-File
 	 * @param prjUrl
 	 *            {@link URL} zu .prj Datei des Shape-File. Darf
@@ -269,9 +271,11 @@
 	 * @throws IOException
 	 */
 	public static FeatureCollection<SimpleFeatureType, SimpleFeature> readFeaturesFromShapeURL(
-			URL url, URL prjUrl) throws IOException {
-		ShapefileDataStore store = new ShapefileDataStore(url);
+			URL shpURL, URL prjUrl) throws IOException {
+		// ShapefileDataStore store = new ShapefileDataStore(url);
 
+		DataStore store = readDataStoreFromShape(shpURL, prjUrl);
+
 		/**
 		 * .crs ?
 		 */
@@ -289,15 +293,19 @@
 			// store.forceSchemaCRS(DEFAULT_CRS);
 		}
 
-		/**
-		 * .cpg ?
-		 */
-		Charset readCharset = readCharset(url);
-		if (readCharset != null)
-			store.setStringCharset(readCharset);
+		if (store instanceof ShapefileDataStore) {
+			ShapefileDataStore sfDatasore = (ShapefileDataStore) store;
 
+			/**
+			 * .cpg ?
+			 */
+			Charset readCharset = readCharset(shpURL);
+			if (readCharset != null)
+				sfDatasore.setStringCharset(readCharset);
+
+		}
 		FeatureCollection<SimpleFeatureType, SimpleFeature> fc = store
-				.getFeatureSource().getFeatures();
+				.getFeatureSource(store.getTypeNames()[0]).getFeatures();
 
 		// Create a new DefaultFeatureCollection to allow modifying
 		// operations on the collection ("fc" is a DataFeatureCollection, whose
@@ -385,9 +393,6 @@
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 * @throws IOException
 	 *             if an error occur
-	 * 
-	 * @deprecated So wird das nicht mehr gemacht. Das wird mit einem Factory
-	 *             Finder gemacht.
 	 */
 	public static DataStore readDataStoreFromShape(URL shpURL, URL prjURL)
 			throws IOException {
@@ -395,18 +400,21 @@
 		map.put("url", shpURL);
 		map.put("create spatial index", true);
 
-		// DataStore dataStore = DataStoreFinder.getDataStore( map );
-		DataStore dataStore = new IndexedShapefileDataStore(shpURL, null,
-				false, true, IndexType.QIX);
-		// DataStore dataStore = new ShapefileDataStore(shpURL);
-		LOGGER.debug("DataStore = " + dataStore.getClass().toString());
-		IndexedShapefileDataStore dataStoreIndex = (IndexedShapefileDataStore) dataStore;
-		try {
-			LOGGER.debug("indexed = " + dataStoreIndex.isIndexed());
-			LOGGER.debug("memory = " + dataStoreIndex.isMemoryMapped());
-		} catch (Exception e) {
-			System.err.println(e);
-		}
+		DataStore dataStore = DataStoreFinder.getDataStore(map);
+		//
+		// // DataStore dataStore = DataStoreFinder.getDataStore( map );
+		// DataStore dataStore = new IndexedShapefileDataStore(shpURL, null,
+		// false, true, IndexType.QIX);
+		// // DataStore dataStore = new ShapefileDataStore(shpURL);
+		// LOGGER.debug("DataStore = " + dataStore.getClass().toString());
+		// IndexedShapefileDataStore dataStoreIndex =
+		// (IndexedShapefileDataStore) dataStore;
+		// try {
+		// LOGGER.debug("indexed = " + dataStoreIndex.isIndexed());
+		// LOGGER.debug("memory = " + dataStoreIndex.isMemoryMapped());
+		// } catch (Exception e) {
+		// System.err.println(e);
+		// }
 
 		return dataStore;
 	}



More information about the Schmitzm-commits mailing list