Skip to content

Commit

Permalink
#3 Optional spatial filter
Browse files Browse the repository at this point in the history
  • Loading branch information
esride-jts committed Sep 26, 2024
1 parent 298dacd commit 4898629
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 17 deletions.
15 changes: 14 additions & 1 deletion spatial-data-science/src/platformshell/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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);
Expand Down
45 changes: 29 additions & 16 deletions spatial-data-science/src/platformshell/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,37 @@ use std::io::Read;



pub fn query_heat_risk_index<F>(urban_hri_url: String, where_clause: &str, location: Point, filter_fn: F) -> Result<FeatureSet<2>, Box<dyn std::error::Error>> 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<F>(urban_hri_url: String, where_clause: &str, location: Option<Point>, filter_fn: F) -> Result<FeatureSet<2>, Box<dyn std::error::Error>> 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();

Expand Down

0 comments on commit 4898629

Please sign in to comment.