Example usage for org.json.simple JSONStreamAware JSONStreamAware

List of usage examples for org.json.simple JSONStreamAware JSONStreamAware

Introduction

In this page you can find the example usage for org.json.simple JSONStreamAware JSONStreamAware.

Prototype

JSONStreamAware

Source Link

Usage

From source file:at.localhost.vectorworldmap.util.FeatureJSON.java

/**
 * Writes a feature collection as GeoJSON.
 *
 * @param features The feature collection.
 * @param output The output. See {@link GeoJSONUtil#toWriter(Object)} for details.
 *//*from w w  w . j  a va 2s.c  o m*/
public void writeFeatureCollection(FeatureCollection features, Object output) throws IOException {
    LinkedHashMap obj = new LinkedHashMap();
    obj.put("type", "FeatureCollection");
    if (encodeFeatureCollectionBounds || encodeFeatureCollectionCRS) {
        final ReferencedEnvelope bounds = features.getBounds();

        if (encodeFeatureCollectionBounds) {
            obj.put("bbox", new JSONStreamAware() {
                public void writeJSONString(Writer out) throws IOException {
                    JSONArray.writeJSONString(Arrays.asList(bounds.getMinX(), bounds.getMinY(),
                            bounds.getMaxX(), bounds.getMaxY()), out);
                }
            });
        }

        if (encodeFeatureCollectionCRS) {
            obj.put("crs", createCRS(bounds.getCoordinateReferenceSystem()));
        }
    }
    if (encodeDistanceTolerance) {
        obj.put("tolerance", Double.toString(distanceTolerance));
    }
    obj.put("features", new FeatureCollectionEncoder(features, gjson));
    GeoJSONUtil.encode(obj, output);
}