コード例 #1
0
  public static SimpleFeatureType toReShapeFeatureType(
      SimpleFeatureCollection delegate, List<Definition> definitionList) {

    SimpleFeature sample = null;
    SimpleFeatureIterator iterator = delegate.features();
    try {
      if (iterator.hasNext()) {
        sample = iterator.next();
      }
    } finally {
      iterator.close(); // good bye
    }

    SimpleFeatureTypeBuilder build = new SimpleFeatureTypeBuilder();
    SimpleFeatureType origional = delegate.getSchema();

    for (Definition def : definitionList) {
      String name = def.name;
      Expression expression = def.expression;

      Object value = null;
      if (sample != null) {
        value = expression.evaluate(sample);
      }
      Class<?> binding = def.binding; // make use of any default binding hint provided by user
      if (value == null) {
        if (expression instanceof PropertyName) {
          PropertyName propertyName = (PropertyName) expression;
          String path = propertyName.getPropertyName();
          AttributeDescriptor descriptor = origional.getDescriptor(name);
          AttributeType attributeType = descriptor.getType();
          binding = attributeType.getBinding();
        }
      } else {
        binding = value.getClass();
      }

      if (binding == null) {
        // note we could consider scanning through additional samples until we get a non null hit
        throw new IllegalArgumentException("Unable to determine type for " + name);
      }

      if (Geometry.class.isAssignableFrom(binding)) {
        CoordinateReferenceSystem crs;
        AttributeType originalAttributeType = origional.getType(name);
        if (originalAttributeType != null && originalAttributeType instanceof GeometryType) {
          GeometryType geometryType = (GeometryType) originalAttributeType;
          crs = geometryType.getCoordinateReferenceSystem();
        } else {
          crs = origional.getCoordinateReferenceSystem();
        }
        build.crs(crs);
        build.add(name, binding);
      } else {
        build.add(name, binding);
      }
    }
    build.setName(origional.getTypeName());
    return build.buildFeatureType();
  }
コード例 #2
0
 private void printAttributeDescriptor(Writer w, PropertyDescriptor attrib)
     throws IOException {
   print(w, attrib.getName().toString());
   print(w, "\t");
   print(w, FieldType.forBinding(attrib.getType().getBinding()).name());
   print(w, "\t");
   print(w, Integer.toString(attrib.getMinOccurs()));
   print(w, "\t");
   print(w, Integer.toString(attrib.getMaxOccurs()));
   print(w, "\t");
   print(w, Boolean.toString(attrib.isNillable()));
   PropertyType attrType = attrib.getType();
   if (attrType instanceof GeometryType) {
     GeometryType gt = (GeometryType) attrType;
     CoordinateReferenceSystem crs = gt.getCoordinateReferenceSystem();
     String crsText = CrsTextSerializer.serialize(crs);
     print(w, "\t");
     println(w, crsText);
   } else {
     println(w, "");
   }
 }
コード例 #3
0
  /**
   * Clones the given schema, changing the geometry attribute to match the given dimensionality.
   *
   * @param schema schema to clone
   * @param dimensionality dimensionality for the geometry 1= points, 2= lines, 3= polygons
   */
  private FeatureType cloneWithDimensionality(FeatureType schema, int dimensionality) {
    SimpleFeatureType simpleFt = (SimpleFeatureType) schema;
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setName(schema.getName());
    builder.setCRS(schema.getCoordinateReferenceSystem());
    for (AttributeDescriptor desc : simpleFt.getAttributeDescriptors()) {
      if (isMixedGeometry(desc)) {
        GeometryDescriptor geomDescriptor = (GeometryDescriptor) desc;
        GeometryType geomType = geomDescriptor.getType();

        Class<?> geometryClass = getGeometryForDimensionality(dimensionality);

        GeometryType gt =
            new GeometryTypeImpl(
                geomType.getName(),
                geometryClass,
                geomType.getCoordinateReferenceSystem(),
                geomType.isIdentified(),
                geomType.isAbstract(),
                geomType.getRestrictions(),
                geomType.getSuper(),
                geomType.getDescription());

        builder.add(
            new GeometryDescriptorImpl(
                gt,
                geomDescriptor.getName(),
                geomDescriptor.getMinOccurs(),
                geomDescriptor.getMaxOccurs(),
                geomDescriptor.isNillable(),
                geomDescriptor.getDefaultValue()));
      } else {
        builder.add(desc);
      }
    }
    schema = builder.buildFeatureType();
    return schema;
  }