Web Analytics Made Easy -
StatCounter

Node Dangles

Quick & Dirty

Working with a routine process today that I normally only do once in awhile but today needed to do it several times. It requires changing the definition query on several features classes. Being the ‘lazy’ GIS guy that I am (owner of a company I used to work at called me that once as a sort of compliment for my tendency to script a lot of what I did), I decided to finally script it instead of changing definition queries about 42 times.
I’ve been working on a few different data import routines and one of the things I recently built was the ability to verify that a potential Code to be entered into a field with a Coded Value Domain is valid. The logic of the code is pretty straight-forward. Get a field’s domain and check that a potential value is one of the code values. The biggest ‘trick’ in this code is that arcpy.
I just had the need to go through a directory containing many (100+) layer files (.lyr) and verify the data sources in each. I could have loaded each into ArcMap and checked the properties, but choose not to. Here’s the bare-bones script I used instead: import arcpy, glob,os theDir = r"L:\gdrs\data\org\us_mn_state_dnr\elev_minnesota_lidar\\" os.chdir(theDir) for iFile in glob.glob("*.lyr"): print iFile lyr = arcpy.mapping.Layer(iFile) for i in arcpy.mapping.ListLayers(lyr): try: print " {0}: {1}".format(i,i.dataSource) except: print " {0}: Does not support dataSource".
I’m in the process of rewriting a process, moving most of the processing from arcpy to postgresql-enabled python (love me some psycopg2). One of the QC checks I’m doing at the end of this re-write is just verifying that the feature class schemas are the same (or that the differences are intended) under the new process as they were in the old process. And while ArcGIS does have a good tool for this, there were a couple tweaks I wanted to make.
In mapping cross sections, our geologists often find themselves renaming their stratigraphic units midway, or at the end, of creating multiple cross sections. This can cause a situation where we need to change multiple values in multiple fields in multiple feature classes–a situation that can get messy very fast. Perfect situation for a quick & dirty arcpy script and, in this case, an ArcToolbox tool that can be downloaded. This tool will change all feature classes in the O:\clay_cga\sand-distribution_model\dnrPackages\stratlines directory.
This is a bit of a tangent but for some crazy reason, I wanted to convert some text to audio so I could listen to it while I drive. A quick Google search left me without any freeware that could handle the 53 page document–there are some cool websites that do text to mp3 like vozme and YAKiToMe! but they didn’t convert the whole document. I then found pyTTS, a python package that serves as a wrapper to the Microsoft Speech API (SAPI) , which has been in version 5 since 2000.
Question: How do I get ArcMap to automatically pan through an area. As I mentioned in a previous post, I recently had the need to have ArcMap automatically pan through a project area. My first attempt was to print a series of data-driven pages (using a fishnet polygon layer as the index) this but that did not accomplish what I needed so I switched to arcpy, which made the task simple enough.
As contributor of the day, Jason Scheirer, pointed out, python has a simple, direct way to browse through the subdirectories of a directory–os.walk Here is a bare-bones example of using it to print out the subdirectories in a path. The files variable of the 3-tuple is a list of files similar to the dirs variable that I loop through. Thanks Jason for pointing out something I missed. import os theDir = 'c:/temp/' for root, dirs, files in os.
Someone asked how to have python recursively search a folder structure. There may be a better way but this is how I typically do it–it basically starts with one directory and loops through the contents compiling a list of sub-directories as it goes through the contents. import glob, os theDir = 'c:/temp/' theDirList = [] theDirList.append(theDir) while len(theDirList)> 0: newDirList = [] for iDir in theDirList: print iDir for iFile in glob.
For some odd reason, I wanted to split all the arcs in a polyline feature class to a specific length–if a specific feature was longer than the target length, it would become two or more separate polyline records. Here is the bare-bones script that copies an existing feature class into a new feature class then processes each record, splitting it into multiple records if the polyline is longer than the user-specified tolerance.
Menu