HOW TO

Store queries using bitmaps, dictionaries, and object tags [SCRIPT]

Last Published: April 25, 2020

Procedure

In Avenue, queries, or more specifically, the results of queries can be stored using a bitmap object. You can manage these bitmaps using either a dictionary object that you store in your project as an object tag on the view document, or any other object that supports object tags.

This example is in the form of two scripts, one (ChooseQuery.AddQuery) for an administrator to create the saved queries, and another (ChooseQuery.Click) for the end-user that should be used as a click event on a button in the View GUI.
Code:
'** ChooseQuery.AddQuery
'** YOU MUST SET THESE VARIABLES!:
ViewName = "View1"
ThemeName = "States.shp"
QueryStr = "( [Pop1990] < 666168 )"
QueryName = "Low Population"

'** Derive objects to use
v = av.GetProject.FindDoc(ViewName)
t = v.FindTheme(ThemeName)
f = t.GetFTab

'** Check to see if the view already has a tag.
'** Presumes its the right kind of tag.
vtag = v.GetObjectTag
if (vtag = nil) then
vtag = Dictionary.Make(1)
elseif (vtag.is(Dictionary)) then
x = vtag.ReturnKeys.Get(0)
if ((vtag.Get(x).Is(List)).not) then
Msgbox.Warning("View already has a different"+
" object tag--cannot continue","")
exit
end
end

'** Execute the query
b = f.GetSelection
r = f.Query(QueryStr,b,#VTAB_SELTYPE_NEW)
if (r.not) then
Msgbox.Error("That query did not work right!","")
exit
end
f.UpdateSelection

'** Set the ObjectTag
vtag.Add(QueryName, {ThemeName, f.GetSelection.Clone})
v.SetObjectTag(vtag)


Code:
'** ChooseQuery.Click
'** Ask user to choose a saved query
v = av.GetActiveDoc
vtag = v.GetObjectTag
lKeys = vtag.ReturnKeys
sq = Msgbox.ChoiceAsString(lKeys,"Choose a query:",
"Saved Queries")

'** Check the result & get parameters
if (sq = nil) then exit end
ThemeName = vtag.Get(sq).Get(0)
selBit = vtag.Get(sq).Get(1)
t = v.FindTheme(ThemeName)
if (t = nil) then
Msgbox.Info("could not find theme: "+ThemeName+
". Cannot continue.","")
exit
end

'** Apply the selected Bitmap
f = t.GetFTab
f.SetSelection(selBit)
f.UpdateSelection

Article ID:000001485

Software:
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic