[Schmitzm-commits] r554 - branches/1.0-gt2-2.6/src/schmitzm/geotools/feature

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Nov 23 22:40:44 CET 2009


Author: alfonx
Date: 2009-11-23 22:40:44 +0100 (Mon, 23 Nov 2009)
New Revision: 554

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java
Log:
Method #featuresToArray will now not return if reading a features throws an execptions, but will try on... 

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java	2009-11-23 21:39:17 UTC (rev 553)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java	2009-11-23 21:40:44 UTC (rev 554)
@@ -371,7 +371,7 @@
 			style = createLineStyle(Color.BLUE, 1);
 
 		style.setName(DEFAULT_VECTOR_STYLE_NAME);
-		
+
 		// 26 style.setTitle(DEFAULT_VECTOR_STYLE_NAME);
 		style.getDescription().setTitle(
 				new SimpleInternationalString(DEFAULT_VECTOR_STYLE_NAME));
@@ -522,29 +522,46 @@
 		if (fc == null || fc.isEmpty())
 			return new SimpleFeature[0];
 
-//		long startTime = System.currentTimeMillis();
+		// long startTime = System.currentTimeMillis();
 
 		// Naiv alle Features durchgehen.
 		final Vector<SimpleFeature> fv = new Vector<SimpleFeature>();
 		final FeatureIterator<SimpleFeature> fi = fc.features();
 		try {
 
-//			for (int i = 0; fi.hasNext(); i++) {
-//				SimpleFeature f = fi.next();
-//					fv.add(f);
-//			}
-			
-			while( fi.hasNext() ) {
-				final SimpleFeature f = fi.next();
-				if (includeNullFeatures || f != null)
-					fv.add(f);
+			// for (int i = 0; fi.hasNext(); i++) {
+			// SimpleFeature f = fi.next();
+			// fv.add(f);
+			// }
+
+			while (fi.hasNext()) {
+				try {
+					final SimpleFeature f = fi.next();
+					if (includeNullFeatures || f != null)
+						fv.add(f);
+				} catch (Exception e) {
+					LOGGER.info("error reading a feature, but continuing",e);
+					// If reading one features fails (as it happens a lot with
+					// OSM data, we still want the others to appear
+					// Caused by: java.lang.IllegalArgumentException: Points of
+					// LinearRing do not form a closed linestring
+					// at
+					// com.vividsolutions.jts.geom.LinearRing.validateConstruction(LinearRing.java:105)
+					// at
+					// com.vividsolutions.jts.geom.LinearRing.<init>(LinearRing.java:100)
+					// at
+					// com.vividsolutions.jts.geom.GeometryFactory.createLinearRing(GeometryFactory.java:339)
+					// at
+					// org.geotools.data.shapefile.shp.PolygonHandler.read(PolygonHandler.java:188)
+				}
 			}
 		} finally {
 			fc.close(fi);
 		}
-		
-//	    LOGGER.info("took "+ (System.currentTimeMillis()-startTime) +"to put features into vector");
-	    
+
+		// LOGGER.info("took "+ (System.currentTimeMillis()-startTime)
+		// +"to put features into vector");
+
 		return fv.toArray(new SimpleFeature[0]);
 	}
 
@@ -2052,10 +2069,9 @@
 	}
 
 	public static Object getLayerSourceObject(MapLayer mapLayer) {
-		return 	getWrappedGeoObject((FeatureSource<SimpleFeatureType, SimpleFeature>) mapLayer
+		return getWrappedGeoObject((FeatureSource<SimpleFeatureType, SimpleFeature>) mapLayer
 				.getFeatureSource());
 	}
-	
 
 	/**
 	 * Checks whether the given attribute local name exists in the schema. If no
@@ -2167,6 +2183,5 @@
 	// gcArr[i] = (GeometryCollection)gcVec.elementAt(i);
 	// return gcArr;
 	// }
-	
 
 }



More information about the Schmitzm-commits mailing list