[Schmitzm-commits] r1539 - in trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools: . feature

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Mar 25 12:51:56 CET 2011


Author: alfonx
Date: 2011-03-25 12:51:54 +0100 (Fri, 25 Mar 2011)
New Revision: 1539

Modified:
   trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/GTUtil.java
   trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/feature/FeatureUtil.java
Log:


Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/GTUtil.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/GTUtil.java	2011-03-23 18:05:11 UTC (rev 1538)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/GTUtil.java	2011-03-25 11:51:54 UTC (rev 1539)
@@ -532,11 +532,15 @@
 	}
 
 	/**
-	 * Tries to determin the EPSG:XXXX definition of a CRS.
+	 * Tries to determin the EPSG:XXXX definition of a CRS. @Return null is no
+	 * EPSG code could be found.
 	 */
 	public static String getEPSG(CoordinateReferenceSystem crs) {
 		try {
-			return "EPSG:" + CRS.lookupEpsgCode(crs, true);
+			final Integer lookupEpsgCode = CRS.lookupEpsgCode(crs, true);
+			if (lookupEpsgCode == null)
+				return null;
+			return "EPSG:" + lookupEpsgCode;
 		} catch (FactoryException e) {
 			throw new RuntimeException(e);
 		}

Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/feature/FeatureUtil.java	2011-03-23 18:05:11 UTC (rev 1538)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/feature/FeatureUtil.java	2011-03-25 11:51:54 UTC (rev 1539)
@@ -276,11 +276,11 @@
 		 * column.
 		 */
 		NONE
-//		, 
-//		/**
-//		 * TODO Is there any problem when we mix Raster and Vector here.
-//		 */
-//		RASTER
+		// ,
+		// /**
+		// * TODO Is there any problem when we mix Raster and Vector here.
+		// */
+		// RASTER
 	}
 
 	/**
@@ -3008,4 +3008,38 @@
 		return result;
 	}
 
+	/**
+	 * @returns a List of n values of the requested attribute
+	 * @param features
+	 *            Where to read the features from
+	 * @param att
+	 *            which attribute to query
+	 * @param n
+	 *            how many samples to get
+	 */
+	public static List<String> getSamples(
+			FeatureCollection<SimpleFeatureType, SimpleFeature> features,
+			String att, int n) {
+
+		List<String> strings = new ArrayList<String>();
+
+		int count = 0;
+		Iterator<SimpleFeature> iterator = features.iterator();
+		try {
+			while (iterator.hasNext() && count < n) {
+				SimpleFeature f = iterator.next();
+				Object o = f.getAttribute(att);
+				if (o == null)
+					strings.add("LEER");
+				else
+					strings.add(o.toString());
+				count++;
+			}
+		} finally {
+			features.close(iterator);
+		}
+
+		return strings;
+	}
+
 }



More information about the Schmitzm-commits mailing list