Sunday, December 23, 2012

Free GeoSpatial Books Online!


Hi all,

I just heard about this site having 100’s of free geospatial pdf books (and other topics).

You do need to make an account (free). Use the search tool for your topic of interest.

Slashgeo has sorted some topics for you at:

My Favorite GIS Video Links

I've sent these out in emails in the past, but I thought I would just start a list here. Have fun, and add to the list if you wish!
 

"West Wing - Why are we changing maps?"

G-I-S State of Mind:

Map Of The World As We Know It (and I see signs):

Tied Together (with GIS):

G-I-Yes:

Fun GIS Products





 
 
I’ve used Geolopes for years and many people have asked where I got them. Thought you might be interested in where to get some:
http://www.necartographics.com/
I also just found this site… some interesting GIS items not based on any software vendor:
http://www.zazzle.com/gisnuts/gifts
BTW, these are just fun items and I do not take any responsibility for any problems you might have with their products… you’re on your own!

Use Maplex Label Engine



Use Maplex Label Engine for fixing this problem.




Before








After with Connect features and Minimize density option









There are many options… go and experiment!

Six of this Year's Most Riveting Maps


I just read this page from GIS Lounge and thought you might be riveted too. I especially like the music set to the last one. 
 
It’s “Six of this Year’s Most Riveting Maps” http://gislounge.com/2012-most-riveting-maps/#comment-39407

Wednesday, December 19, 2012

Working with a Definition Query, ArcPy and Python

I recently taught a class in Portland, OR where the students asked about changing a definition query in Python. Well, I thought this was simple -- and it is, but I didn't get there the easy way! I would assume that others may also have this challenge so I thought I would post this little challenge.

First, I thought I would set a varible to an existing definition query (so I'd see exactly how one looks as it comes from ArcPy). I have a map document that contains a layer named "Survey Grid Boundary" with a definition query.


In the python window, I typed the following lines:

>>> mxd = arcpy.mapping.MapDocument("CURRENT")
>>> layers = arcpy.mapping.ListLayers(mxd,"Survey*")
>>> print layers[0].definitionQuery
"TOWNSHIP_C" = 'C7' AND "RANGE_CD" = '2'

Cool, I thought! This is easy! So then I thought I could just change the statement with a query held in a variable. I just wanted to change the last number from a 2 to a 3. So I entered (and I knew this would cause troubles):

>>> query = "TOWNSHIP_C" = 'C7' AND "RANGE_CD" = '3'
Parsing error SyntaxError: invalid syntax (line 1)
Of course we all know that python uses quotes (either " or ') to enclose strings. Dummy me immediately thought of the str() function. WRONG! Then I thought of just quoting everything in quotes. WRONG! Then I started searching for a function to quote complex strings. WRONG!!! I was getting my self into a rabbit hole...

So then a basic issue hit me... the issue about path names and using the backslash '\'. And we've learned that the backslash is an escape character. So I came up with:

>>> query = '\"TOWNSHIP_C\" = \'C7\' AND \"RANGE_CD\" = \'3\''
>>> layers[0].definitionQuery = query

>>> print layers[0].definitionQuery

"TOWNSHIP_C" = 'C7' AND "RANGE_CD" = '3'


It works perfectly! And, it's pretty darn simple.

So just remember the the backslash can be your friend and there are two single quotes at the end of the variable assignment line rather than a double quote. 




Using Jeff's comment, I thought I would respond to his post and put the statements into courier font to read easier... well, it didn't work so I'm adding that here where I can control font. Thanks, Jeff!

query = '"TOWNSHIP_C" = \'C7\' AND "RANGE_CD" = \'3\''

or 

query = """"TOWNSHIP_C" = 'C7' AND "RANGE_CD" = '4'"""


So, which is cleaner and easier to read??? It probably comes down to your choice. That's fun with Python!

Thank you, Jeff.