Hi, I'm making a QML application where I want to see if the features of one feature layer (which are points) are within the bounds of another feature layer which is of geometryType esriGeometryPolygon (https://livefeeds.arcgis.com/arcgis/rest/services/LiveFeeds/Wildfire_Activity/MapServer/2 this is the actual layer if it helps). Currently I'm getting data on wildfires by doing a queryFeaturesWithFieldOptions on the Active Fire Report layer to gain info on wildfires in my current extent, but I want to see the points of the other feature which are within the polygon of the perimeter. Within my QueryParameters I see options for spatialRelationship, outSpatialReference, and geometry so I definitely think what I'm trying to do is possible, but from my testing I haven't gotten the results I want yet. Any help would be appreciated, and I can answer any questions if needed.
Solved! Go to Solution.
Sounds like you're on the right track. Here is an example of using a polygon to find points that are within it. Just click on a state and you can see what cities are within that state:
import QtQuick 2.6
import QtQuick.Controls 1.4
import Esri.ArcGISRuntime 100.3
ApplicationWindow {
id: appWindow
width: 800
height: 600
title: "SpatialQuery"
// add a mapView component
MapView {
anchors.fill: parent
// set focus to enable keyboard navigation
focus: true
// add a map to the mapview
Map {
// add the BasemapTopographic basemap to the map
BasemapTopographic {}
FeatureLayer {
id: statesLayer
ServiceFeatureTable {
id: statesTable
url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/2"
}
}
FeatureLayer {
id: citiesLayer
ServiceFeatureTable {
id: citiesTable
url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"
onQueryFeaturesStatusChanged: {
if (queryFeaturesStatus !== Enums.TaskStatusCompleted)
return;
var resultIter = queryFeaturesResult.iterator;
while (resultIter.hasNext) {
var feat = resultIter.next();
citiesLayer.selectFeature(feat)
console.log("City:", feat.attributes.attributeValue("areaname"));
}
}
}
}
}
onMouseClicked: {
// clear selection and identify layers
statesLayer.clearSelection();
citiesLayer.clearSelection();
identifyLayerWithMaxResults(statesLayer, mouse.x, mouse.y, 10, false, 1)
}
onIdentifyLayerStatusChanged: {
if (identifyLayerStatus !== Enums.TaskStatusCompleted)
return;
// select the state layer that was identified
var result = identifyLayerResult.geoElements[0];
statesLayer.selectFeature(result);
// find all the cities in that polygon
// create the params
var queryParams = ArcGISRuntimeEnvironment.createObject("QueryParameters");
queryParams.geometry = result.geometry;
queryParams.spatialRelationship = Enums.SpatialRelationshipIntersects;
// query the table
citiesTable.queryFeatures(queryParams)
}
}
}
Sounds like you're on the right track. Here is an example of using a polygon to find points that are within it. Just click on a state and you can see what cities are within that state:
import QtQuick 2.6
import QtQuick.Controls 1.4
import Esri.ArcGISRuntime 100.3
ApplicationWindow {
id: appWindow
width: 800
height: 600
title: "SpatialQuery"
// add a mapView component
MapView {
anchors.fill: parent
// set focus to enable keyboard navigation
focus: true
// add a map to the mapview
Map {
// add the BasemapTopographic basemap to the map
BasemapTopographic {}
FeatureLayer {
id: statesLayer
ServiceFeatureTable {
id: statesTable
url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/2"
}
}
FeatureLayer {
id: citiesLayer
ServiceFeatureTable {
id: citiesTable
url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"
onQueryFeaturesStatusChanged: {
if (queryFeaturesStatus !== Enums.TaskStatusCompleted)
return;
var resultIter = queryFeaturesResult.iterator;
while (resultIter.hasNext) {
var feat = resultIter.next();
citiesLayer.selectFeature(feat)
console.log("City:", feat.attributes.attributeValue("areaname"));
}
}
}
}
}
onMouseClicked: {
// clear selection and identify layers
statesLayer.clearSelection();
citiesLayer.clearSelection();
identifyLayerWithMaxResults(statesLayer, mouse.x, mouse.y, 10, false, 1)
}
onIdentifyLayerStatusChanged: {
if (identifyLayerStatus !== Enums.TaskStatusCompleted)
return;
// select the state layer that was identified
var result = identifyLayerResult.geoElements[0];
statesLayer.selectFeature(result);
// find all the cities in that polygon
// create the params
var queryParams = ArcGISRuntimeEnvironment.createObject("QueryParameters");
queryParams.geometry = result.geometry;
queryParams.spatialRelationship = Enums.SpatialRelationshipIntersects;
// query the table
citiesTable.queryFeatures(queryParams)
}
}
}
Thank you for this example! This gives me a good place to start. Rather than clicking the state and then seeing the cities, the behavior I'm looking for is that the user clicks a city and then the state is logged, but this is a good example for me to work from and I'm sure I can tweak it so that I can get what I want. I'll post later if I have further questions, but I greatly appreciate your help!