Package org.geotools.geojson.feature

Examples of org.geotools.geojson.feature.FeatureJSON$FeatureEncoder


    @Override
    public FeatureReader read(ImportData data, ImportTask item) throws IOException {
        final SimpleFeatureType featureType =
            (SimpleFeatureType) item.getMetadata().get(FeatureType.class);
        FeatureJSON json = new FeatureJSON();
        json.setFeatureType(featureType);
        final FeatureIterator it = json.streamFeatureCollection(file(data, item));

        return new FeatureReader() {

            @Override
            public FeatureType getFeatureType() {
View Full Code Here


        return false;
    }

    SimpleFeature sniff(File file) {
        try {
            FeatureIterator it = new FeatureJSON().streamFeatureCollection(file);
            try {
                if (it.hasNext()) {
                    return (SimpleFeature) it.next();
                }
            }
View Full Code Here

    ImportTask task(ImportData data, Catalog catalog) throws IOException {
        File file = maybeFile(data).get();

        // get the composite feature type
        SimpleFeatureType featureType = new FeatureJSON().readFeatureCollectionSchema(file, false);
        System.out.println(featureType);

        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
        tb.init(featureType);
        tb.setName(FilenameUtils.getBaseName(file.getName()));
        featureType = tb.buildFeatureType();

        // create the feature type
        FeatureTypeInfo ft = catalog.getFactory().createFeatureType();
        ft.setName(FilenameUtils.getBaseName(file.getName()));
        ft.setNativeName(ft.getName());

        // crs
        CoordinateReferenceSystem crs = null;
        if (featureType != null && featureType.getCoordinateReferenceSystem() != null) {
            crs = featureType.getCoordinateReferenceSystem();
        }
        try {
            crs = crs != null ? crs : CRS.decode("EPSG:4326");
        }
        catch (Exception e) {
            throw new IOException(e);
        }

        ft.setNativeCRS(crs);

        String srs = srs(crs);
        if (srs != null) {
            ft.setSRS(srs);
        }

        // bounds
        ReferencedEnvelope bounds = new ReferencedEnvelope(crs);

        FeatureJSON reader = new FeatureJSON();
        reader.setFeatureType(featureType);
        FeatureIterator<SimpleFeature> it = reader.streamFeatureCollection(file);
        while(it.hasNext()) {
            SimpleFeature f = it.next();
            bounds.include(f.getBounds());
        }
        ft.setNativeBoundingBox(bounds);
View Full Code Here

        // Final checks on the result
        Assert.assertNotNull(jsonZip);

        File[] files = exctractJSONFile(jsonZip);

        SimpleFeatureCollection rawTarget = (SimpleFeatureCollection) new FeatureJSON()
                .readFeatureCollection(new FileInputStream(files[0]));

        Assert.assertNotNull(rawTarget);

        Assert.assertEquals(rawSource.size(), rawTarget.size());
View Full Code Here

         "</wps:Execute>";
 
        MockHttpServletResponse r = postAsServletResponse("wps", xml);
        assertEquals("application/json", r.getContentType());
        // System.out.println(r.getOutputStreamContent());
        FeatureCollection fc = new FeatureJSON().readFeatureCollection(r.getOutputStreamContent());
        assertEquals(2, fc.size());
       
    }
View Full Code Here

         "</wps:Execute>";
 
        MockHttpServletResponse r = postAsServletResponse("wps", xml);
        assertEquals("application/json", r.getContentType());
        // System.out.println(r.getOutputStreamContent());
        FeatureCollection fc = new FeatureJSON().readFeatureCollection(r.getOutputStreamContent());
        assertEquals(2, fc.size());
       
    }
View Full Code Here

        }

        @Override
        protected void write(Object object, OutputStream out) throws IOException {
            SimpleFeatureCollection features = (SimpleFeatureCollection) object;
            final FeatureJSON json = new FeatureJSON();
            boolean geometryless = features.getSchema().getGeometryDescriptor() == null;
            json.setEncodeFeatureCollectionBounds(!geometryless);
            json.setEncodeFeatureCollectionCRS(!geometryless);
            json.writeFeatureCollection(features, out);
        }
View Full Code Here

    }

    @Override
    protected void write(Object object, OutputStream out) throws IOException {
        SimpleFeatureCollection features = (SimpleFeatureCollection) object;
        final FeatureJSON json = new FeatureJSON();
        boolean geometryless = features.getSchema().getGeometryDescriptor() == null;
        json.setEncodeFeatureCollectionBounds(!geometryless);
        json.setEncodeFeatureCollectionCRS(!geometryless);
        json.writeFeatureCollection(features, out);
    }
View Full Code Here

         "</wps:Execute>";
 
    MockHttpServletResponse r = postAsServletResponse("wps", xml);
    assertEquals("application/json", r.getContentType());
    // System.out.println(r.getOutputStreamContent());
    FeatureCollection fc = new FeatureJSON().readFeatureCollection(r.getOutputStreamContent());
    assertEquals(2, fc.size());
   
    }
View Full Code Here

TOP

Related Classes of org.geotools.geojson.feature.FeatureJSON$FeatureEncoder

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.