Friday, February 25, 2011

Getting a File Extension

Here is a useful bit of code to get the file extension of a file. The os module has a useful built in function called splitext(), which returns a string array where the 2nd entry is the file extension.

From Python.org:
Split the pathname path into a pair (root, ext) such that root + ext == path, and ext is empty or begins with a period and contains at most one period. Leading periods on the basename are ignored; splitext('.cshrc') returns ('.cshrc', '').

Enjoy
~A


def __fileExtension(filePath):
import os
return os.path.splitext(filePath)[1]

Wednesday, February 2, 2011

Map Scale and Resolution

When I first started using GIS, I did not program and I did not write any custom code.  I was a cartographer many years ago.  As I move on in my career I have slowly moved away from cartography, but the principles I learned in my cartography classes have been critical to my success as a developer.  When I saw this blog post it brought back a time when I use to just be a map maker (cartographer).  If you program in the GIS world, no matter if it's web, desktop, or services, you should always have a good understanding of how to present data.  Developing tools to show and analyze data is just one part of GIS, but in reality it's how you interpret/display the results that really matter.

So read up on this article because understanding Map Scale and Resolution is important to being a good GIS programmer.

I shall step off the soapbox now.

Friday, January 7, 2011

Developer Guidelines for Python

For anyone getting heavily involved with python development or wants to start getting involved with python, I recommend you follow the PEP-8 specs outlined on http://www.python.org/.  It's a simple enough programming style that I find allows for easy cooperation between developers. 

If that isn't good enough for you to follow, it's also the official develop style of the programming language. 

So check it out, and improve your python skills today: http://www.python.org/dev/peps/pep-0008/

Enjoy

Wednesday, January 5, 2011

TIGER Data Download Frenzy

It's here, so go get it.  The TIGER data is ready to go! Get it here.

Enjoy

Friday, December 3, 2010

Getting Installation Information in ArcGIS 10

At v10 there is a very Arcpy way of getting the installation directory for ArcGIS Desktop.  It's very easy and it goes as follows:

Now we want to see what software is installed on the machine:

You'll ge a list of software installed on the machine.

Happy Coding!

Thursday, October 28, 2010

Dynamic Label Tip

When working with data driven pages, you might want to put the adjacent grid cells on the page layout. What happens is the cell is empty? By default, the value "[EMPTY]" will appear, which is not very pleasing. To get around this issue, there is a property called emptystr. If you set the emptystr=" " you will see nothing instead of "[EMPTY]."


Code sample below:

< dyn emptystr=" " property="PageNumber_E" type="page" >

Tuesday, October 26, 2010

Assigning Alias to Custom Toolboxes

I create lots of custom scripts and toolboxes to help out with various tasks, and I noticed the following message the other day when I exported a script from model builder to python:
# Warning: the toolbox toolbox.tbx DOES NOT have an alias.
# Please assign this toolbox an alias to avoid tool name collisions
# And replace arcpy.gp.toolname(...) with arcpy.toolname_ALIAS(...)

Basically, the system is asking for an Alias to provide an additional unique identifier because tools within the same toolbox cannot have the same name, but tools in other toolboxes can have the same name. 

To define an alias, open ArcCatalog and right click on the tbx file.  Select properties, you'll see this:

Enter in an alias and press ok.

That easy!
Enjoy