NHDFlowline.java [src/java/svap/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 svap.utils;

import csip.Config;
import csip.ServiceException;
import java.io.IOException;
import java.net.URISyntaxException;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

/**
 *
 * @author Rumpal Sidhu
 *
 * Look for "Flowline - Small Scale" services at USGS website, when they change
 * the endpoint addresses. No need to really change the default here in the
 * code...just change the config file for the SVAP services
 */
public class NHDFlowline extends USGS {

  private static final String USGS_NHD_URL = "//hydro.nationalmap.gov/arcgis/rest/services/nhd/MapServer/5/query";


  public NHDFlowline() {
    outFields = "FCODE, LENGTHKM";
    format = "geojson";
    this.geometryType = "esriGeometryPolygon";
  }


  public JSONObject getNHDFlowlineData(String geometry) throws URISyntaxException, IOException, ServiceException, JSONException {
    this.geometry = geometry;
    JSONObject hucResponse = callService(Config.getString("service.usgs.nhd.url", USGS_NHD_URL));
    String fixResult = hucResponse.toString();
    fixResult = fixResult.replaceAll(",0,null]", "]");
    try {
      hucResponse = new JSONObject(fixResult);
    } catch (JSONException ex) {
      throw new ServiceException("The USGS NHD Flowline service did not return valid data.");
    }
    return hucResponse;
  }

}