An easy way to get the line number of your python code

Sometimes you just want to know where things are in the script when you are debugging.  Or where things came from.  You can pass that information or report it while debugging using this snippet.  Easy, simple.

import inspect

def lineno():
    """Returns the current line number in our program."""
    return inspect.currentframe().f_back.f_lineno

print "this is line", %lineno()
print  " the line number, %s, is in the middle of this sentence"%lineno()
i = type(lineno())
print i

results in :

this is line number 8
the line number, 10, is in the middle of this sentence
<type 'int'>

Note that the line number is type integer.

Thanks to the Danny Yoo and the Active State recipes for this easy tip.

Calc the lat/long of a point in python using new ArcPy tools

Calculating the latitude and longitude of a point that is not in a geographic coordinate system was a tricky thing for me to figure out one day.

My data was not in the “World Projection” (as ArcMap calls it) so when I finally figured out how to access the x,y coordinates of the point, they were not in Lat/Long.  So basically I reproject the file, extract the x,y coordinates, then reproject back to State Plane which is what I need.  Not too elegant, but it gets the job done.

Here’s how I accomplished it:

Continue reading

The importance of participating in your community – python, GIS or otherwise.

I just solved a problem that has perplexed me for a week. I have banged my head and the heads of my colleagues on an issue that has pretty much halted a project. It was solved today because someone 4 years ago posted a little note on the ESRI forums and I am so grateful to them I would like to hug them. Thank you Rafael Ferraro! I would thank you in the forums, but the comments have been closed in the old archived forums.

So this brings to mind the importance of each and every one of us participating in our communities. Each voice is
Continue reading