3

I'm trying to create something in here. I want to have an automated process of doing a DEFINITION QUERY then ZOOM TO LAYER with one step.

the concept is like that, a dialog comes up with one form that asks me to put a unique id for the specific parcel that I'm trying to look up, then I type the parcel numder then hit OK then it brings me to that specific parcel directly.

  1. Dialog pop-up
  2. Empty form to be filled
  3. Hit ok
  4. It zooms directly to that parcel

How can I do this using ArcPy?

An automated way to do the definition query then zoom to layer.

  • Have you got the dialog working? I am not sure if you can get to the layers' definition query via python but you can make a layer with a where clause, this should reduce the apparent extent and then zoom to layer. – Michael Stimson Jul 2 '14 at 22:48
  • The problem here is that I'm new to both python and modelbuilder. I'm just thinking of a way to do a definition query on a specific attribute then after finding it it will zoom to layer. Simple yet complicated! But if I get a solution to this one I'm surely will have the experience to do the upcoming tasks. – user32954 Jul 2 '14 at 22:52
  • There is code provided in an answer to possible duplicate of How to zoom to selection in arcpy.mapping and only see selected features? – PolyGeo Jul 2 '14 at 22:52
  • Your biggest problem is the dialog box. How do you feel about C# or VB.net instead of python? Much more control but less portability. – Michael Stimson Jul 2 '14 at 22:53
  • That would be perfect if you could show me the way to do it, can't wait to be at ESRIUC! Many ideas but less means! I would be thankful, Sir. – user32954 Jul 2 '14 at 22:56
4

The definition query of the layer and zooming to is the easy part:

import arcpy

# Assuming that Value is set by the form, there is only one data frame
# and the layer name is LayerName

doc = arcpy.mapping.MapDocument("Current")
dataFrame = arcpy.mapping.ListDataFrames(doc)[0] # the first data frame

MapLayers = arcpy.mapping.ListLayers(doc,"LayerName",dataFrame)
Layer = MapLayers[0]
Layer.definitionQuery = "Field = %s" % Value
Extent = Layer.getExtent(True) # visible extent of layer

dataFrame.extent = Extent
arcpy.RefreshActiveView() # redraw the map

The hard part is building the form and accepting/validating the values.. You have to ensure that the definition query is valid; look at GetCount_management to ensure that the layer as at least one feature before zooming.

  • The "hard" part has only a similar degree of difficulty to do the basics of form input (GetParameterAsText on a Python script tool) and checking for features before zooming (GetCount; as you indicate) because there is no need to validate the Definition Query syntax when all that is being input is an ID as specified in the question. I think doing something fancier than that should be researched/asked as a new question. – PolyGeo Jul 3 '14 at 0:48
  • Yes @PolyGeo if it is run as a script tool nothing fancy need be done. The OP is thinking about a custom form and I think a python add-in. I can really only help with the arcpy in this case as the OP needs to find a form lib (like QT or PyWin) to implement the custom form and seek help on that from Stack Overflow. As a beginner though it might be getting too deep too fast. – Michael Stimson Jul 3 '14 at 0:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.