Package org.geotools.geojson.feature

Examples of org.geotools.geojson.feature.FeatureJSON


    }

    private SimpleFeatureCollection readFeatureCollection(final String geojsonData) throws IOException {
        String convertedGeojsonObject = convertToGeoJsonCollection(geojsonData);

        FeatureJSON geoJsonReader = new FeatureJSON();
        final SimpleFeatureType featureType = createFeatureType(convertedGeojsonObject);
        if (featureType != null) {
            geoJsonReader.setFeatureType(featureType);
        }
        ByteArrayInputStream input = new ByteArrayInputStream(convertedGeojsonObject.getBytes(Constants.DEFAULT_CHARSET));

        return (SimpleFeatureCollection) geoJsonReader.readFeatureCollection(input);
    }
View Full Code Here


    protected DataStore getDataStore(String geoJSON) throws FileNotFoundException, IOException {
        try {
            File geoJsonfile = new File(geoJSON);
            checkParameter(geoJsonfile.exists(), "File does not exist '%s'", geoJsonfile);
            InputStream in = new FileInputStream(geoJsonfile);
            FeatureJSON fjson = new FeatureJSON();
            @SuppressWarnings("rawtypes")
            FeatureCollection fc = fjson.readFeatureCollection(in);
            @SuppressWarnings("unchecked")
            DataStore dataStore = new MemoryDataStore(fc);
            return dataStore;
        } catch (IOException ioe) {
            throw new CommandFailedException("Error opening GeoJSON: " + ioe.getMessage(), ioe);
View Full Code Here

            op.exportDefaultFeatureType();
        }
        FileWriter writer = null;
        try {
            op.setProgressListener(cli.getProgressListener()).call();
            FeatureJSON fjson = new FeatureJSON();
            @SuppressWarnings("rawtypes")
            FeatureCollection fc = featureSource.getFeatures();
            writer = new FileWriter(file);
            fjson.writeFeatureCollection(fc, writer);
        } catch (IllegalArgumentException iae) {
            throw new org.locationtech.geogig.cli.InvalidParameterException(iae.getMessage(), iae);
        } catch (GeoToolsOpException e) {
            file.delete();
            switch (e.statusCode) {
View Full Code Here

        List<IsochroneData> isochrones = getIsochronesAccumulative(surf, spacing);
        final FeatureCollection fc = LIsochrone.makeContourFeatures(isochrones);
        return Response.ok().entity(new StreamingOutput() {
            @Override
            public void write(OutputStream output) throws IOException {
                FeatureJSON fj = new FeatureJSON();
                fj.writeFeatureCollection(fc, output);
            }
        }).build();
    }
View Full Code Here

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response getGeoJsonIsochrone() throws Exception {
        SimpleFeatureCollection contourFeatures = makeContourFeatures(computeIsochrone());
        StringWriter writer = new StringWriter();
        FeatureJSON fj = new FeatureJSON();
        fj.writeFeatureCollection(contourFeatures, writer);
        CacheControl cc = new CacheControl();
        cc.setMaxAge(3600);
        cc.setNoCache(false);
        return Response.ok().entity(writer.toString()).cacheControl(cc).build();
    }
View Full Code Here

    public Response geoJsonGet() throws Exception {
        /* QGIS seems to want multi-features rather than multi-geometries. */
        SimpleFeatureCollection contourFeatures = makeContourFeatures();
        /* Output the staged features to JSON */
        StringWriter writer = new StringWriter();
        FeatureJSON fj = new FeatureJSON();
        fj.writeFeatureCollection(contourFeatures, writer);
        return Response.ok().entity(writer.toString()).build();
    }
View Full Code Here

        //bencharkGeometryEncode(data);
    }
   
    static void benchmarkFeatureCollectionParse(File source) throws Exception {
        BufferedReader reader = new BufferedReader(new FileReader(source));
        FeatureJSON fjson = new FeatureJSON();
        FeatureIterator<SimpleFeature> it = fjson.streamFeatureCollection(reader);
        int count = 0;
       
        long t1 = System.currentTimeMillis();
        while(it.hasNext()) {
//            SimpleFeature f = it.next();
View Full Code Here

        // currently require some data to exist due to construction of featuretype from existing feature...
        db.postBulk(loadJSON("morocco.json", "countries"));
       
        JSONArray data = loadJSON("italy.json", "countries");
        JSONObject italy = (JSONObject) data.get(0);
        FeatureJSON json = new FeatureJSON();
        json.setFeatureType(CouchDBUtils.createFeatureType(italy, "countries"));
        Feature feature = json.readFeature(italy.toString());
       
        ContentFeatureStore featureStore = (ContentFeatureStore) store.getFeatureSource("gttestdb.countries");
        featureStore.addFeatures(Collections.singleton(feature));
       
        // single add case
View Full Code Here

       
        SimpleFeatureBuilder fb = new SimpleFeatureBuilder(schema);
        fb.add(new WKTReader().read("POINT(10 20)"));
        SimpleFeature feature = fb.buildFeature("outbreak.1");
       
        FeatureJSON fj = new FeatureJSON();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        fj.writeFeature(feature, os);
       
        String json = os.toString();
       
        // here it would break because the written json was incorrect
        SimpleFeature feature2 = fj.readFeature(json);
        assertEquals(feature.getID(), feature2.getID());
    }
View Full Code Here

        SimpleFeatureBuilder fb = new SimpleFeatureBuilder(schema);
        fb.add(new WKTReader().read("POINT(20037508.34 20037508.34)"));
        fc.add(fb.buildFeature("xyz.1"));

        FeatureJSON fj = new FeatureJSON();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        fj.writeFeatureCollection(fc, os);

        assertEquals(strip(json), os.toString());
    }
View Full Code Here

TOP

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

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.