コード例 #1
0
  /**
   * Create a new Features from the provided coordinates and of the type indicated by geomType
   *
   * @param coordCRS The crs of the coordinates provided
   * @param destinationCRS The desired crs of the geometry
   * @param type the feature type of the object created
   * @param coordinates the coordinates that will be used to create the new feature
   * @param geomType the type of geometry that will be created
   * @return A new features.
   * @throws Exception
   */
  public static <T extends Geometry> SimpleFeature createFeature(
      CoordinateReferenceSystem coordCRS,
      CoordinateReferenceSystem destinationCRS,
      SimpleFeatureType type,
      Coordinate[] coordinates,
      Class<T> geomType)
      throws Exception {

    transform(coordCRS, destinationCRS, coordinates);
    Object[] attrs = new Object[type.getAttributeCount()];
    for (int i = 0; i < attrs.length; i++) {
      attrs[i] = setDefaultValue(type.getDescriptor(i));
    }
    final SimpleFeature newFeature = SimpleFeatureBuilder.build(type, attrs, null);
    // Class geomType = type.getDefaultGeometry().getType();

    T geom = GeometryBuilder.create().safeCreateGeometry(geomType, coordinates);
    newFeature.setDefaultGeometry(geom);

    return newFeature;
  }