Skip to content

Commit

Permalink
#3 Filter features using HRI
Browse files Browse the repository at this point in the history
- need to be field type specific
  • Loading branch information
esride-jts committed Sep 24, 2024
1 parent ec5a297 commit 1fcf6d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 17 additions & 5 deletions spatial-data-science/src/platformshell/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,34 @@ mod tests {


fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a Point with latitude and longitude
let location = Point::new(7.116004, 50.719847);
// Create a Point with latitude and longitude
let location = Point::new(7.116108, 50.719725);

// Query the feature service
let urban_hri_url = env::var("URBAN_HEAT_RISK_INDEX_FEATURE_SERVICE_URL")?;

// Define the filtering logic
let filter_fn = |feature: &Feature<2>| {
// Define the filtering logic using polygon geometry
let polygon_filter_fn = |feature: &Feature<2>| {
if let Some(geometry) = &feature.geometry {
geometry.clone().as_polygon().is_some()
} else {
false
}
};

// Define the filtering logic using high HRI value
let hri_filter_fn = |feature: &Feature<2>| {
if let Some(attributes) = &feature.attributes {
if let Some(hri_value) = attributes.get("HRI") {
if let Some(hri_value) = hri_value.as_f64() {
return hri_value > 7.0;
}
}
}
false
};

match utils::query_heat_risk_index(urban_hri_url, location, filter_fn) {
match utils::query_heat_risk_index(urban_hri_url, "1=1", location, hri_filter_fn) {
Ok(hri_featureset) => {
let json = serde_json::to_string_pretty(&hri_featureset)?;
println!("{}", json);
Expand Down
4 changes: 2 additions & 2 deletions spatial-data-science/src/platformshell/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::io::Read;



pub fn query_heat_risk_index<F>(urban_hri_url: String, location: Point, filter_fn: F) -> Result<FeatureSet<2>, Box<dyn std::error::Error>> where F: Fn(&Feature<2>) -> bool, {
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";

Expand All @@ -16,7 +16,7 @@ pub fn query_heat_risk_index<F>(urban_hri_url: String, location: Point, filter_f
let query_url = Url::parse_with_params(
&(urban_hri_url + "/query"),
&[
("where", "1=1"),
("where", where_clause),
("geometryType", "esriGeometryPoint"),
("geometry", &location_str),
("inSR", &location_wkid_str),
Expand Down

0 comments on commit 1fcf6d8

Please sign in to comment.