Package org.geotools.geojson.geom

Examples of org.geotools.geojson.geom.GeometryJSON


    Assert.assertTrue(json instanceof JSONObject);
    JSONObject jsonObject = (JSONObject) json;
    JSONArray features = (JSONArray) jsonObject.get("features");
    JSONObject feature = (JSONObject) features.get(0);
    JSONObject geometry = (JSONObject) feature.get("geometry");
    GeometryJSON g = new GeometryJSON(0);
    Geometry m = g.read(geometry.toJSONString());
    Envelope envelope = new Envelope(0, 1, 0, 1);
    Geometry orig = JTS.toGeometry(envelope);
    Geometry m2 = geoservice.transform(orig, "EPSG:4326", "EPSG:900913");
    // equality check on buffer, JTS equals does not do the trick !
    Assert.assertTrue(m.buffer(0.01).contains(m2));
View Full Code Here


        Assert.isTrue(this.style == null || this.display == AoiDisplay.RENDER,
                "'style' does not make sense unless 'display' == RENDER.  In this case 'display' == " + this.display);
    }

    private void parseGeometry() {
        GeometryJSON json = new GeometryJSON();
        byte[] bytes;
        try {
            bytes = this.area.getBytes(Constants.DEFAULT_ENCODING);
            final InputStream input = new ByteArrayInputStream(bytes);
            this.polygon = (Polygon) json.read(input);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
View Full Code Here

            allConnectingEdges.clear();
            for (Edge tedge : connectingEdgesMap.values())
                allConnectingEdges.add(tedge);
        }
        StringWriter sw = new StringWriter();
        GeometryJSON geometryJSON = new GeometryJSON();
        //
        // -- create the different outputs ---
        //
        try {
            if (output.equals(SIsochrone.RESULT_TYPE_POINTS)) {
                // in case there was no road we create a circle and
                // and return those points
                if (noRoadNearBy) {
                    Geometry circleShape = createCirle(dropPoint, pathToStreet);
                    coords = circleShape.getCoordinates();
                }
                // -- the states/nodes with time elapsed <= X min.
                LOG.debug("write multipoint geom with {} points", coords.length);
                geometryJSON.write(gf.createMultiPoint(coords), sw);
                LOG.debug("done");
            } else if (output.equals(SIsochrone.RESULT_TYPE_SHED)) {

                Geometry geomsArray[] = null;
                // in case there was no road we create a circle
                if (noRoadNearBy) {
                    Geometry circleShape = createCirle(dropPoint, pathToStreet);
                    geometryJSON.write(circleShape, sw);
                } else {
                    if (maxTime > shedCalcMethodSwitchTimeInSec) { // eg., walkshed > 20 min
                        // -- create a point-based walkshed
                        // less exact and should be used for large walksheds with many edges
                        LOG.debug("create point-based shed (not from edges)");
                        geomsArray = new Geometry[coords.length];
                        for (int j = 0; j < geomsArray.length; j++) {
                            geomsArray[j] = gf.createPoint(coords[j]);
                        }
                    } else {
                        // -- create an edge-based walkshed
                        // it is more exact and should be used for short walks
                        LOG.debug("create edge-based shed (not from points)");
                        Map<ReversibleLineStringWrapper, LineString> walkShedEdges = Maps
                                .newHashMap();
                        // add the walk from the pushpin to closest street point
                        walkShedEdges.put(new ReversibleLineStringWrapper(pathToStreet),
                                pathToStreet);
                        // get the edges and edge parts within time limits
                        ArrayList<LineString> withinTimeEdges = this
                                .getLinesAndSubEdgesWithinMaxTime(maxTime, allConnectingEdges,
                                        sptA, angleLimitForUShapeDetection,
                                        distanceToleranceForUShapeDetection, maxUserSpeed, usesCar,
                                        doSpeedTest);
                        for (LineString ls : withinTimeEdges) {
                            walkShedEdges.put(new ReversibleLineStringWrapper(ls), ls);
                        }
                        geomsArray = new Geometry[walkShedEdges.size()];
                        int k = 0;
                        for (LineString ls : walkShedEdges.values())
                            geomsArray[k++] = ls;
                    } // end if-else: maxTime condition
                    GeometryCollection gc = gf.createGeometryCollection(geomsArray);
                    // create the concave hull, but in case it fails we just return the convex hull
                    Geometry outputHull = null;
                    LOG.debug(
                            "create concave hull from {} geoms with edge length limit of about {} m (distance on meridian)",
                            geomsArray.length, concaveHullAlpha * 111132);
                    // 1deg at Latitude phi = 45deg is about 111.132km
                    // (see wikipedia: http://en.wikipedia.org/wiki/Latitude#The_length_of_a_degree_of_latitude)
                    try {
                        ConcaveHull hull = new ConcaveHull(gc, concaveHullAlpha);
                        outputHull = hull.getConcaveHull();
                    } catch (Exception e) {
                        outputHull = gc.convexHull();
                        LOG.debug("Could not generate ConcaveHull for WalkShed, using ConvexHull instead.");
                    }
                    LOG.debug("write shed geom");
                    geometryJSON.write(outputHull, sw);
                    LOG.debug("done");
                }
            } else if (output.equals(SIsochrone.RESULT_TYPE_EDGES)) {
                // in case there was no road we return only the suggested path to the street
                if (noRoadNearBy) {
                    geometryJSON.write(pathToStreet, sw);
                } else {
                    // -- if we would use only the edges from the paths to the origin we will miss
                    // some edges that will be never on the shortest path (e.g. loops/crescents).
                    // However, we can retrieve all edges by checking the times for each
                    // edge end-point
                    Map<ReversibleLineStringWrapper, LineString> walkShedEdges = Maps.newHashMap();
                    // add the walk from the pushpin to closest street point
                    walkShedEdges.put(new ReversibleLineStringWrapper(pathToStreet), pathToStreet);
                    // get the edges and edge parts within time limits
                    ArrayList<LineString> withinTimeEdges = this
                            .getLinesAndSubEdgesWithinMaxTime(maxTime, allConnectingEdges, sptA,
                                    angleLimitForUShapeDetection,
                                    distanceToleranceForUShapeDetection, maxUserSpeed, usesCar,
                                    doSpeedTest);
                    for (LineString ls : withinTimeEdges) {
                        walkShedEdges.put(new ReversibleLineStringWrapper(ls), ls);
                    }
                    Geometry mls = null;
                    LineString edges[] = new LineString[walkShedEdges.size()];
                    int k = 0;
                    for (LineString ls : walkShedEdges.values())
                        edges[k++] = ls;
                    LOG.debug("create multilinestring from {} geoms", edges.length);
                    mls = gf.createMultiLineString(edges);
                    LOG.debug("write geom");
                    geometryJSON.write(mls, sw);
                    LOG.debug("done");
                }
            } else if (output.equals("DEBUGEDGES")) {
                // -- for debugging, i.e. display of detected u-shapes/crescents
                ArrayList<LineString> withinTimeEdges = this.getLinesAndSubEdgesWithinMaxTime(
                        maxTime, allConnectingEdges, sptA, angleLimitForUShapeDetection,
                        distanceToleranceForUShapeDetection, maxUserSpeed, usesCar, doSpeedTest);
                if (this.showTooFastEdgesAsDebugGeomsANDnotUShapes) {
                    LOG.debug("displaying edges that are traversed too fast");
                    this.debugGeoms = this.tooFastTraversedEdgeGeoms;
                } else {
                    LOG.debug("displaying detected u-shaped roads/crescents");
                }
                LineString edges[] = new LineString[this.debugGeoms.size()];
                int k = 0;
                for (Iterator iterator = debugGeoms.iterator(); iterator.hasNext();) {
                    LineString ls = (LineString) iterator.next();
                    edges[k] = ls;
                    k++;
                }
                Geometry mls = gf.createMultiLineString(edges);
                LOG.debug("write debug geom");
                geometryJSON.write(mls, sw);
                LOG.debug("done");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
View Full Code Here

    @Override
    public void serialize(Geometry value, JsonGenerator jgen, SerializerProvider provider)
            throws IOException, JsonProcessingException {
       
        GeometryJSON json = new GeometryJSON();
       
        jgen.writeRawValue(json.toString(value));
    }
View Full Code Here

public class GeoJSONDeserializer extends JsonDeserializer<Geometry> {

    @Override
    public Geometry deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
            JsonProcessingException {
        GeometryJSON json = new GeometryJSON();
        String text = jp.getText();
        ByteArrayInputStream stream = new ByteArrayInputStream(text.getBytes());
        return json.read(stream);
    }
View Full Code Here

    boolean encodeFeatureCRS = false;
    boolean encodeFeatureCollectionCRS = false;
    boolean encodeNullValues = false;
   
    public FeatureJSON() {
        this(new GeometryJSON());
    }
View Full Code Here

        it.close();
        reader.close();
    }
   
    static void bencharkGeometryEncode(FeatureSource data) throws Exception {
        GeometryJSON gjson = new GeometryJSON();
        OutputStream out = System.out;/*new NullOutputStream();*/
        Writer writer = new OutputStreamWriter(out);
       
        FeatureCollection features = data.getFeatures();
        FeatureIterator it = features.features();

        long t1 = System.currentTimeMillis();
        while(it.hasNext()) {
            SimpleFeature f = (SimpleFeature) it.next();
            gjson.write((Geometry) f.getDefaultGeometry(), writer);
        }
       
        writer.flush();
       
        long t2 = System.currentTimeMillis();
View Full Code Here

    private int wrote = 0;

    CouchDBAddFeatureWriter(SimpleFeatureType buildFeatureType, CouchDBDataStore dataStore) {
        this.featureType = buildFeatureType;
        this.dataStore = dataStore;
        this.json = new GeometryJSON();
        // @todo non scalable in memory buffer
        this.buffer = new StringWriter();
        featureFactory = dataStore.getFeatureFactory() == null
                ? new LenientFeatureFactoryImpl() : dataStore.getFeatureFactory();
View Full Code Here

    }

    private void writeGeometry(Geometry geom) {
        if (!properties.containsKey("geometry")) {
            String strGeoJSON = "";
            GeometryJSON gjson = new GeometryJSON();
            try {
                StringWriter sw = new StringWriter();
                gjson.write(geom, sw);
                strGeoJSON = sw.toString();
            } catch (IOException ex) {
                LOGGER.log(Level.SEVERE, " Exception at visit  : Intersect Filter " + ex.getMessage(), ex);
            }
            properties.put("geometry", strGeoJSON);
View Full Code Here

        String geometry = form.getFirstValue("geometry");
        if (geometry == null) {
            return Filter.INCLUDE;
        } else {
            try {
                Geometry geom = new GeometryJSON().read(geometry);
                final double tolerance = getTolerance(form);
                return geometryFilter(schema, geom, tolerance);
            } catch (IOException e) {
                throw new RestletException("Could not parse the geometry geojson: "
                        + e.getMessage(), Status.CLIENT_ERROR_BAD_REQUEST);
View Full Code Here

TOP

Related Classes of org.geotools.geojson.geom.GeometryJSON

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.