HOW TO
The script below allows a selection of table records associated with the selected entity types. The user will be prompted to select one or many entity types available in the selected table. SDE stores entity types for shapes in a layer's F table. The F table has a one-to-one correlation with the business table and contains the shape itself, the entity type for each shape, and SE_ROW_ID, which is accessible directly through DBAccess. The entity type is represented numerically and can be one of the following 11 options: NIL_SHAPE 0
POINT_SHAPE 1
LINE_SHAPE 2
SIMPLE_LINE_SHAPE 4
AREA_SHAPE 8
SHAPE_CLASS_MASK 255
SHAPE_MULTI_PART_MASK 256
MULTI_POINT_SHAPE 257
MULTI_LINE_SHAPE 258
MULTI_SIMPLE_LINE_SHAPE 260
MULTI_AREA_SHAPE 264
Code:
'--SCRIPT ENT_SEL.AVE
'
' make the connection and get the fields from the table
' server: abbey, user: avtest, table: REXXSTATES
' THE USER WILL NEED to CHANGE THE CONNECTION STRING AND tableNAME ONLY
' THE tableNAME MUST BE CAPITALIZED
'
THECONNECTION = sdeconnection.make("abbey","","avtest","avtest")
THETABNAME = "REXXSTATES"
thetable = sdetable.make(theconnection, "avtest."+thetabname)
theflds = thetable.getfields
'
' make the querydef, clone it, and add the SE_ROW_ID field to the select
columns which
' specifies the unique feature id for each shape in the SDE layer
qd1 = querydef.make(theconnection)
qd = qd1.clone
qd.setfromtables({"avtest."+thetabname})
se_id = "SE_ROW_ID"
theflds.add(se_id)
qd.setselectcolumns(theflds)
qd.setwhereclause("")
'
' query the LAYERS table owned by the sde admin
qd3 = querydef.make(theconnection)
qd2 = qd3.clone
qd2.setfromtables({"sde.layers"})
qd2.setselectcolumns({"layers.LAYER_ID", "layers.table_NAME"})
qd2.setwhereclause("table_NAME = '"+thetabname+"'")
'
' create a list that contains the layer id for the selected table
lvlist = list.make
rs2 = qd2.openrecordset
layfld = rs2.findfield("LAYER_ID")
while (rs2.next)
lv = rs2.getvalue(layfld).clone
lvlist.add(lv)
end
rs2.close
'
' query the F table for the selected table to get the entity types
qd5 = querydef.make(theconnection)
qd4 = qd5.clone
ftablename = "F"+ lvlist.get(0).asstring
qd4.setfromtables({ftablename})
qd4.setselectcolumns({"ENTITY"})
qd4.setwhereclause("")
'
' get the entity codes... see dictionary below for reference
entlist1 = list.make
rs3 = qd4.openrecordset
entfld = rs3.findfield("ENTITY")
while (rs3.next)
ev = rs3.getvalue(entfld).clone
entlist1.add(ev)
end
rs3.close
entlist1.removeduplicates
'
' create dictionary to associate entity codes with appropriate text
thedict = dictionary.make(24)
thedict.add(0, {"NIL"})
thedict.add(1, {"POINT"})
thedict.add(2, {"LINE"})
thedict.add(4, {"SIMPLE LINE"})
thedict.add(8, {"POLYGON"})
thedict.add(255, {"MASK"})
thedict.add(256, {"MULTI MASK"})
thedict.add(257, {"MULTI POINT"})
thedict.add(258, {"MULTI LINE"})
thedict.add(260, {"MULTI SIMPLE LINE"})
thedict.add(264, {"MULTI POLYGON"})
thedict.add("NIL", {0})
thedict.add("POINT", {1})
thedict.add("LINE", {2})
thedict.add("SIMPLE LINE", {4})
thedict.add("POLYGON", {8})
thedict.add("MASK", {255})
thedict.add("MULTI MASK", {256})
thedict.add("MULTI POINT", {257})
thedict.add("MULTI LINE", {258})
thedict.add("MULTI SIMPLE LINE", {260})
thedict.add("MULTI POLYGON", {264})
'
' get values from dictionary
msglist = list.make
for each et in entlist1
ev = thedict.get(et).get(0).clone
msglist.add(ev)
end
thekeys = msgbox.multilistasstring(msglist, "Select feature types","SDE")
thesellist = list.make
for each ll in thekeys
dv = thedict.get(ll).get(0).clone
thesellist.add(dv)
end
'
' query the F table and put all the unique feature ids that are associated
with
' the selected entity type into a list
loglist = list.make
qd7 = querydef.make(theconnection)
qd6 = qd7.clone
ftablename1 = "F"+ lv.asstring
qd6.setfromtables({ftablename1})
qd6.setselectcolumns({"FID","ENTITY"})
qd6.setwhereclause("")
rs4 = qd6.openrecordset
entfld1 = rs4.findfield("ENTITY")
shpidfld1 = rs4.findfield("FID")
while (rs4.next)
shv = rs4.getvalue(shpidfld1).clone
ev11 = rs4.getvalue(entfld1).clone
if (thesellist.findbyvalue(ev11) >= 0) then
loglist.add(shv)
else
end
end
rs4.close
'
' create a log file (selection file), you will write selected features to
this
file
alogname = sdelog.makelogname(theconnection)
alogfile = sdelog.make(theconnection, alogname, "avtest."+thetabname,
#SDELOG_MODE_CREATE)
'
' open the recordset and step through it, select features based on selected
entity type
rs = qd.openrecordset
theidfld = rs.findfield("SE_ROW_ID")
while (rs.next)
v = rs.getvalue(theidfld).clone
if (loglist.findbyvalue(v) >= 0) then
id = rs.getvalue(theidfld).clone
alogfile.addfeature(id)
else
end
end
rs.close
qd.setsrcdest(alogfile, nil, false)
thetable = dbtable.make(qd)
thetable.getwin.open
av.purgeobjects
'-- END OF SCRIPT
Note:
Using the GetClass.GetClassName request on each shape will only return polygon, polyline, or multipoint and may not accurately represent the features. For example, annotation is multipoint with GetClass.GetClassName but is actually stored as a line in SDE.
Article ID:000005315
Get help from ArcGIS experts
Download the Esri Support App