public static SimpleFeatureCollection featureCollectionFromGeometry( CoordinateReferenceSystem crs, Geometry... geometries ) {
        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("simplegeom");
        b.setCRS(crs);

        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();

        EGeometryType geometryType = EGeometryType.forGeometry(geometries[0]);
        b.add("the_geom", geometryType.getClazz());

        Object userData = geometries[0].getUserData();
        int userDataSize = 1;
        if (userData != null) {
            if (userData instanceof String[]) {
                String[] string = (String[]) userData;
                userDataSize = string.length;
                for( int i = 0; i < userDataSize; i++ ) {
                    b.add("data" + i, String.class);
                }
            } else {
                b.add("userdata", userData.getClass());
            }
        }

        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        for( Geometry g : geometries ) {
            Object[] values;
            if (userData == null) {
                values = new Object[]{g};
            } else {
                Object tmpUserData = g.getUserData();
                if (tmpUserData instanceof String[]) {
                    String[] string = (String[]) tmpUserData;
                    values = new Object[userDataSize + 1];
                    values[0] = g;
                    for( int i = 0; i < string.length; i++ ) {
                        values[i + 1] = string[i];
                    }
                } else {
                    values = new Object[]{g, tmpUserData};
                }
            }
            builder.addAll(values);
            SimpleFeature feature = builder.buildFeature(null);
            newCollection.add(feature);
        }
        return newCollection;
    }
public static SimpleFeatureCollection featureCollectionFromGeometry ( CoordinateReferenceSystem crs , Geometry ... geometries ) { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder ( ) ; b . setName ( "simplegeom" ) ; b . setCRS ( crs ) ; DefaultFeatureCollection newCollection = new DefaultFeatureCollection ( ) ; EGeometryType geometryType = EGeometryType . forGeometry ( geometries [ 0 ] ) ; b . add ( "the_geom" , geometryType . getClazz ( ) ) ; Object userData = geometries [ 0 ] . getUserData ( ) ; int userDataSize = 1 ; if ( userData != null ) { if ( userData instanceof String [ ] ) { String [ ] string = ( String [ ] ) userData ; userDataSize = string . length ; for ( int i = 0 ; i < userDataSize ; i ++ ) { b . add ( "data" + i , String . class ) ; } } else { b . add ( "userdata" , userData . getClass ( ) ) ; } } SimpleFeatureType type = b . buildFeatureType ( ) ; SimpleFeatureBuilder builder = new SimpleFeatureBuilder ( type ) ; for ( Geometry g : geometries ) { Object [ ] values ; if ( userData == null ) { values = new Object [ ] { g } ; } else { Object tmpUserData = g . getUserData ( ) ; if ( tmpUserData instanceof String [ ] ) { String [ ] string = ( String [ ] ) tmpUserData ; values = new Object [ userDataSize + 1 ] ; values [ 0 ] = g ; for ( int i = 0 ; i < string . length ; i ++ ) { values [ i + 1 ] = string [ i ] ; } } else { values = new Object [ ] { g , tmpUserData } ; } } builder . addAll ( values ) ; SimpleFeature feature = builder . buildFeature ( null ) ; newCollection . add ( feature ) ; } return newCollection ; }
Make a {@link SimpleFeatureCollection} from a set of {@link Geometry}.

<p>This is a fast utility and adds no attributes.</p>

@param crs The {@link CoordinateReferenceSystem}.
@param geometries the set of {@link Geometry} to add.
@return the features wrapping the geoms.