/// <summary> /// Requests the closest APSOIL, using the ASRIS web service /// Currently obtains the closest 5, and presents these to the user /// </summary> /// <returns>True if successful</returns> private bool GetMatchingSoil() { if (!CheckValue(entryLatitude) || !CheckValue(entryLatitude)) { return(false); } string url = "http://www.asris.csiro.au/ASRISApi/api/APSIM/getClosestApsoil?maxCnt=5&longitude=" + entryLongitude.Text + "&latitude=" + entryLatitude.Text; Soil newSoil = null; WaitCursor = true; try { try { MemoryStream stream = WebUtilities.ExtractDataFromURL(url); stream.Position = 0; XmlDocument doc = new XmlDocument(); doc.Load(stream); List <XmlNode> soilNodes = XmlUtilities.ChildNodesRecursively(doc, "soil"); // We should have 0 to 5 nodes. If multiple nodes, we should let the user choose if (soilNodes.Count > 0) { int selNode = 0; if (soilNodes.Count > 1) { selNode = SelectSoil(soilNodes); } if (selNode >= 0) { newSoil = SoilFromApsoil(soilNodes[selNode]); } else { return(false); } } if (newSoil != null) { ReplaceModelCommand command = new ReplaceModelCommand(soil, newSoil, explorerPresenter); explorerPresenter.CommandHistory.Add(command, true); } return(true); } catch (Exception e) { return(false); } } finally { WaitCursor = false; } }
/// <summary> /// Gets a soil description from the ISRIC REST API for World Modellers /// </summary> /// <returns>True if successful</returns> private bool GetISRICSoil() { if (!CheckValue(entryLatitude) || !CheckValue(entryLatitude)) { return(false); } string url = "https://worldmodel.csiro.au/apsimsoil?lon=" + entryLongitude.Text + "&lat=" + entryLatitude.Text; Soil newSoil = null; WaitCursor = true; try { try { MemoryStream stream = WebUtilities.ExtractDataFromURL(url); stream.Position = 0; XmlDocument doc = new XmlDocument(); doc.Load(stream); List <XmlNode> soilNodes = XmlUtilities.ChildNodesRecursively(doc, "Soil"); // We will have either 0 or 1 soil nodes if (soilNodes.Count > 0) { newSoil = SoilFromApsoil(soilNodes[0]); // Something looks very wrong with organic carbon in these soils. // It looks to me like it's off by a factor of 10. SoilOrganicMatter soilOrganic = Apsim.Child(newSoil, typeof(SoilOrganicMatter)) as SoilOrganicMatter; soilOrganic.OC = MathUtilities.Divide_Value(soilOrganic.OC, 10.0); ReplaceModelCommand command = new ReplaceModelCommand(soil, newSoil, explorerPresenter); explorerPresenter.CommandHistory.Add(command, true); } MessageDialog md = new MessageDialog(owningView.MainWidget.Toplevel as Window, DialogFlags.Modal, MessageType.Warning, ButtonsType.Ok, "Initial values for water and soil nitrogen have not been provided with this soil description. " + "Please add sensible values before using this soil in a simulation."); md.Title = "Soil use warning"; md.Run(); md.Destroy(); return(true); } catch (Exception) { return(false); } } finally { WaitCursor = false; } }
/// <summary> /// Requests a "synthethic" ASPIM soil from the ASRIS web service /// </summary> /// <returns>True if successful</returns> private bool GetSyntheticSoil() { if (!CheckValue(entryLatitude) || !CheckValue(entryLatitude)) { return(false); } string url = "http://www.asris.csiro.au/ASRISApi/api/APSIM/getApsoil?longitude=" + entryLongitude.Text + "&latitude=" + entryLatitude.Text; Soil newSoil = null; WaitCursor = true; try { try { MemoryStream stream = WebUtilities.ExtractDataFromURL(url); stream.Position = 0; XmlDocument doc = new XmlDocument(); doc.Load(stream); List <XmlNode> soilNodes = XmlUtilities.ChildNodesRecursively(doc, "soil"); // We will have either 0 or 1 soil nodes if (soilNodes.Count > 0) { newSoil = SoilFromApsoil(soilNodes[0]); ReplaceModelCommand command = new ReplaceModelCommand(soil, newSoil, explorerPresenter); explorerPresenter.CommandHistory.Add(command, true); } return(true); } catch (Exception e) { return(false); } } finally { WaitCursor = false; } }