Zoom to Parcel

1021
7
04-27-2012 08:08 AM
JobyClark
New Contributor
I'm trying to find an add-in that allows me to enter a parcel#, select, then zoom to that parcel. I have seen "zoom to attribute" examples but nothing that allows me to enter parcel numbers. The add-in would be used by me to zoom to the parcel without having to open attribute table find the parcel number (out of thousands) then zoom to.

This is the code I have used, which selects all the parcels and then zooms to extent
the layer name is "Parcel_Link" and the Field that holds the parcel number is PIN

mxd = arcpy.mapping.MapDocument('CURRENT')
... df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
... Parcel_Link = arcpy.mapping.ListLayers('CURRENT', Parcel_Link, df)[0]
... whereClause = "PIN ='%s'" % Parcel_Link
... arcpy.SelectLayerByAttribute_management("Parcel_Link", "NEW_SELECTION", whereClause)
... df.extent = Parcel_Link.getSelectedExtent(True)
... df.scale *= 1.5
... arcpy.RefreshActiveView()

Any input would be nice
Thanks

Joby
Tags (2)
0 Kudos
7 Replies
TonyAlmeida
Occasional Contributor II
I hear your frustration, i don't understand why ESRI is not going to be using VBA anymore.
0 Kudos
MathewCoyle
Frequent Contributor
I hear your frustration, i don't understand why ESRI is not going to be using VBA anymore.


Because VBA is no longer going to be supported by Microsoft.

If you are interested you can read details on it here to garner an understanding.
http://blogs.esri.com/esri/arcgis/2009/03/30/vba-and-vb6-the-road-ahead/
0 Kudos
MathewCoyle
Frequent Contributor
I'm trying to find an add-in that allows me to enter a parcel#, select, then zoom to that parcel. I have seen "zoom to attribute" examples but nothing that allows me to enter parcel numbers. The add-in would be used by me to zoom to the parcel without having to open attribute table find the parcel number (out of thousands) then zoom to.

This is the code I have used, which selects all the parcels and then zooms to extent
the layer name is "Parcel_Link" and the Field that holds the parcel number is PIN

mxd = arcpy.mapping.MapDocument('CURRENT')
... df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
... Parcel_Link = arcpy.mapping.ListLayers('CURRENT', Parcel_Link, df)[0]
... whereClause = "PIN ='%s'" % Parcel_Link
... arcpy.SelectLayerByAttribute_management("Parcel_Link", "NEW_SELECTION", whereClause)
... df.extent = Parcel_Link.getSelectedExtent(True)
... df.scale *= 1.5
... arcpy.RefreshActiveView()

Any input would be nice
Thanks

Joby


Here is a script I use to zoom to an attribute passed from a script tool.

import arcpy
arcpy.AddMessage("Starting")
pu = arcpy.GetParameterAsText(0)
arcpy.AddMessage(pu)
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Main Map")[0]
lyr = arcpy.mapping.ListLayers(mxd, "PLANNING UNIT", df)[0]
arcpy.AddMessage(lyr.name)
expression = "PLANNINGUNIT = '"+pu+"'"
arcpy.AddMessage(expression)
arcpy.SelectLayerByAttribute_management(lyr,"NEW_SELECTION",expression)
df.extent = lyr.getSelectedExtent()
df.scale = df.scale*1.1
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "PU"):
    if elm.name == "PU":
        elm.text = (pu)
arcpy.SelectLayerByAttribute_management(lyr,"CLEAR_SELECTION")
arcpy.RefreshActiveView()
arcpy.AddMessage("Completed")

0 Kudos
TonyAlmeida
Occasional Contributor II
mzcoyle

Could you elaborate a little on what "pu" is and how do we change what you have for this script to work for us?
Can we see a pic of your parameters for this script?

Thanks for he script.
0 Kudos
MathewCoyle
Frequent Contributor
pu is just the variable name you are passing, short for planning unit in this case. The parameter is just a string that is searched for in the field "PLANNINGUNIT", in layer "PLANNING UNIT" in data frame "Main Map" in the current mxd. It also changes the layout text object named "PU" to the searched string.
0 Kudos
TonyAlmeida
Occasional Contributor II
mzcoyle would you mind sharing your toolbox with this script please? I would really appropriate it allot.

Thanks for your response.
0 Kudos
TonyAlmeida
Occasional Contributor II
you also said to "Add it to a toolbox and then make it a button." http://forums.arcgis.com/threads/38985-Creating-a-Custom-Toolbar-Button?highlight=zoom+parcel

How to you make a toolbox into a button in ArcMap? what exactly did you mean?

Never mind

Figured it out. under customize /geoprocessing tools, add tools then you and the script.
0 Kudos