Web Analytics Made Easy -
StatCounter

Node Dangles

arcpy

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.
One of the great advancements over the last decade plus in GIS is that government agencies have started to move away from a ‘recover-our-cost’ mentality to more of an ‘Open Data’. Minnesota, for example, has launched their Geospatial Commons as a platform for sharing data. And while getting free, authoritative data is awesome, it can leave you in a bind if the structure of the data changes. Sometime between April and September, Hennepin County, Minnesota, changed the schema of their publicly available street centerlines data.
Working on doing some advanced ArcGIS server printing and had the need to batch convert many existing .mxd files to .lyr files. So instead of opening up X number of map documents, thought I would do it via code. All of my .mxds in this case had just one data frame so the process was pretty simple–I add an empty group layer (Thanks Petr Krebs for the idea), copy all the existing layers into it, and save it out as a layer file.
Recently I’ve created Python add-ins for data entry for our staff. Most of these have a toolbar with a ‘Help’ button that opens a help file in .pdf format.Sample python add-in toolbar. The first add-in was for ArcCatalog and this worked splendidly. I was using os.startfile(path to help.pdf). However, when I started doing ArcMap add-ins, clicking the Help button would open the help.pdf but ArcMap would crash. Oops! Luckily the Python development team at Esri already had a blog post about this at their ArcPy Café blog.
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 mentioned using Tapiriik to batch download my entire Garmin Connect history–over 1,000 separate .GPX files. I found several tools to convert .GPX to shapefiles that worked but none seemed to recognize my heart rate data. The trick is Garmin extends the GPX specification to incorporate the heart rate: <span style="color: #333333;">xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1"</span> Each track point looks like this: 2014-03-16T20:35:47+00:00 296.20001220703125 86 gpxtpx:TrackPointExtension trkpt  Since the first few exiting GPX converters failed to meet my needs, I decided to make my own, at least partially.
I was recently re-evaluating our back-up procedures and discovered and found a nasty bug with the arcpy’s ListFeatureClasses request. If you have a feature class in a feature dataset with the same name, ListFeatureClasses may not find it or anything else in that feature dataset. Unfortunately, we recently made our daily backup a python-based system that uses ListFeatureClasses and got bit by this bug. After discovering missing data in our backups, I reconstructed what happened and found this bug.
I was helping a co-worker who needed to check if a field exists in their arcpy script. Since we were located at their computer, I thought I would just do a quick Google search and pull the code off this blog. Seemed logical since I the original purpose was exactly that—to serve as a handy, public place to store code snippets that I use & that others might find handy.
In the last week, I have looked for multi-part features a couple of times. Today, I was looking for multi-part polygons after dealing with the fall-out of a case of Clip Gone Wild as shown below. I have not found a way to write a query to find these but Field Calculator does allow you to calculate a field’s value to the number of parts. Using the Python parser, just write the formula (note that case matters): !
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.
Menu