Package org.geotools.feature.simple

Examples of org.geotools.feature.simple.SimpleFeatureBuilder


        tb.add( "name", String.class );
        tb.add( "description", String.class );
        tb.add( "geometry", Geometry.class );
       
        GeometryFactory gf = new GeometryFactory();
        SimpleFeatureBuilder sb = new SimpleFeatureBuilder( tb.buildFeatureType() );
        ArrayList features = new ArrayList();
       
        sb.add( "one" );
        sb.add( "the first feature");
        sb.add( gf.createPoint( new Coordinate(1, 1) ) ) ;
        features.add( sb.buildFeature("1"));
       
        sb.add( "two" );
        sb.add( "the second feature");
        sb.add( gf.createPoint( new Coordinate(2, 2) ) ) ;
        features.add( sb.buildFeature("2"));
       
        sb = new SimpleFeatureBuilder(DocumentTypeBinding.FeatureType);
        sb.set( "Feature", features );
        SimpleFeature f = sb.buildFeature("kml");
       
        Encoder encoder = new Encoder(new KMLConfiguration());
        encoder.setIndenting(true);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        encoder.encode(f, KML.kml, out );
View Full Code Here


     *
     * @throws IOException In the event of a parsing error or if the input json is invalid.
     */
    public SimpleFeature readFeature(Object input) throws IOException {
        return GeoJSONUtil.parse(new FeatureHandler(
            featureType != null ? new SimpleFeatureBuilder(featureType): null, attio
        ), input, false);
    }
View Full Code Here

        }
        if (geometry != null) {
            addGeometryType(typeBuilder, geometry);
        }
       
        return new SimpleFeatureBuilder(typeBuilder.buildFeatureType());
    }
View Full Code Here

        typeBuilder.setDefaultGeometry("geometry");
    }

    SimpleFeature buildFeature() {
     
        SimpleFeatureBuilder builder = this.builder != null ? this.builder : createBuilder();
        SimpleFeatureType featureType = builder.getFeatureType();
        SimpleFeature f = builder.buildFeature(id);
        if (geometry != null) {
            if(featureType.getGeometryDescriptor() == null) {
                //GEOT-4293, case of geometry coming after properties, we have to retype
                // the builder
                // JD: this is ugly, we should really come up with a better way to store internal
                // state of properties, and avoid creating the builder after the properties object
                // is completed
                SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
                typeBuilder.init(featureType);
                addGeometryType(typeBuilder, geometry);

                featureType = typeBuilder.buildFeatureType();
                SimpleFeatureBuilder newBuilder = new SimpleFeatureBuilder(featureType);
                newBuilder.init(f);
                f = newBuilder.buildFeature(id);
            }
            f.setAttribute(featureType.getGeometryDescriptor().getLocalName(), geometry);
        }       
        return f;
    }
View Full Code Here

        ContentFeatureCollection features = fs.getFeatures();
        assertPrimaryKeyValues(features, 3);

        SimpleFeatureType featureType = fs.getSchema();
        SimpleFeatureBuilder b = new SimpleFeatureBuilder( featureType );
        b.add("four");
        b.add( new GeometryFactory().createPoint( new Coordinate(4,4) ) );

        SimpleFeature f = b.buildFeature(null);
        fs.addFeatures( DataUtilities.collection(f));

        //pattern match to handle the multi primary key case
        assertTrue(((String)f.getUserData().get( "fid" )).matches( tname(featureType.getTypeName()) + ".4(\\..*)?"));

 
View Full Code Here

     */
    static final DecimalFormatSymbols DECIMAL_SYMBOLS = new DecimalFormatSymbols();

    public FeatureMapper(SimpleFeatureType targetSchema, Object layer, GeometryFactory geomFactory, OGR ogr) {
        this.schema = targetSchema;
        this.builder = new SimpleFeatureBuilder(schema);
        this.geomMapper = new GeometryMapper.WKB(geomFactory, ogr);
        this.geomFactory = geomFactory;
        this.ogr = ogr;

        attributeIndexes = new HashMap<String, Integer>();
View Full Code Here

        this(null, null);
    }

    public FeatureCollectionHandler(SimpleFeatureType featureType, AttributeIO attio) {
        if (featureType != null) {
            builder = new SimpleFeatureBuilder(featureType);
        }
      
        if (attio == null) {
            if (featureType != null) {
                attio = new FeatureTypeAttributeIO(featureType);
View Full Code Here

                    SimpleFeatureType featureType = feature.getFeatureType();
                    if (featureType.getCoordinateReferenceSystem() == null && crs != null){
                        //retype with a crs
                        featureType = SimpleFeatureTypeBuilder.retype(featureType, crs);
                    }
                    builder = new SimpleFeatureBuilder(featureType);
                }
               
                ((FeatureHandler)delegate).init();
                //we want to pause at this point
                return false;
View Full Code Here

        return ftBuilder.buildFeatureType();
    }

    public static SimpleFeature feature(SimpleFeatureType fType, String fid, Node node)
        throws Exception {
        SimpleFeatureBuilder b = new SimpleFeatureBuilder(fType);

        Object[] attributes = new Object[fType.getAttributeCount()];

        for (int i = 0; i < fType.getAttributeCount(); i++) {
            AttributeDescriptor att = fType.getDescriptor(i);
            AttributeType attType = att.getType();
            Object attValue = node.getChildValue(att.getLocalName());

            if ((attValue != null) && !attType.getBinding().isAssignableFrom(attValue.getClass())) {
                //type mismatch, to try convert
                Object converted = Converters.convert(attValue, attType.getBinding());

                if (converted != null) {
                    attValue = converted;
                }
            }

            b.add(attValue);
        }

        //create the feature
        return b.buildFeature(fid);
    }
View Full Code Here

        tb.setName("featureType");
        tb.add("geometry", Point.class);
        tb.add("integer", Integer.class);

        GeometryFactory gf = new GeometryFactory();
        SimpleFeatureBuilder b = new SimpleFeatureBuilder(tb.buildFeatureType());

        DefaultFeatureCollection features = new DefaultFeatureCollection(null, b.getFeatureType());
        for (int i = 0; i < 2; i++) {
            b.add(gf.createPoint(new Coordinate(i, i)));
            b.add(i);
            features.add(b.buildFeature(i + ""));
        }

        Map<String, Object> input = new HashMap();
        input.put(BufferFeatureCollectionFactory.FEATURES.key, features);
        input.put(BufferFeatureCollectionFactory.BUFFER.key, 10d);
View Full Code Here

TOP

Related Classes of org.geotools.feature.simple.SimpleFeatureBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.