[Schmitzm-commits] r357 - in branches/1.0-gt2-2.6/src/schmitzm/geotools: feature gui

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Aug 31 15:52:42 CEST 2009


Author: mojays
Date: 2009-08-31 15:52:40 +0200 (Mon, 31 Aug 2009)
New Revision: 357

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

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 13:20:02 UTC (rev 356)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java	2009-08-31 13:52:40 UTC (rev 357)
@@ -1241,6 +1241,18 @@
    * @param crs       Koordinatensystem
    */
   public static GeometryAttributeType createGeometryAttributeType(Class<? extends Geometry> geomType, Geometry defGeom, CoordinateReferenceSystem crs) {
+    return createGeometryAttributeType(null, geomType, defGeom, crs);
+  }
+  
+  /**
+   * Erzeugt einen Geometrie-Attribut-Typ.
+   * @param attrName  Name des attribute (wenn {@code null}, wird "the_geom"
+   *                  verwendet)
+   * @param geomType  Art der Geometrie
+   * @param defGeom   Standard-Wert
+   * @param crs       Koordinatensystem
+   */
+  public static GeometryAttributeType createGeometryAttributeType(String attrName, Class<? extends Geometry> geomType, Geometry defGeom, CoordinateReferenceSystem crs) {
 //    return new GeometricAttributeType(
 //        "the_geom",
 //        geomType,
@@ -1249,8 +1261,11 @@
 //        crs,
 //        null
 //      );
+    if ( attrName == null )
+      attrName = "the_geom";
+    
     return (GeometryAttributeType)AttributeTypeFactory.newAttributeType(
-        "the_geom",
+        attrName,
         geomType,
         false, // nillable
         null,  // restrictions

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/JEditorPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/JEditorPane.java	2009-08-31 13:20:02 UTC (rev 356)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/JEditorPane.java	2009-08-31 13:52:40 UTC (rev 357)
@@ -47,6 +47,7 @@
 import org.geotools.feature.FeatureTypeBuilder;
 import org.geotools.feature.GeometryAttributeType;
 import org.geotools.feature.SchemaException;
+import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
 import org.geotools.feature.type.GeometricAttributeType;
 import org.geotools.map.DefaultMapContext;
 import org.geotools.map.DefaultMapLayer;
@@ -732,7 +733,7 @@
     Coordinate[] coord      = segmUndoPoints.toArray(new Coordinate[0]);
     LineString   lineString = createGeometryFromPoints(LineString.class, coord);
     try {
-      return segmLineFeatureType.create( new Object[] {lineString} );
+      return FeatureUtil.createFeature(segmLineFeatureType, lineString );
     } catch (Exception e) {
       throw new RuntimeException(e);
     }
@@ -752,7 +753,7 @@
     Coordinate[] coord      = segmUndoPoints.toArray(new Coordinate[0]);
     MultiPoint   multiPoint = createGeometryFromPoints(MultiPoint.class, coord);
     try {
-      return segmPointFeatureType.create( new Object[] {multiPoint} );
+      return FeatureUtil.createFeature(segmPointFeatureType,multiPoint);
     } catch (Exception e) {
       throw new RuntimeException(e);
     }
@@ -781,7 +782,7 @@
             attr[i] = FeatureUtil.getNextAutoValue(aType);
         }
         // create new feature
-        feature = editorFeatureType.create(attr);
+        feature = FeatureUtil.createFeature(editorFeatureType,attr);
       }
       feature.setDefaultGeometry(
           createGeometryFromPoints(getGeometryType(editorMode), coord )
@@ -864,24 +865,27 @@
    * @param ftype a feature type which is extended (can be {@code null})
    */
   private SimpleFeatureType createFeatureType(Class<? extends Geometry> gtype, SimpleFeatureType ftype) {
-    GeometryAttributeType geomAttrType = new GeometricAttributeType(
+//    GeometryAttributeType geomAttrType = new GeometricAttributeType(
+//        GEOMETRY_ATTR,
+//        gtype,
+//        false,
+//        createGeometryFromPoints(gtype,null),
+//        mapContext.getCoordinateReferenceSystem(),
+//        null
+//    );
+    GeometryAttributeType geomAttrType = FeatureUtil.createGeometryAttributeType(
         GEOMETRY_ATTR,
         gtype,
-        false,
         createGeometryFromPoints(gtype,null),
-        mapContext.getCoordinateReferenceSystem(),
-        null
+        mapContext.getCoordinateReferenceSystem()
     );
-    String ftypeName           = ftype != null ? ftype.getTypeName() : gtype.getSimpleName()+"_feature";
-    FeatureTypeBuilder builder = FeatureTypeBuilder.newInstance(ftypeName);
-    builder.setDefaultGeometry( geomAttrType );
-    if ( ftype != null )
-      builder.addTypes( ftype.getAttributeTypes() );
-    try {
-      return builder.getFeatureType();
-    } catch ( SchemaException err ) {
-      throw new RuntimeException(err);
-    }
+    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
+    builder.init(ftype);
+    if ( ftype == null )
+      builder.setName( gtype.getSimpleName()+"_feature" );
+    builder.add( geomAttrType ); // automatically sets the default geometry! 
+    
+    return builder.buildFeatureType();
   }
 
   /**
@@ -905,7 +909,7 @@
    */
   private static SimpleFeature createDummyFeature(SimpleFeatureType ftype) {
     try {
-      return ftype.create( FeatureUtil.getDefaultAttributeValues(ftype) );
+      return FeatureUtil.createSampleFeature(ftype);
     } catch (Exception e) {
       throw new RuntimeException(e);
     }



More information about the Schmitzm-commits mailing list