GISModelDataService.java [src/java/m/gis] Revision:   Date:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package m.gis;

import m.utils.IGISDatabase;
import m.utils.GeoJSONParser;
import m.utils.GeoJSON;
import m.utils.DatabaseBuilder;
import csip.ModelDataService;
import csip.ServiceException;
import org.codehaus.jettison.json.JSONArray;

/**
 *
 * @author ktraff
 */
public class GISModelDataService extends ModelDataService{
    
    protected JSONArray result;
    protected GeoJSON layers;
    protected int outputSRID;
    
    protected IGISDatabase db;
    
    @Override
    protected void preProcess() throws Exception {
        db = (IGISDatabase) new DatabaseBuilder()
                .setAll(DatabaseBuilder.DB.POSTGRES_GIS)
                .create();
        result = new JSONArray();
        JSONArray geojson = getJSONArrayParam("layer");
        layers = new GeoJSON(geojson, db);
        
        try {
            outputSRID = getIntParam("outputSRID");
        } catch (ServiceException ex) {
            outputSRID = GeoJSONParser.getSRIDInt(db.getDefaultCRS());
        }
    }
    
    @Override
    protected void postProcess() throws Exception {
        putResult("layer", result);
    }
    
}