Python
UPDATE: After receiving a request to modify the code to ignore .lock files, I have an updated to this post.
I’ve received a request on how to use the Zip Shapefile code I posted last week from ArcGIS. Sorry, I did not set the code up to call directly from ArcGIS but only as an illustration of how it can be done.
I have, however, with some minor tweaking, made a version that can added to ArcToolbox.
Since I use python for different tasks, I launch python scripts a variety of ways. Depending on what I am doing, a single script may need to accept parameters from either:
Passed in from an ArcGIS Toolbox Tool. Re-occurring default value. Often used in scheduled processes, a nightly backup, for example. A temporary set of values used in an interactive, debugging session. What I often do is make the parameter interpretation flexible to meet my needs.
UPDATE: After receiving a request to modify the code to ignore .lock files, I have an updated to this post.
One of the tasks I’ve been automating is publishing a weekly data update to a website. The update consists of shapefile. The trouble with shapefiles is they consist of 3 or more files with the same basename but different extensions in the same directory.
Not an overly complicated situation but a common one that ArcGIS does not have a solution out-of-the-box.
In running an automated process, I had a TopoToRaster repeatedly fail on me. The only input theme was a contour theme. The process ran fine when I used the envelope of the contour theme as the output extent but when I changed it to the envelope of a polygon theme, it would bomb. The polygon’s envelope was smaller than the contour theme.
ArcCatalog would bomb out without presenting any sort of useful message.
I was using Model Builder (ugh!) to select records in one table (CWI.C5ST) that relate to a subset of records ([BHGEOPHYS] = ‘Y’) in another table (CWI.C5IX). There is not an existing tool for doing this in ArcGIS. I did find a post by Layne Seely in ArcForums titled ‘trying to perform ‘relate’ in Model Builder.’ that led me to the Make Table View under Data Management Tools-Make Table View and even had the basic syntax I was looking for (if it hadn’t I probably would have guessed that it would not allow subqueries).
As previously mentioned, I have a scheduled nightly backup that is written in Python. Most of it has been working fine but I had not gotten it to copy files to network drives. I finally got around to correcting that part. My first attempt was just to map the network drives for the user account that is used to run the task. No good.
My second attempt was to call a .
So I have a nightly process that runs and I, being the lazy programmer I am, didn’t want to bother checking a log file each morning to see how it went. The natural answer is to have the results emailed to me because I do have to check my email.
Since the process is already handled mostly in python, thought I would implement the emailing via python. It was actually simple enough to do–just required figuring out the setting for my SMTP server (actually I didn’t figure it our for my work server so I’m using my GMail account).
The USGS updated a significant portion of NED data for my state in June. I recently downloaded the updates, processed them–projecting and converting the elevations from meters to feet–using python and geoprocessing. My python skills are still pretty crude but I was able to get the job done.
One of the benefits of working for the public sector is that I can more freely publish code without worrying about ‘trade secrets’ or what have you so I thought I would put my code out for anyone to see, maybe someone will find it useful. It is split into two separate files, mostly because I used Model Builder to generate the main processing chunk of code (Project_Reclassify.py) and another script to control looping, etc. The code isn’t pretty and you’ll see the results of my development process with two subroutines in LaunchScript.py that could really be one.
I recently had the need to calculate the distance from a point (address point) to a polyline (street segment) and wanted to avoid using any additional libraries because it was being done for an external client. Ok, I actually used arcgisscripting for reading the data but that lacked, from what I could tell, the fine-detail granularity of measuring distance between individual geometries.
But since the only spatial operations I needed were to measure the distance between two points and the distance between a point and polyline, I decided to just do it via brute force.