|
9/14/2007 3:02:42 PM
|
IndyPin Posts 16
|
I want to add a "Logical" filter to my selection script. I see that the Predicate filter gets its name from the Select by Attributes window (i.e. oFilter.Predicate = Predicate.Like). I tried something like oFilter.Logical = Logical.And but this did not work because I supposed Im not calling it up properly. Is there a different way to type this?
Thanks again.
Give a man a fish, feed him for a day. Teach a man to fish, feed him for a lifetime.
|
|
9/14/2007 3:10:23 PM
|
Dave Posts 209
|
e.g. oFilter.LogicalOperation = LogicalOperation.And
The following are valid:
LogicalOperation.Or LogicalOperation.And LogicalOperation.XOr
Dave Priest AccuGlobe Product Manager DDTI
|
|
9/14/2007 3:32:54 PM
|
Chris Posts 52
|
Also, its important to note that logical operations work against other filters. So, youll need to add at least two filters. For example:
Filter1.LeftOperand = "ST_NAME" Filter1.Predicate = Predicate.Equals Filter1.RightOperand = "MAIN"
Filter2.LogicalOperation = LogicalOperation.Or Filter2.LeftOperand = "ST_NAME" Filter2.Predicate = Predicate.Equals Filter2.RightOperand = "HIGH"
Query1.AddFilter(Filter1) Query1.AddFilter(Filter2)
Performing this query will get everything in the ST_NAME field that equals "MAIN" OR "HIGH". Dave will correct me if I state this wrong, but I believe the logical operation of a filter applies to it relationship with the previous filter.
|
|
9/14/2007 5:26:04 PM
|
IndyPin Posts 16
|
Thanks for your help. I believe Im really very close to getting this to work the way I want it to. Is AddFilter a valid attribute? Im trying to use it against the DTQuery() and its reporting that there is no AddField attribute. If its not too much trouble could you point out what I need to do to get this to work? I have the pertinent section of code below. DTQuery will only take 1 argument and I dont want to create 2 queries. Im sure Im just missing something. Id appreciate anything you could tell me.
def buttonPressed(self, sender, args): layer = ActiveMap.Layers.Item(61) oFilter = DTFilter() oFilter.LeftOperand = INTNAME oFilter.Predicate = Predicate.Like oFilter.RightOperand = "%%"+self.text.Text pFilter = DTFilter() pFilter.LogicalOperation.And pFilter.LeftOperand = INTNAME pFilter.Predicate = Predicate.Like pFilter.RightOperand = "%%"+self.text2.Text Query1 = DTQuery(oFilter)
oRecords = DTRecords() oRecords = layer.ExecuteSelectionQuery(Query1, True, True)
Give a man a fish, feed him for a day. Teach a man to fish, feed him for a lifetime.
|
|
9/14/2007 5:31:40 PM
|
Dave Posts 209
|
% is a wildcard so unless you want to anything before your search text you dont need this. %% is redundant... its the equivalent to %... and may actually use some cpu to process. You can actually specify something like this "%d%e%f%"... where % represents 0 or more characters.
Anyway this is what you want:
def buttonPressed(self, sender, args): layer = ActiveMap.Layers.Item(61) oFilter = DTFilter() oFilter.LeftOperand = INTNAME oFilter.Predicate = Predicate.Like oFilter.RightOperand = "%"+self.text.Text pFilter = DTFilter() pFilter.LogicalOperation.And pFilter.LeftOperand = INTNAME pFilter.Predicate = Predicate.Like pFilter.RightOperand = "%"+self.text2.Text
Query1 = DTQuery(oFilter) Query1.AddFilter(pFilter)
oRecords = DTRecords()
oRecords = layer.ExecuteSelectionQuery(Query1, True, True)
Dave Priest AccuGlobe Product Manager DDTI
|
|
9/14/2007 5:34:07 PM
|
Dave Posts 209
|
both of your filters are pointing to the same field...
oFilter.LeftOperand = INTNAME pFilter.LeftOperand = INTNAME
and
pFilter.LogicalOperation.And
so unless self.text.Text and self.text2.Text are the same you will never get any results.
Dave Priest AccuGlobe Product Manager DDTI
|
|
9/17/2007 9:16:16 AM
|
IndyPin Posts 16
|
Wow, thanks for your great postings. I will begin implementing your suggestions. I do believe I will still get search results however because both street names are in the INTNAME field. Im using the wildcards to make the dialog box more user friendly so the individuals can just type the name of the street without direction prefixes. Through testing Ive noticed that % = 1 character but %%=multiple characters.
Give a man a fish, feed him for a day. Teach a man to fish, feed him for a lifetime.
|
|
9/17/2007 9:23:40 AM
|
IndyPin Posts 16
|
error message on execute:
DTQuery object has no attribute AddFilter
Give a man a fish, feed him for a day. Teach a man to fish, feed him for a lifetime.
|
|
9/17/2007 9:24:25 AM
|
Chris Posts 52
|
What I think you want to do is:
oFilter = DTFilter() oFilter.LeftOperand = INTNAME oFilter.Predicate = Predicate.Like oFilter.RightOperand = "%"+self.text.Text+"%" pFilter = DTFilter() pFilter.LogicalOperation.And pFilter.LeftOperand = INTNAME pFilter.Predicate = Predicate.Like pFilter.RightOperand = "%"+self.text2.Text+"%"
Notice the wildcards (%) at the beginning and end of the RightOperand. So if self.text.Text = "MAIN" and self.text2.Text = "HIGH" and the value in INTNAME = "INTERSECTION OF MAIN ST AND HIGH ST" you would get a hit. However, if INTNAME was "CORNER OF MAIN ST" you would not get a hit, because HIGH is missing (and you used the And LogicalOperation). Hope this helps.
|
|
9/17/2007 9:31:35 AM
|
Chris Posts 52
|
oFilters = new DTFilters()
oFilters.Add(oFilter) oFilters.Add(pFilter)
Query1 = DTQuery(oFilters)
|
|
pages:
1 |