SpatialQueryFilter() set up

407
2
11-26-2021 01:44 AM
DavidMrázek
Occasional Contributor II

Hello everyone,
I would like to ask how should I set the SpatialQueryFilter() to look for different values ​​in different columns in two layers. First FeatureLayer is "PlochyOsidleni_Final" and second is "intravilan_ZTM5".

In the first, I'm looking for a value 'Vysoký Chlumec' in the column "NAZ_CAST".

In the second value 'Víska' in the column "NAZEV".

 var mv = MapView.Active;
            var plochy = "PlochyOsidleni_Final";
            var intravian = "intravilan_ZTM5";
            var str1 = "NAZ_CAST = 'Vysoký Chlumec'";
            var str2 = "NAZEV = 'Víska'";
            SpatialQueryFilter sqf = new SpatialQueryFilter()
            {
                WhereClause = str1 + str2,
                FilterGeometry = geometry,
               SpatialRelationship = SpatialRelationship.Contains
            };
            var features = mv.GetFeatures(geometry);
            var lyrI = mv.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>()
                .FirstOrDefault(l => l.Name == intravian);
            var lyrP = mv.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>()
                .FirstOrDefault(l => l.Name == plochy);
 List<FeatureLayer> editableLayers = new List<FeatureLayer>();
            editableLayers.Add(lyrP);
            editableLayers.Add(lyrI);
           
            foreach (FeatureLayer editableFeatureLayer in editableLayers)
            {
                Table fc = editableFeatureLayer.GetTable();
                int descriptionIndex = -1;
                descriptionIndex = fc.GetDefinition().FindField(plochy);
                using (var rowCursor = editableFeatureLayer.Select(sqf))//here show me error:'An invalid SQL statement was used.'

                {
                    var oid = rowCursor.GetObjectIDs();

When I write it like this, it throws me a mistake.

 

Thank you for all the advice and ideas.

0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor

You do not say what the error message is or at what line it is occurring at, so how are people meant to help you?

That said I would imagine an error is cause by a malformed where clause:

WhereClause = str1 + str2,

 

Would that not resolves to: "NAZ_CAST = 'Vysoký Chlumec'NAZEV = 'Víska'"

You need an AND or OR between these two statements, so it should be:

WhereClause = str1 + " OR " + str2,
0 Kudos
DavidMrázek
Occasional Contributor II

After all, I wrote the mistake directly in the code.But thank you for the advice anyway.

0 Kudos