<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jduck.net &#187; python</title>
	<atom:link href="http://jduck.net/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://jduck.net</link>
	<description></description>
	<lastBuildDate>Fri, 02 Jul 2010 13:01:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Woowee&#8230;</title>
		<link>http://jduck.net/2007/07/03/woowee/</link>
		<comments>http://jduck.net/2007/07/03/woowee/#comments</comments>
		<pubDate>Tue, 03 Jul 2007 19:51:12 +0000</pubDate>
		<dc:creator>Jonah</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[geospatial]]></category>
		<category><![CDATA[gis]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://jduck.net/2007/07/03/woowee/</guid>
		<description><![CDATA[The blog is getting mighty impersonal with all those del.icio.us posts. Maybe that can serve as a reminder for me to post more. I have been hacking on a bunch of convenience code in python for the LTM (Land Transformation Model) which serves as the land use projection portion of my research. Basically just wrapping [...]]]></description>
			<content:encoded><![CDATA[<p>The blog is getting mighty impersonal with all those del.icio.us posts.  Maybe that can serve as a reminder for me to post more.  </p>
<p>I have been hacking on a bunch of convenience code in python for the LTM (Land Transformation Model) which serves as the land use projection portion of my research.  Basically just wrapping a bunch of ArcGIS functions that do what I need done and then some file manipulation and config file writing before I launch code written by our postdoc.  Going to try and do some time projections for all of the state of Indiana and then go back to my Muskegon study area with the new tools to re-run the model up there.  It should make things run much more smoothly.</p>
]]></content:encoded>
			<wfw:commentRss>http://jduck.net/2007/07/03/woowee/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick and dirty GIS Server</title>
		<link>http://jduck.net/2007/06/26/quick-and-dirty-gis-server/</link>
		<comments>http://jduck.net/2007/06/26/quick-and-dirty-gis-server/#comments</comments>
		<pubDate>Tue, 26 Jun 2007 16:18:26 +0000</pubDate>
		<dc:creator>Jonah</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[gis]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://jduck.net/2007/06/26/quick-and-dirty-gis-server/</guid>
		<description><![CDATA[Here is a quick and dirty ArcGIS geoprocessing server. I mostly did this so that I can call ArcGIS routines from scripts on my linux box across a cluster of ArcGIS servers. It is not without caveats, mostly security caveats. I work in a firewalled environment and would not recommend exposing the entire arcgisscripting geoprocessing [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick and dirty ArcGIS geoprocessing server.  I mostly did this so that I can call ArcGIS routines from scripts on my linux box across a cluster of ArcGIS servers.  </p>
<p>It is not without caveats, mostly security caveats.  I work in a firewalled environment and would not recommend exposing the entire arcgisscripting geoprocessing object in a non-firewalled environment, without adding some security.  With the client code I am able to write scripts that work on either Win32 or Linux with the same code.</p>
<p>Additionally, you will need to refer to files and directories in your scripts as they would appear to the server instance (with its windows permissions).  As ArcGIS scripting routines do not directly allow the passing of GIS data to them, you will have to point to them on the server&#8217;s filesystem, geodatabase or remote ArcSDE server as you would locally on the server.<br />
<span id="more-90"></span><br />
<strong>Server:</strong></p>
<pre>from SimpleXMLRPCServer import SimpleXMLRPCServer
import arcgisscripting as agis
geop = agis.create()
server = SimpleXMLRPCServer(("10.0.0.128",8000))
server.register_instance(geop)
print "Starting server..."
server.serve_forever()</pre>
<p><strong>Client:</strong></p>
<pre>#!/usr/bin/python
REMOTE_SERVER = "http://10.0.0.128:8000"
import sys
print "We're running on: ", sys.platform
if sys.platform == "win32":  # We're on win32, call instance of gp object as we normally would.
        print "Importing the geoprocessing object"
        import arcgisscripting as agis
        gp = agis.create()
else:  # Run our calls over XMLRPC to REMOTE_SERVER
        from xmlrpclib import ServerProxy
        print "Using XMLRPC to connect to:", REMOTE_SERVER
        gp = ServerProxy(REMOTE_SERVER)
# Just check that we can call the geoprocessing object.
print gp.ProductInfo() #Show which product we're running just to make sure it is working.</pre>
<p>Use:<br />
On the server run:</p>
<pre>python server.py</pre>
<pre>Starting server...</pre>
<p>On the client call the Client code at the top of your geoprocessing script, then refer to the gp object as you would normally.</p>
]]></content:encoded>
			<wfw:commentRss>http://jduck.net/2007/06/26/quick-and-dirty-gis-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>geopy</title>
		<link>http://jduck.net/2007/05/09/geopy/</link>
		<comments>http://jduck.net/2007/05/09/geopy/#comments</comments>
		<pubDate>Wed, 09 May 2007 15:57:18 +0000</pubDate>
		<dc:creator>Jonah</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[geospatial]]></category>
		<category><![CDATA[gis]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://jduck.net/2007/05/09/geopy/</guid>
		<description><![CDATA[Stumbled upon geopy while looking through a fantastic list of OSS and Linux GIS tools. Geopy lets me code a geocoder in 6 lines of python using the google maps API. Example: #!/usr/bin/python from geopy import geocoders import sys g = geocoders.Google('ENTER YOUR API KEY HERE') address = sys.argv[1] place, (lat,lng) = g.geocode(address) print "%s: [...]]]></description>
			<content:encoded><![CDATA[<p>Stumbled upon <a href="http://exogen.case.edu/projects/geopy/">geopy</a> while looking through a <a href="http://pkg-grass.alioth.debian.org/debiangis-status.html">fantastic list</a> of OSS and Linux GIS tools.</p>
<p>Geopy lets me code a geocoder in 6 lines of python using the google maps API.</p>
<p><span id="more-89"></span><br />
Example:</p>
<pre>
#!/usr/bin/python
from geopy import geocoders
import sys
g = geocoders.Google('ENTER YOUR API KEY HERE')
address = sys.argv[1]
place, (lat,lng) = g.geocode(address)
print "%s: %.5f, %.5f" % (place,lat,lng)
</pre>
<p>Then run from the command line like so:</p>
<pre>
# geoloc "500 Main St. 42367"
500 Main St, Powderly, KY 42367, USA: 37.23329, -87.16244
</pre>
<p>Nice!</p>
]]></content:encoded>
			<wfw:commentRss>http://jduck.net/2007/05/09/geopy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Histogram of an ASCII Raster</title>
		<link>http://jduck.net/2007/03/06/histogram-of-an-ascii-raster/</link>
		<comments>http://jduck.net/2007/03/06/histogram-of-an-ascii-raster/#comments</comments>
		<pubDate>Tue, 06 Mar 2007 21:37:49 +0000</pubDate>
		<dc:creator>Jonah</dc:creator>
				<category><![CDATA[gis]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://jduck.net/2007/03/06/histogram-of-an-ascii-raster/</guid>
		<description><![CDATA[Warning, esoteric GIS related post follows. I often like to be able to generate a quick histogram of an ASCII raster file that I use for some of my models. I can do this inside of ArcGIS on a GRID file, but I like to be able to do this directly on an ASCII sometimes. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Warning, esoteric GIS related post follows.</strong></p>
<p>I often like to be able to generate a quick histogram of an ASCII raster file that I use for some of my models.  I can do this inside of ArcGIS on a GRID file, but I like to be able to do this directly on an ASCII sometimes.  Python to the rescue&#8230;</p>
<p><span id="more-81"></span></p>
<p>In a few lines of python I whipped this up:</p>
<pre>
#!/usr/bin/python
# By Jonah Duckles jonah@purdue.edu 7/17/2006
# Histogram Ascii will take a standard ESRI ascii file and output a histogram
#   of the values found in the file.

import sys, string, os
from operator import *

file = sys.argv[1]
histo = dict()
fh = open(file)
currow = 0
for line in fh.xreadlines():
    if currow > 6:
        line = string.rstrip(line, '/n')
        row = line.split(" ")
        row = row[:len(row)-1]
        for cell in row:
            if cell in histo:
                histo[cell] = histo[cell] + 1
            else:
                histo[cell] = 1
    currow += 1

k = histo.keys()
k.sort()

print "#Histogram for " + file
for element in k:
    print str(element) + "\t" + str(histo[element])
</pre>
<p>Now what if I want to be able to do this directly on a GRID file on Linux with no ArcGIS.  I admit this is a complete hack, but here it is.  A script that calls GDAL bin tools to convert the GRID to ASCII (it does it pretty fast actually), then calls hasc.py above and saves the histogram to a file.</p>
<pre>
#!/bin/bash
tmp=00-$1.asc
out=hist-$1.csv
gdal_translate -of AAIGrid $1 $tmp
echo "Computing histogram"
hasc $tmp > $out
echo "Histogram output to $out"
echo "Cleaning up"
rm $tmp
</pre>
<p><strong>EDIT:</strong> Fixed a minor bug per pyther&#8217;s comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://jduck.net/2007/03/06/histogram-of-an-ascii-raster/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
