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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Aug 26 17:38:07 CEST 2009


Author: alfonx
Date: 2009-08-26 17:38:06 +0200 (Wed, 26 Aug 2009)
New Revision: 326

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java
Log:
FeatureUtil now uses <SimpleFeatureType... generics

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-08-26 15:32:54 UTC (rev 325)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java	2009-08-26 15:38:06 UTC (rev 326)
@@ -70,6 +70,7 @@
 import org.geotools.styling.Style;
 import org.geotools.styling.StyleBuilder;
 import org.geotools.styling.Symbolizer;
+import org.geotools.util.SimpleInternationalString;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
 import org.opengis.filter.FilterFactory2;
@@ -199,7 +200,7 @@
    * Determines the kind of geometry of a {@link FeatureCollection}.
    * @param fc a feature collection
    */
-  public static GeometryForm getGeometryForm(FeatureCollection fc) {
+  public static GeometryForm getGeometryForm(FeatureCollection<SimpleFeatureType, SimpleFeature> fc) {
     return getGeometryForm(fc.getSchema());
   }
 
@@ -207,7 +208,7 @@
    * Determines the kind of geometry of a {@link FeatureSource}.
    * @param fs a feature source
    */
-  public static GeometryForm getGeometryForm(FeatureSource fs) {
+  public static GeometryForm getGeometryForm(FeatureSource<SimpleFeatureType, SimpleFeature> fs) {
     return getGeometryForm(fs.getSchema());
   }
 
@@ -243,11 +244,11 @@
    * @param fc FeatureCollection
    * @return Array aller Geometrien in der FeatureCollection.
    */
-  public static Vector<Geometry> extractGeometries(FeatureCollection fc, Vector<Geometry> result) {
+  public static Vector<Geometry> extractGeometries(FeatureCollection<SimpleFeatureType, SimpleFeature> fc, Vector<Geometry> result) {
     if ( result == null )
       result = new Vector<Geometry>();
 
-    FeatureIterator fi = fc.features();
+    FeatureIterator<SimpleFeature> fi = fc.features();
     for (;fi.hasNext();) {
       SimpleFeature f = fi.next();
       result.add( f.getDefaultGeometry() );
@@ -260,7 +261,7 @@
    * Und setzt eine default namen
    * @param fc FeatureCollection
    */
-  public static Style createDefaultStyle(FeatureCollection fc) {
+  public static Style createDefaultStyle(FeatureCollection<SimpleFeatureType, SimpleFeature> fc) {
     GeometryAttributeType geometryAttrib = fc.getSchema().getDefaultGeometry();
     return createDefaultStyle( geometryAttrib );
   }
@@ -285,7 +286,9 @@
       style = createLineStyle(Color.BLUE, 1);
 
     style.setName(DEFAULT_VECTOR_STYLE_NAME);
-    style.setTitle(DEFAULT_VECTOR_STYLE_NAME);
+    
+//    26 style.setTitle(DEFAULT_VECTOR_STYLE_NAME);
+    style.getDescription().setTitle( new SimpleInternationalString( DEFAULT_VECTOR_STYLE_NAME) );
     return style;
   }
 
@@ -315,7 +318,7 @@
    * @param width Groesse des Punkts
    */
   public static Style createPointStyle(Color fillColor, Color borderColor, double width) {
-    return createPointStyle(STYLE_BUILDER.MARK_CIRCLE, fillColor, borderColor, 1, 1, width, 0);
+    return createPointStyle(StyleBuilder.MARK_CIRCLE, fillColor, borderColor, 1, 1, width, 0);
   }
 
   /**
@@ -368,7 +371,7 @@
   * @param fc eine SimpleFeature Collection
   * @return einen leeren Array, wenn die Collection leer oder {@code null} ist
   */
-  public static SimpleFeature[] featuresToArray(FeatureCollection fc) {
+  public static SimpleFeature[] featuresToArray(FeatureCollection<SimpleFeatureType, SimpleFeature> fc) {
 //    if ( fc == null || fc.size() == 0 ) // bei leerer FC klappt .toArray nicht!!
 //      return new SimpleFeature[0];
 //    SimpleFeature[] featureArray = (SimpleFeature[])fc.toArray(new SimpleFeature[0]);
@@ -394,7 +397,7 @@
    *            Array kopiert
    * @return einen leeren Array, wenn die Collection leer oder {@code null} ist
    */
-   public static SimpleFeature[] featuresToArray(FeatureCollection fc, boolean includeNullFeatures) {
+   public static SimpleFeature[] featuresToArray(FeatureCollection<SimpleFeatureType, SimpleFeature> fc, boolean includeNullFeatures) {
 //     if ( includeNullFeatures )
 //       return featuresToArray(fc);
      if ( fc == null )
@@ -402,7 +405,7 @@
      
      // Naiv alle Features durchgehen.
      Vector<SimpleFeature> fv = new Vector<SimpleFeature>();
-     FeatureIterator fi = fc.features();
+     FeatureIterator<SimpleFeature> fi = fc.features();
      for (int i=0; fi.hasNext(); i++) {
        SimpleFeature f = fi.next();
        if ( includeNullFeatures || f != null )
@@ -526,7 +529,7 @@
    * @param attrName the attribute to order by
    * @return a list of ordered features
    */
-  public static Vector<SimpleFeature> sortFeatures(FeatureCollection fc, String attrName) {
+  public static Vector<SimpleFeature> sortFeatures(FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String attrName) {
     return sortFeatures(fc.features(), attrName);
   }
 
@@ -536,7 +539,7 @@
    * @param attrName the attribute to order by
    * @return a list of ordered features
    */
-  public static Vector<SimpleFeature> sortFeatures(FeatureIterator fi, String attrName) {
+  public static Vector<SimpleFeature> sortFeatures(FeatureIterator<SimpleFeature> fi, String attrName) {
     // First create a SortedMap with CollisionList
     SortedMap<Comparable<?>, Vector<SimpleFeature>> sortedFeatureLists = new TreeMap<Comparable<?>, Vector<SimpleFeature>>();
     for (;fi.hasNext();) {
@@ -580,14 +583,14 @@
    * @throws IllegalAttributeException falls das Einfuegen der Features in die
    *         neue {@link FeatureCollection} scheitert
    */
-  public static FeatureCollection extendFeatureCollection(FeatureCollection fc, AttributeType... aTypes) throws SchemaException, IllegalAttributeException  {
+  public static FeatureCollection<SimpleFeatureType, SimpleFeature> extendFeatureCollection(FeatureCollection<SimpleFeatureType, SimpleFeature> fc, AttributeType... aTypes) throws SchemaException, IllegalAttributeException  {
     // Schema erstellen
     SimpleFeatureType fType = fc.getSchema();
     SimpleFeatureType resultType = extendFeatureType( fType, aTypes );
 
     // Neue Collection erstellen
-    FeatureCollection resultFc = DefaultFeatureCollections.newCollection();
-    FeatureIterator   fi       = fc.features();
+    FeatureCollection<SimpleFeatureType, SimpleFeature> resultFc = DefaultFeatureCollections.newCollection();
+    FeatureIterator<SimpleFeature>   fi       = fc.features();
     // Array fuer die Attribut-Werte eines Features
     Object[]          fValues  = new Object[resultType.getAttributeCount()];
     for ( ; fi.hasNext(); ) {
@@ -623,7 +626,7 @@
    * @throws IllegalAttributeException falls das Einfuegen der Features in die
    *         neue {@link FeatureCollection} scheitert
    */
-  public static FeatureCollection joinFeatureCollection(JoinType joinType, FeatureCollection fc1, String joinAttr1, AttributeFilter compareOp, FeatureCollection fc2, String joinAttr2, String... projAttr) throws SchemaException, IllegalAttributeException  {
+  public static FeatureCollection<SimpleFeatureType, SimpleFeature> joinFeatureCollection(JoinType joinType, FeatureCollection<SimpleFeatureType, SimpleFeature> fc1, String joinAttr1, AttributeFilter compareOp, FeatureCollection<SimpleFeatureType, SimpleFeature> fc2, String joinAttr2, String... projAttr) throws SchemaException, IllegalAttributeException  {
     // RIGHT-OUTER-JOIN reaslisiert als "inverser" LEFT-OUTER-JOIN
     // Bemerkung: nur Uebergangsloesung, da nicht ganz sauber!!
     //            Attribut-Reihenfolge wird vertauscht...
@@ -682,7 +685,7 @@
 
     // Neue Collection erstellen
     DefaultFeatureCollection resultFc = (DefaultFeatureCollection)DefaultFeatureCollections.newCollection();
-    FeatureIterator fi = fc1.features();
+    FeatureIterator<SimpleFeature> fi = fc1.features();
     // Array fuer die Attribut-Werte eines Features
     Object[] fValues = new Object[resultType.getAttributeCount()];
 
@@ -702,7 +705,7 @@
       // Passende Features in 2. Colletion suchen
       filter.setAttributeName(joinAttr2);
       filter.setCompareValue(f1.getAttribute(joinAttr1));
-      FeatureIterator joinedFeatures = fc2.subCollection(filter).features();
+      FeatureIterator<SimpleFeature> joinedFeatures = fc2.subCollection(filter).features();
 
       // Wenn LEFT-OUTER-JOIN und JOIN nicht erfolgreich, ein Dummy
       // SimpleFeature mit Default-Werten in die Collection einfuegen
@@ -753,7 +756,7 @@
    * @throws IllegalAttributeException falls das Einfuegen der Features in die
    *         neue {@link FeatureCollection} scheitert
    */
-  public static FeatureCollection joinFeatureCollection(FeatureCollection fc1, String joinAttr1, AttributeFilter compareOp, FeatureCollection fc2, String joinAttr2, String... projAttr) throws SchemaException, IllegalAttributeException  {
+  public static FeatureCollection<SimpleFeatureType, SimpleFeature> joinFeatureCollection(FeatureCollection<SimpleFeatureType, SimpleFeature> fc1, String joinAttr1, AttributeFilter compareOp, FeatureCollection<SimpleFeatureType, SimpleFeature> fc2, String joinAttr2, String... projAttr) throws SchemaException, IllegalAttributeException  {
     return joinFeatureCollection(JoinType.FULL, fc1, joinAttr1, compareOp, fc2, joinAttr2, projAttr);
   }
 
@@ -773,7 +776,7 @@
    * @see #joinFeatureCollection(FeatureCollection, String, AttributeFilter, FeatureCollection, String)
    * @see #AttributeFilter.EQUALS
    */
-  public static FeatureCollection joinFeatureCollection(FeatureCollection fc1, String joinAttr1, FeatureCollection fc2, String joinAttr2, String... projAttr) throws SchemaException, IllegalAttributeException  {
+  public static FeatureCollection<SimpleFeatureType, SimpleFeature> joinFeatureCollection(FeatureCollection<SimpleFeatureType, SimpleFeature> fc1, String joinAttr1, FeatureCollection<SimpleFeatureType, SimpleFeature> fc2, String joinAttr2, String... projAttr) throws SchemaException, IllegalAttributeException  {
     return joinFeatureCollection(fc1,joinAttr1,AttributeFilter.EQUALS,fc2,joinAttr2,projAttr);
   }
 
@@ -884,7 +887,7 @@
       throw new IllegalArgumentException("Destination array "+destArray.length+" with start index "+destStartIdx+" too small for "+attrName.length+" attribute values!");
 
     // Wenn keine Attribute angegeben sind, alle verwenden
-    int attrCount = attrName.length > 0 ? attrName.length : f.getNumberOfAttributes();
+    int attrCount = attrName.length > 0 ? attrName.length : f.getAttributeCount();
     for (int i=0; i<attrCount; i++) {
       Object attr = attrName.length > 0 ? f.getAttribute(attrName[i]) : f.getAttribute(i);
       // wenn attr = null, dann gibt es das Attribut im SimpleFeature nicht
@@ -923,7 +926,7 @@
       for (int i=0; i<attrName.length; i++)
         destMap.put( attrName[i], f.getAttribute(attrName[i]) );
     else
-      for (int i=0; i<f.getNumberOfAttributes(); i++)
+      for (int i=0; i<f.getAttributeCount(); i++)
         destMap.put( f.getFeatureType().getAttributeType(i).getName(), f.getAttribute(i) );
 
     return destMap;
@@ -944,7 +947,7 @@
    * @throws IllegalAttributeException falls das Einfuegen der Features in die
    *         neue {@link FeatureCollection} scheitert
    */
-  public static FeatureCollection joinFeatureCollection(FeatureCollection fc, String fcJoinAttr, ResultSet rs, String rsJoinAttr, String... projAttr) throws SchemaException, IllegalAttributeException, SQLException  {
+  public static FeatureCollection<SimpleFeatureType, SimpleFeature> joinFeatureCollection(FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String fcJoinAttr, ResultSet rs, String rsJoinAttr, String... projAttr) throws SchemaException, IllegalAttributeException, SQLException  {
     return joinFeatureCollection(fc, fcJoinAttr, AttributeFilter.EQUALS, rs, rsJoinAttr);
   }
 
@@ -964,7 +967,7 @@
    * @throws IllegalAttributeException falls das Einfuegen der Features in die
    *         neue {@link FeatureCollection} scheitert
    */
-  public static FeatureCollection joinFeatureCollection(FeatureCollection fc, String fcJoinAttr, AttributeFilter compareOp, ResultSet rs, String rsJoinAttr, String... projAttr) throws SchemaException, IllegalAttributeException, SQLException  {
+  public static FeatureCollection<SimpleFeatureType, SimpleFeature> joinFeatureCollection(FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String fcJoinAttr, AttributeFilter compareOp, ResultSet rs, String rsJoinAttr, String... projAttr) throws SchemaException, IllegalAttributeException, SQLException  {
     return joinFeatureCollection(JoinType.LEFT_OUTER, fc, fcJoinAttr, compareOp, rs, rsJoinAttr, projAttr);
 
   }
@@ -986,7 +989,7 @@
    * @throws IllegalAttributeException falls das Einfuegen der Features in die
    *         neue {@link FeatureCollection} scheitert
    */
-  public static FeatureCollection joinFeatureCollection(JoinType joinType, FeatureCollection fc, String fcJoinAttr, AttributeFilter compareOp, ResultSet rs, String rsJoinAttr, String... projAttr) throws SchemaException, IllegalAttributeException, SQLException  {
+  public static FeatureCollection<SimpleFeatureType, SimpleFeature> joinFeatureCollection(JoinType joinType, FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String fcJoinAttr, AttributeFilter compareOp, ResultSet rs, String rsJoinAttr, String... projAttr) throws SchemaException, IllegalAttributeException, SQLException  {
     if ( fcJoinAttr == null || fcJoinAttr.trim().equals("") ) {
       // Erste Nicht-Geometrie-Spalte suchen
       for (AttributeType aType : fc.getSchema().getAttributeTypes()) {
@@ -1003,7 +1006,7 @@
     }
 
     // FeatureCollection aus ResultSet erzeugen
-    FeatureCollection rsFeatureCollection = createFeatureCollection(
+    FeatureCollection<SimpleFeatureType, SimpleFeature> rsFeatureCollection = createFeatureCollection(
         rs,
         // fuer den JOIN muss das Join-Attribut vorhanden sein!
         projAttr.length > 0 ? LangUtil.extendArray(projAttr,rsJoinAttr) : projAttr
@@ -1032,7 +1035,7 @@
    * @throws SchemaException falls das Erzeugen des SimpleFeatureType scheitert
    * @throws IllegalAttributeException falls das Erzeugen eines Features scheitert
    */
-  public static FeatureCollection createFeatureCollection(ResultSet rs, String... projAttr) throws SchemaException, IllegalAttributeException, SQLException {
+  public static FeatureCollection<SimpleFeatureType, SimpleFeature> createFeatureCollection(ResultSet rs, String... projAttr) throws SchemaException, IllegalAttributeException, SQLException {
     // Schema der FeatureCollection erzeugen
     SimpleFeatureType rsFeatureType = createFeatureType(rs.getMetaData(),projAttr);
 
@@ -1040,7 +1043,7 @@
     Object[] rsFeatureValues = new Object[rsFeatureType.getAttributeCount()];
 
     // ResultSet in FeatureCollection uebertragen
-    FeatureCollection rsFeatureCollection = DefaultFeatureCollections.newCollection();
+    FeatureCollection<SimpleFeatureType, SimpleFeature> rsFeatureCollection = DefaultFeatureCollections.newCollection();
     for ( ;rs.next(); ) {
       for (int i=0; i<rsFeatureType.getAttributeCount(); i++)
         rsFeatureValues[i] = rs.getObject( rsFeatureType.getAttributeType(i).getName() );
@@ -1249,8 +1252,8 @@
 	 * @param features 
 	 * @return
 	 */
-	public static FeatureSource createMemoryFeatureSource(
-			FeatureCollection features) {
+	public static FeatureSource<SimpleFeatureType, SimpleFeature> createMemoryFeatureSource(
+			FeatureCollection<SimpleFeatureType, SimpleFeature> features) {
 		try {
 			return  new MemoryDataStore(
 					features).getFeatureSource(features



More information about the Schmitzm-commits mailing list