Select to view content in your preferred language

Automating a Find and Zoom Process

10638
21
07-01-2014 07:20 AM
ib
by
Deactivated User
Hi all,
I am a total newbie to programming anything into Arc with little to no programming experience but I'm finding the need to be able to automate certain processes so now's as good of time as any to start learning.  The problem is, I need to get this process going ASAP, of course...

What I'm trying to do seems fairly simple:

I have a bunch of points with unique ID's and I need to be able to export the area around these points from my base map to JPG's at multiple zoom levels.

My process might look like this:
1. Enter the unique ID into a field
2. The program/script would zoom to the point with this ID and export a JPG at two or three different scales.

Can I do this in model builder or will I need to write a Python script? 
Thanks!
0 Kudos
21 Replies
IanMurray
Honored Contributor


Its crashing prior to the Select by Attribute, when its making the layer object.

I changed the Layer Name Parameter to a Layer type, and it still ran, so if you want to do it that way it should work.  I made it as a string originally so it could be run in ArcCatalog(which seems to speed up geoprocessing opposed to ArcMap, if you knew python better, you would just be able to change the varialbes and it could run outside of Arc entirely, which would make it even faster, but oh well.)

Btw, this script is made to work only if your Layer has a field called ID, not FID or OID or anything different from that, and it should be able to handle all characters for the ID value, just make it what it shows in the attribute table.  Also the layer must already be in a saved mxd file if that wasn't clear before.  Also remember python is case sensitive so if the Layer Name is Arctest_01, it will crash for ArcTest_01.  For the ID number just enter as it shows in the attribute table, no other characters.

I've tested this on two map documents and it should work fine.  If you want to change the Layer Parameters thats fine, it worked both ways for me.

ib
by
Deactivated User

SUCCESS!!!!!! 

The script was having issues with "FID" and "ID" being in two columns, so I changed all of the ID's to FID's and it worked!  Thank you so much!  Now that it's working, I can go and start modifying it and breaking it again. 

I'm seeing how all of this works now and starting to understand the functions.  Thank you so very much for taking the time to work through this (really, to do it) for me.

I'll play with it a bit and come back to this thread if I get more functionality out of it (or if I'm having trouble- lol).  Again, thanks a ton!  I look forward to expanding upon what I have and will learn from this script. 

0 Kudos
IanMurray
Honored Contributor

Glad you got it worked out!

If you got any other questions about it, feel free to ask them here, or you can post stuff in Python‌ and GIS Developers

Also with the new system be sure to tag your post python if you got python related questions so people can find them easier.‌

0 Kudos
CesarMediavilla
Emerging Contributor

Hi Ian. I can not speak English. I am translating with google. I am very interested in adapting your script. Features-I have a class and I've added a field ID String. But when I run I get an error that I believe is in the syntax of the Query. To work with a personal geodatabase. I get the following error:

Traceback (most recent call last):

  File "D:\A-Fichas\ZoomToID.py\ZoomToID.py", line 23, in <module>

    arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION" , "ID = " + ID)

  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6494, in SelectLayerByAttribute

    raise e

ExecuteError: ERROR 000358: Expresión no válida

Falló al ejecutar (SelectLayerByAttribute).

Falló al ejecutar (ZoomToSelectedID).

Error el Tue Jul 15 12:01:25 2014 (Tiempo transcurrido: 0,56 segundos)

I could clarify the syntax of the query?. Thank you very much from Spain.

0 Kudos
IanMurray
Honored Contributor

Hi Cesar, 

It's likely due to the fact that geodatabase field names must be in brackets for SQL expressions.

Try this instead for that line of code

arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION" , "[ID] = " + ID)

I'm not at a computer where I can check it right now.  Also check the link below about making SQL expressions

ArcGIS Desktop

Hope this helps!

CesarMediavilla
Emerging Contributor

Hi Ian, thank you very much for your help. The program no longer runs but I do not select any item. I will try new syntax to see if it works. I'll tell you. Thank you very much again.

0 Kudos
CesarMediavilla
Emerging Contributor

Hi Ian. Another question, please. How do I know the number of selected elements with SelectLayerByAttribute_management?

Thank you very much

0 Kudos
GaryChedore
Deactivated User

Hi Ian:

I'm a novice programmer, interested in iterating an entire list through the find and zoom process.

I know this was asked in the same series of threads, but the version was never posted. I would appreciate your guidance when you have a moment

Thanks in advance!

Gary

0 Kudos
IanMurray
Honored Contributor

Hi Gary,


Could you be a little more clear with what you were wanting to do?  Are you wanting to iterate through a list of feature and export out for each one of them at different scales?  I could gladly help out with something like that, in fact looking over the original script now I'm finding a few ways to make it work easier for people and more efficient.  The more information you can give the better.

0 Kudos
GaryChedore
Deactivated User

Thanks for the quick reply:

Yes.. I have a list of mapgrid Id's which if I could go to export each of them at one or more scales simply by using a text file or .csv file to load them in or some other simpler method within the database, great.

I did this over the weekend and it took some time thankfully your program cut that time drastically, but I wondered how much tweaking it may require to pull in the list and run off all pdfs for 33 records at 25000, 50000, and 100000 scales.

Clear enough yet?

Gary

0 Kudos