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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Aug 31 14:16:39 CEST 2009


Author: mojays
Date: 2009-08-31 14:16:37 +0200 (Mon, 31 Aug 2009)
New Revision: 349

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java
Log:
gt2-2.6.x conversion bugs eliminated
NO MORE ERRORS IN FeatureUtil!!! :-)

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-31 12:06:30 UTC (rev 348)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java	2009-08-31 12:16:37 UTC (rev 349)
@@ -60,10 +60,10 @@
 import org.geotools.feature.DefaultFeatureCollections;
 import org.geotools.feature.FeatureCollection;
 import org.geotools.feature.FeatureIterator;
-import org.geotools.feature.FeatureTypeBuilder;
 import org.geotools.feature.GeometryAttributeType;
 import org.geotools.feature.SchemaException;
 import org.geotools.feature.simple.SimpleFeatureBuilder;
+import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
 import org.geotools.feature.type.GeometricAttributeType;
 import org.geotools.filter.FilterFactory;
 import org.geotools.map.MapLayer;
@@ -78,9 +78,11 @@
 import org.opengis.feature.simple.SimpleFeatureType;
 import org.opengis.feature.type.AttributeDescriptor;
 import org.opengis.feature.type.GeometryDescriptor;
+import org.opengis.filter.Filter;
 import org.opengis.filter.FilterFactory2;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 
+import schmitzm.geotools.FilterUtil;
 import schmitzm.lang.LangUtil;
 import schmitzm.lang.ResourceProvider;
 
@@ -379,7 +381,7 @@
    * @param lineWidth Breite der Linie
    */
   public static Style createLineStyle(Color lineColor, double lineWidth) {
-	  // TODO I don't like StyleBuilder!
+    // TODO I don't like StyleBuilder!
     final Symbolizer symb = STYLE_BUILDER.createLineSymbolizer(lineColor, lineWidth);
     return STYLE_BUILDER.createStyle( symb );
   }
@@ -450,15 +452,15 @@
     if ( fTypeName == null )
       fTypeName = fType.getTypeName();
 
-    FeatureTypeBuilder builder = FeatureTypeBuilder.newInstance(fType.getTypeName());
+    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
+    builder.setName(fType.getTypeName());
     for (AttributeDescriptor aType : fType.getAttributeDescriptors() ) {
       AttributeDescriptor aTypeClone = cloneAttributeType(aType, nillable);
+      builder.add(aTypeClone);
       if ( aTypeClone instanceof GeometryAttributeType && builder.getDefaultGeometry() == null )
-        builder.setDefaultGeometry( (GeometryAttributeType)aTypeClone );
-      else
-        builder.addType(aTypeClone);
+        builder.setDefaultGeometry( aTypeClone.getLocalName() );
     }
-    return builder.getFeatureType();
+    return builder.buildFeatureType();
   }
 
   /**
@@ -484,12 +486,16 @@
     if ( aType instanceof GeometryAttributeType )
       metaData = ((GeometryAttributeType)aType).getCoordinateSystem();
 
+    // combine the restrictions of the attribute type for the
+    // AttributeTypeFactory
+    Filter restrictions = FilterUtil.FILTER_FAC.and( aType.getType().getRestrictions() );
+    
     // Create the clone
     return AttributeTypeFactory.newAttributeType(
             aType.getLocalName(),
             aType.getType().getBinding(),
             nillable,
-            aType.getType().getRestrictions(),
+            restrictions,
             defaultValue,
             metaData
            );
@@ -504,6 +510,19 @@
    * @throws SchemaException falls das Erweitern des SimpleFeature-Schemas scheitert
    * @throws NullPointerException falls {@code fType = null}
    */
