COMETools.java [src/java/m/comet/utils] Revision: default  Date:
/*
 * $Id$
 *
 * This file is part of the Cloud Services Integration Platform (CSIP),
 * a Model-as-a-Service framework, API, and application suite.
 *
 * 2012-2017, OMSLab, Colorado State University.
 *
 * OMSLab licenses this file to you under the MIT license.
 * See the LICENSE file in the project root for more information.
 */
package m.comet.utils;

import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

/**
 *
 * @author rumpal
 */
public class COMETools {

    public static JSONObject createFeatureCollection(double latitude, double longitude) throws JSONException {
        //Adding Geometry Type
        JSONObject geometry = new JSONObject();
        geometry.put("type", "Point");

        //Creating coordinates JSONArray
        JSONArray coordinates = new JSONArray();
        coordinates.put(longitude);
        coordinates.put(latitude);

        //Adding coordinates to the geometry
        geometry.put("coordinates", coordinates);

        //Creating properties array and adding properties
        JSONObject properties = new JSONObject();
        properties.put("name", "pt one");
        properties.put("gid", 1);

        //Adding properties and geometry to the feature
        JSONObject feature = new JSONObject();
        feature.put("type", "Feature");
        feature.put("properties", properties);
        feature.put("geometry", geometry);
        JSONArray features = new JSONArray();
        features.put(feature);

        //Adding feature to featureCollection
        JSONObject featureCollection = new JSONObject();
        featureCollection.put("type", "FeatureCollection");
        featureCollection.put("features", features);

        return featureCollection;

    }

}