I am trying to zoom to a selected feature on a feature layer. I have found some answers here but I was not able to adapt any of them into my situation.
Related answers:
https://community.esri.com/t5/arcgis-pro-sdk-questions/arcgis-pro-sdk-select-feature-from-featurelayer/m-p/866907#M4984
https://community.esri.com/t5/arcgis-runtime-sdk-for-net/arcgis-runtime-sdk-for-net-zoom-to-features-that-are-not/m-p/426725#M5169
https://community.esri.com/t5/arcgis-pro-sdk-questions/pro-sdk-how-to-get-features-after-getfeatures/td-p/766418
string selectedCounty = CountiesListBox.SelectedItem.ToString(); QueuedTask.Run(() => { FeatureLayer featLayer = countiesLayer as FeatureLayer; QueryFilter qf = new QueryFilter { SubFields = "NAME2" }; qf.WhereClause = selectedCounty; featLayer.Select(qf); MapView.Active.ZoomToSelected(); });
I think I have syntax problem somewhere. If I remove qf I am able to select everything.
Hi OguzSariyildiz,
If you surround your code snippet with a try {} catch {} you should see an error message because of your where clause is not a valid where clause.
The where clause string for a QueryFilter has to be specified in sql where clause format:
{ string selectedCounty = "San Bernardino"; QueuedTask.Run(() => { var featLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(fl => fl.Name.Contains("Counties")).FirstOrDefault(); QueryFilter qf = new QueryFilter { WhereClause = $@"name = '{selectedCounty}'" }; featLayer.Select(qf); MapView.Active.ZoomToSelected(); }); }
The idea was zooming to selected feature when user selects it via a listbox. I knew I was doing something wrong with the whereclause so it worked when I changed the code as
string selectedCounty = CountiesListBox.SelectedItem.ToString(); QueuedTask.Run(() => { FeatureLayer featLayer = countiesLayer as FeatureLayer; QueryFilter qf = new QueryFilter { WhereClause = $@"myFieldName = '{selectedCounty}'" }; qf.WhereClause = selectedCounty; featLayer.Select(qf); MapView.Active.ZoomToSelected(); });
Thanks @Anonymous User
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.