diff --git a/spatial-data-science/src/platformshell/src/main.rs b/spatial-data-science/src/platformshell/src/main.rs index 2550bcb..5617df3 100644 --- a/spatial-data-science/src/platformshell/src/main.rs +++ b/spatial-data-science/src/platformshell/src/main.rs @@ -82,7 +82,20 @@ fn main() -> Result<(), Box> { false }; - match utils::query_heat_risk_index(urban_hri_url, "1=1", location, hri_filter_fn) { + /* + match utils::query_heat_risk_index(urban_hri_url, "1=1", Some(location), hri_filter_fn) { + Ok(hri_featureset) => { + let json = serde_json::to_string_pretty(&hri_featureset)?; + println!("{}", json); + } + Err(e) => { + eprintln!("Error querying heat risk index: {}", e); + return Err(Box::new(LocationServicesError { code:9999, message:"Error querying heat risk index!".to_string() })); + } + } + */ + + match utils::query_heat_risk_index(urban_hri_url, "1=1", None, hri_filter_fn) { Ok(hri_featureset) => { let json = serde_json::to_string_pretty(&hri_featureset)?; println!("{}", json); diff --git a/spatial-data-science/src/platformshell/src/utils.rs b/spatial-data-science/src/platformshell/src/utils.rs index 3280512..349c6ce 100644 --- a/spatial-data-science/src/platformshell/src/utils.rs +++ b/spatial-data-science/src/platformshell/src/utils.rs @@ -7,24 +7,37 @@ use std::io::Read; -pub fn query_heat_risk_index(urban_hri_url: String, where_clause: &str, location: Point, filter_fn: F) -> Result, Box> where F: Fn(&Feature<2>) -> bool, { - let location_str = format!("{}, {}", location.x(), location.y()); - let location_wkid_str = "4326"; - +pub fn query_heat_risk_index(urban_hri_url: String, where_clause: &str, location: Option, filter_fn: F) -> Result, Box> where F: Fn(&Feature<2>) -> bool, { // Query the feature service + let query_url; let out_fields = "HRI, TEMP"; - let query_url = Url::parse_with_params( - &(urban_hri_url + "/query"), - &[ - ("where", where_clause), - ("geometryType", "esriGeometryPoint"), - ("geometry", &location_str), - ("inSR", &location_wkid_str), - ("outFields", &out_fields), - ("returnGeometry", "true"), - ("f", "json"), - ], - )?; + if let Some(spatial_filter_location) = location { + let location_str = format!("{}, {}", spatial_filter_location.x(), spatial_filter_location.y()); + let location_wkid_str = "4326"; + + query_url = Url::parse_with_params( + &(urban_hri_url + "/query"), + &[ + ("where", where_clause), + ("geometryType", "esriGeometryPoint"), + ("geometry", &location_str), + ("inSR", &location_wkid_str), + ("outFields", &out_fields), + ("returnGeometry", "true"), + ("f", "json"), + ], + )?; + } else { + query_url = Url::parse_with_params( + &(urban_hri_url + "/query"), + &[ + ("where", where_clause), + ("outFields", &out_fields), + ("returnGeometry", "true"), + ("f", "json"), + ], + )?; + } let mut response = reqwest::blocking::get(query_url)?; let mut body = String::new();