+  public static SimpleFeatureType extendFeatureType(SimpleFeatureType fType, List<AttributeDescriptor> aTypes) throws SchemaException {
+    return extendFeatureType(fType, aTypes.toArray(new AttributeDescriptor[0]));
+  }
+  
+  /**
+   * Erweitert das Schema einer {@link FeatureCollection} um eine Reihe von
+   * Attributen.
+   * @param fType  zu erweiterndes SimpleFeature-Schema
+   * @param aTypes Typen der neuen Attribute
+   * @return eine <b>neue</b> Instanz von {@link SimpleFeatureType}
+   * @throws SchemaException falls das Erweitern des SimpleFeature-Schemas scheitert
+   * @throws NullPointerException falls {@code fType = null}
+   */
   public static SimpleFeatureType extendFeatureType(SimpleFeatureType fType, AttributeDescriptor... aTypes) throws SchemaException {
 //BEMERKUNG: Folgende Methode funktioniert, fuegt die abgeleiteten (alten)
 //           Attribute aber hinten an die neuen Attribute an. Dies ist
@@ -516,25 +535,31 @@
 //        new SimpleFeatureType[] { fType },
 //        null
 //    );
-    FeatureTypeBuilder builder = FeatureTypeBuilder.newInstance(fType.getTypeName());
-    builder.addTypes( fType.getAttributeTypes() ); // old attributes
-    for (AttributeDescriptor aType : aTypes )
+
+    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
+    builder.setName( fType.getName() );
+    builder.addAll( fType.getAttributeDescriptors() ); // old attributes
+    for (AttributeDescriptor aType : aTypes ) {
+      // combine the restrictions of the attribute type for the
+      // AttributeTypeFactory
+      Filter restrictions = FilterUtil.FILTER_FAC.and( aType.getType().getRestrictions() );
+
       try {
+        builder.add(aType);
         if ( aType instanceof GeometryAttributeType && builder.getDefaultGeometry() == null )
-          builder.setDefaultGeometry( (GeometryAttributeType)aType );
-        else
-          builder.addType(aType);
+          builder.setDefaultGeometry( aType.getLocalName() );
       } catch (IllegalArgumentException err) {
-        builder.addType( AttributeTypeFactory.newAttributeType(
+        builder.add( AttributeTypeFactory.newAttributeType(
             aType.getLocalName()+"_2",
             aType.getType().getBinding(),
             aType.isNillable(),
-            aType.getRestriction(),
+            restrictions,
             aType.getDefaultValue(),
             null
         ));
       }
-    SimpleFeatureType resultType = builder.getFeatureType();
+    }
+    SimpleFeatureType resultType = builder.buildFeatureType();
 
     // As long as DataUtilities.defaultValue(AttributeDescriptor) does
     // not handle the default value correctly for not-nillable
@@ -626,7 +651,7 @@
       for ( int i=fType.getAttributeCount(); i<fValues.size(); i++)
         fValues.set(i,resultType.getAttributeDescriptors().get(i).getDefaultValue());
       // Erweitertes SimpleFeature erzeugen und FeatureCollection fuellen
-      resultFc.add( resultType.create( fValues ) );
+      resultFc.add( createFeature(resultType,fValues ) );
     }
 
     return resultFc;
@@ -690,7 +715,8 @@
         resultType = extendFeatureType(fType1, fType2.getAttributeDescriptors());
     else {
       // Leeren SimpleFeature-Type erzeugen
-      FeatureTypeBuilder builder = FeatureTypeBuilder.newInstance(fType1.getTypeName());
+      SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
+      builder.setName(fType1.getName());
       // Projektions-Attribute hinzufuegen
       for (String attrName : projAttr) {
         // erste Wahl: Attribut von fc2 uebernehmen (da beim Belegen
@@ -703,10 +729,10 @@
           aType = fType1.getDescriptor(attrName);
         // Attribut in den SimpleFeatureType einfuegen
         if ( aType != null )
-          builder.addType( aType );
+          builder.add( aType );
       }
       // SimpleFeatureType erzeugen
-      resultType = builder.getFeatureType();
+      resultType = builder.buildFeatureType();
     }
 
     // Neue Collection erstellen
@@ -723,7 +749,7 @@
       // Werte der 1. Features in Array schreiben
       if ( !projection )
         // Alle Attribut-Werte aus fc1
-        f1.getAttributes(fValues);
+        getAttributeValues(f1,fValues,0);
       else
         // Nur Werte der Projektions-Attribute aus fc1
         getAttributeValues(f1,fValues,0,projAttr);
@@ -1129,7 +1155,8 @@
 
     // Fuer alle Attribute aus Metadaten einen AttributeDescriptor erzeugen
     // und diesen in SimpleFeatureType uebernehmen
-    FeatureTypeBuilder   featureTypeFac = FeatureTypeBuilder.newInstance(featureTypeName);
+    SimpleFeatureTypeBuilder   featureTypeFac = new SimpleFeatureTypeBuilder();
+    featureTypeFac.setName(featureTypeName);
     for (int i=1; i<=metaData.getColumnCount(); i++) {
       String columnName = metaData.getColumnName(i);
       // Attribut nur uebernehmen, wenn als Projektions-Attribut angegeben
@@ -1151,7 +1178,7 @@
         LOGGER.warn("Could not create default value for not-null attribute '"+columnName+"': "+columnClass.getSimpleName());
 
       // Add an attribute for the column to the SimpleFeatureType
-      featureTypeFac.addType( AttributeTypeFactory.newAttributeType(
+      featureTypeFac.add( AttributeTypeFactory.newAttributeType(
         columnName,
         columnClass,
         nillable,
@@ -1160,7 +1187,7 @@
         null  // no meta data
       ));
     }
-    return featureTypeFac.getFeatureType();
+    return featureTypeFac.buildFeatureType();
   }
 
   /**
@@ -1175,16 +1202,17 @@
     if ( featureTypeName == null )
       featureTypeName = "SimpleFeatureType";
 
-    FeatureTypeBuilder featureTypeFac = FeatureTypeBuilder.newInstance(featureTypeName);
+    SimpleFeatureTypeBuilder featureTypeFac = new SimpleFeatureTypeBuilder();
+    featureTypeFac.setName(featureTypeName);
     for (String attrName : attrValues.keySet()) {
       Object attrValue = attrValues.get( attrName );
       Class  attrClass = attrValue == null ? defaultAttrClass : attrValue.getClass();
-      featureTypeFac.addType( AttributeTypeFactory.newAttributeType(
+      featureTypeFac.add( AttributeTypeFactory.newAttributeType(
         attrName,
         attrClass
       ));
     }
-    return featureTypeFac.getFeatureType();
+    return featureTypeFac.buildFeatureType();
   }
 
   /**



More information about the Schmitzm-commits mailing list