public async Task <IActionResult> Network([FromQuery] double lat, [FromQuery] double lon, [FromQuery] double distance, [FromQuery] bool includeStats = false, [FromQuery] bool geojson = false, [FromQuery] int?page = null, [FromQuery] int pageCount = 50) { try { var nldi_sa = new NLDIServiceAgent(this.NLDIsettings, this.Navigationsettings); var isOk = await nldi_sa.ReadNLDIAsync(lat, lon, distance); if (!isOk) { throw new Exception("Failed to retrieve NLDI data"); } JObject nldi_stations = (JObject)nldi_sa.getStations(); var stationCodes = new List <string>(); if (nldi_stations["features"] != null) { var count = nldi_stations["features"].Count(); if (count == 0) { sm("No stations located within search distance.", MessageType.warning); } foreach (var feat in nldi_stations["features"].Children()) { var id = (string)feat["properties"]["identifier"]; string splitID = id.Split(new string[] { "-" }, StringSplitOptions.None)[1]; stationCodes.Add(splitID); } if (count > 0) { var stations = agent.GetStations(null, null, null, null, null, null, includeStats, null, stationCodes); // need to pull in geojson changes and use that if (geojson) { return(Ok(GeojsonFormatter.ToGeojson(stations))); } // get number of items to skip for pagination // checking for page number to be sent for this so it doesn't cause issues in StreamStats for now if (page != null) { var skip = (Convert.ToInt32(page) - 1) * pageCount; sm("Returning page " + page + " of " + (stations.Count() / pageCount + 1) + "."); sm("Total Count: " + stations.Count()); stations = stations.Skip(skip).Take(pageCount); } return(Ok(stations)); } } sm("No stations located within search distance.", MessageType.warning); return(Ok(nldi_stations)); } catch (Exception ex) { return(await HandleExceptionAsync(ex)); } }
public NavigationAgent(IOptions <NetworkSettings> NetworkSettings, IHttpContextAccessor httpContextAccessor) { this._messages = httpContextAccessor.HttpContext.Items; nldiAgent = new NLDIServiceAgent(NetworkSettings.Value.NLDI); nldiAgent2 = new NLDIServiceAgent(new Resource() { baseurl = "https://cida-test.er.usgs.gov", resources = NetworkSettings.Value.NLDI.resources }); ssAgent = new StreamStatsServiceAgent(NetworkSettings.Value.StreamStats); NavDBConnectionstring = NetworkSettings.Value.DBConnectionString; //deep clone to ensure objects stay stateless availableNetworks = JsonConvert.DeserializeObject <List <Network> >(JsonConvert.SerializeObject(NetworkSettings.Value.Networks)); }
public async Task <IActionResult> Get([FromQuery] Int32?featureid, [FromQuery] double?x, [FromQuery] double?y) { //returns list of available Navigations try { List <Dictionary <string, object> > results = null; if (!featureid.HasValue && (!x.HasValue && !y.HasValue)) { return(new BadRequestObjectResult("An featureid or location (x,y) must be specified.")); } if (x.HasValue && y.HasValue) { var agent = new NLDIServiceAgent(settings.NLDI); featureid = Convert.ToInt32(agent.GetLocalCatchmentAsync(new Point(new Position(y.Value, x.Value)) { CRS = new NamedCRS("EPSG:4326") }).Features.FirstOrDefault().Properties["featureid"]); } using (var NavDBOps = new NavigationDBOps(settings.DBConnectionString)) { results = NavDBOps.GetAvailableProperties(new List <int>() { featureid.Value }).ToList(); }//end using return(Ok(results)); } catch (Exception ex) { return(HandleException(ex)); } }