<?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>michalisavraam.org blog &#187; data manipulation</title>
	<atom:link href="http://michalisavraam.org/tag/data-manipulation/feed/" rel="self" type="application/rss+xml" />
	<link>http://michalisavraam.org</link>
	<description>a spatial web presence</description>
	<lastBuildDate>Mon, 24 May 2010 17:17:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>What is geoprocessing?</title>
		<link>http://michalisavraam.org/2010/03/what-is-geoprocessing/</link>
		<comments>http://michalisavraam.org/2010/03/what-is-geoprocessing/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 01:25:23 +0000</pubDate>
		<dc:creator>Michalis Avraam</dc:creator>
				<category><![CDATA[ESRI]]></category>
		<category><![CDATA[GIS* Points]]></category>
		<category><![CDATA[Python Geoprocessing]]></category>
		<category><![CDATA[Spatial Data]]></category>
		<category><![CDATA[ArcGIS]]></category>
		<category><![CDATA[data manipulation]]></category>
		<category><![CDATA[geoprocessing]]></category>

		<guid isPermaLink="false">http://michalisavraam.org/?p=279</guid>
		<description><![CDATA[An interesting question came about a few days ago. While I have been discussing ESRI&#8217;s geoprocessor and how one can use it effectively, I failed to define what geoprocessing is,, either within the ESRI realm or the general  GIS realm. In short, geoprocessing is an operation performed on geographic (spatial) data. In other words, it [...]


Related posts:<ol><li><a href='http://michalisavraam.org/2009/10/understanding-the-geoprocessor-programming-model-part/' rel='bookmark' title='Permanent Link: Understanding the Geoprocessor Programming Model part 1'>Understanding the Geoprocessor Programming Model part 1</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>An interesting question came about a few days ago. While I have been discussing ESRI&#8217;s geoprocessor and how one can use it effectively, I failed to define what geoprocessing is,, either within the ESRI realm or the general  GIS realm. In short, geoprocessing is an operation performed on geographic (spatial) data. In other words, it is when one uses data to perform some operations and receiving results. An example would be geocoding. The user provides spatial data (an address), which we geoprocess to identify the output (latitude and longitude). In the ArcGIS world, there are a few methods for geoprocessing:  running commands from the ArcToolbox, the Model Builder, the command line and Python scripting (the one I focus on mostly in this blog).<br />
<span id="more-279"></span><br />
<h2>The ArcToolbox</h2>
<div id="attachment_282" class="wp-caption alignright" style="width: 112px"><a href="http://michalisavraam.org/wp-content/uploads/2010/03/Picture-3.png"><img class="size-medium wp-image-282 " title="The ArcToolbox of ArcGIS 9.3" src="http://michalisavraam.org/wp-content/uploads/2010/03/Picture-3-146x300.png" alt="The ArcToolbox of ArcGIS 9.3" width="102" height="210" /></a><p class="wp-caption-text">The ArcToolbox of ArcGIS 9.3</p></div>
<p>The ArcToolbox is a collection of tools provided by ESRI that achieve a number of geoprocessing operations. They are logically organized in themes based on the functionality, and are available to use without any customization. These operations can be very powerful and achieve great results. As you can see from the image on the right, there is a number of tools available to you to use. Depending on the extensions you have installed, you will see some different results, but the Geocoding Tools we mentioned above are available with any kind of license. To use any of these geoprocessing tools, you simply double-click on its name, and a window will pop up asking you for the required inputs and outputs. Pay attention to all the options available to you, and make use of the help button to clarify what the operation does, and how it is achieved.</p>
<h2>The Model Builder</h2>
<div id="attachment_280" class="wp-caption alignright" style="width: 310px"><a href="http://michalisavraam.org/wp-content/uploads/2010/03/Picture-2.png"><img class="size-medium wp-image-280" title="The Model Builder Window" src="http://michalisavraam.org/wp-content/uploads/2010/03/Picture-2-300x207.png" alt="The Model Builder Window" width="300" height="207" /></a><p class="wp-caption-text">The Model Builder Window</p></div>
<p>The Model Builder is a wonderful program written by ESRI that allows you to graphically define geoprocessing operations. Using a simple tool, a user can drag and drop operations and data on a canvas, and connect them with directional arrows (signifying direction of data). On the example on the right, we follow the Address Geocoding operation. There are three data inputs for the operation, including an address locator, address fields to be used, and finally the input table with the addresses. There is one more data element in the picture, the output feature, on the far right. Note that all data are represented by ovals. The operation, which is in the middle, receives data from all the arrows pointing to it, and returns data to the arrow pointing outwards. Notice that the operation is in a rectangular box rather than an oval, to distinguish it.</p>
<h2>The Command Line</h2>
<div id="attachment_283" class="wp-caption alignright" style="width: 310px"><a href="http://michalisavraam.org/wp-content/uploads/2010/03/Picture-4.png"><img class="size-medium wp-image-283" title="The Command Line Window" src="http://michalisavraam.org/wp-content/uploads/2010/03/Picture-4-300x157.png" alt="The Command Line Window" width="300" height="157" /></a><p class="wp-caption-text">The Command Line Window</p></div>
<p>The command line window is one more way to achieve geoprocessing when one is using ArcGIS. The window simply allows one to type commands, an hit enter to execute them. Some users are more familiar with this interface, and like the speed of which you can type operations. Typing a few letters in the top box will give you a list of all commands starting with those letters. Pressing space will bring the tooltip shown in the top of the image on your right. As you can see, it tells you what the tool expects to run. In this case, it expects an input table (in_table), an address locator (address_locator), the address fields (in_address_fields) and where to save the output (output_feature). Optionally, you can set the out_relation_type (notice the curly braces this time).</p>
<h2>Python Scripting</h2>
<div id="attachment_284" class="wp-caption alignright" style="width: 310px"><a href="http://michalisavraam.org/wp-content/uploads/2010/03/Picture-5.png"><img class="size-medium wp-image-284" title="Python Scripting Geocoding" src="http://michalisavraam.org/wp-content/uploads/2010/03/Picture-5-300x149.png" alt="Python Scripting Geocoding" width="300" height="149" /></a><p class="wp-caption-text">Python Scripting Geocoding</p></div>
<p>The perhaps most complex way to perform geocoding is done through Python scripting. The example on the right actually presents geoprocessing code. What happens when one uses Python Scripting to create geoprocessing operations is similar with the command line option talked about earlier, with some slight changes. Python scripting gives you the option to interact with the data deeper. What this means is that the user can now access an individual point by latitude and longitude. And since all vector spatial data are built from points, this means you have deep access to any spatial data using Python (to see more about Accessing Geometries using the Geoprocessor <a href="http://michalisavraam.org/2009/02/accessing-geometries-using-the-geoprocessor-updated/">click here</a>). Also, as Python is a general use scripting language, you can find reusable code by other users (in the form of modules) to achieve things like reading Excel files (<a href="http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-1-reading-files/">click here</a> for an overview).</p>
<p>And that is what geoprocessing is. Operations that work on spatial data. In the ArcGIS realm, that means either using ArcToolbox, the Model Builder, the Command Line interface or creating your own Python Scripts to achieve your desired results.</p>
Note: There is a rating embedded within this post, please visit this post to rate it.


<p>Related posts:<ol><li><a href='http://michalisavraam.org/2009/10/understanding-the-geoprocessor-programming-model-part/' rel='bookmark' title='Permanent Link: Understanding the Geoprocessor Programming Model part 1'>Understanding the Geoprocessor Programming Model part 1</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://michalisavraam.org/2010/03/what-is-geoprocessing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Manipulating Excel files using Python part 2: Writing Excel Files</title>
		<link>http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-2-writing-files/</link>
		<comments>http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-2-writing-files/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 04:50:18 +0000</pubDate>
		<dc:creator>Michalis Avraam</dc:creator>
				<category><![CDATA[Python Points]]></category>
		<category><![CDATA[data manipulation]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[excel files]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[write]]></category>
		<category><![CDATA[writing]]></category>
		<category><![CDATA[xlwd]]></category>

		<guid isPermaLink="false">http://michalisavraam.org/blog/38-blog-entries/58-writing-excel-files-using-python-no-excel-needed</guid>
		<description><![CDATA[Writing Excel files using Python is quite easy, using the xlwt package. Similar to xlrd mentioned in an earlier post, xlwt allows one to write Excel files from scratch using Python.A brief reminded of Excel files (as mentioned in an earlier post) follows, to help people understand how Excel files work.The program stores data in [...]


Related posts:<ol><li><a href='http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-1-reading-files/' rel='bookmark' title='Permanent Link: Manipulating Excel files using Python part 1: Reading Excel Files'>Manipulating Excel files using Python part 1: Reading Excel Files</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Writing Excel files using Python is quite easy, using the <a title="xwt repository" href="https://secure.simplistix.co.uk/svn/xlwt/trunk/">xlwt package</a>. Similar to <a title="xlrd package" href="http://www.lexicon.net/sjmachin/xlrd.htm">xlrd</a> mentioned in an <a title="Reaing Excel files using Python" href="http://michalisavraam.org/blog/38-blog-entries/57-manipulating-excel-files-in-python-no-excel-needed.html">earlier post</a>, xlwt allows one to write Excel files from scratch using Python.<span id="more-22"></span><img class="alignright size-full wp-image-43" title="excelPreview" src="http://michalisavraam.org/wp-content/uploads/2009/06/excelPreview.png" alt="excelPreview" width="461" height="280" />A brief reminded of Excel files (as mentioned in an earlier post) follows, to help people understand how Excel files work.The program stores data in what is called a <strong>Workbook</strong>. Think of this as the file on your computer (the .xls). A Workbook can then have one or more <strong>Sheets</strong>, the little tabs on the bottom left corner usually. Within each Sheet, you can find an arrangement of <strong>Cells</strong> in a matrix form, which are referenced by Column Name and Row Number (so the top left cell is A1, the one directly to its right is A2, the one below is B2, etc. The image should help shed some light if you are not familiar with the concept of spreadsheets.To create your own Excel files using Python, all you need to have is the xlwt package. The workflow for such a process is simple: create a workbook, create a sheet within the workbook, start writing data into the cells of the sheet. Sample code shown below should help you get started quickly and easily.</p>
<pre style="text-align: left;">
<pre class="brush: python;">
import xlwt # Import the package
wbook = xlwt.Workbook() # Create a new workbook
sheet = wbook.add_sheet(&amp;amp;amp;quot;Sample Sheet&amp;amp;amp;quot;) # Create a sheet
data = &amp;amp;amp;quot;Sample data&amp;amp;amp;quot; # Something to write into the sheet
for rowx in range(5):
# Loop through the first five rows
for colx in range(5):
# Loop through the first five columns
# Write the data to rox, column
sheet.write(rowx, colx, data)
# Save our workbook on the harddrive
wbook.save(&amp;amp;amp;quot;myFile.xls&amp;amp;amp;quot;)</pre>
</pre>
<p>And that is all you need. You just created a brand new Excel file called myFile.xls within Python without the use of Excel itself. The file has the first 5 rows and columns filled out with the text &#8220;Sample data&#8221;. It is trivial then to change this so it can save any data you want with a little bit more of Python.</p>
Note: There is a rating embedded within this post, please visit this post to rate it.


<p>Related posts:<ol><li><a href='http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-1-reading-files/' rel='bookmark' title='Permanent Link: Manipulating Excel files using Python part 1: Reading Excel Files'>Manipulating Excel files using Python part 1: Reading Excel Files</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-2-writing-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Manipulating Excel files using Python part 1: Reading Excel Files</title>
		<link>http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-1-reading-files/</link>
		<comments>http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-1-reading-files/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 05:42:21 +0000</pubDate>
		<dc:creator>Michalis Avraam</dc:creator>
				<category><![CDATA[Python Points]]></category>
		<category><![CDATA[data manipulation]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[excel file]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[read]]></category>
		<category><![CDATA[reading]]></category>
		<category><![CDATA[xlrd]]></category>

		<guid isPermaLink="false">http://michalisavraam.org/blog/38-blog-entries/57-manipulating-excel-files-in-python-no-excel-needed</guid>
		<description><![CDATA[It is often the case that the freely available data online are in Excel format. If one has Excel, then one has the ability to do some sort of basic manipulation of the files. But if Excel is not available, or your analysis software does not read Excel files, there is another way: use Python [...]


Related posts:<ol><li><a href='http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-2-writing-files/' rel='bookmark' title='Permanent Link: Manipulating Excel files using Python part 2: Writing Excel Files'>Manipulating Excel files using Python part 2: Writing Excel Files</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>It is often the case that the freely available data online are in Excel format. If one has Excel, then one has the ability to do some sort of basic manipulation of the files. But if Excel is not available, or your analysis software does not read Excel files, there is another way: use Python to manipulate Excel files.<span id="more-23"></span></p>
<p><img class="alignright size-full wp-image-43" title="excelPreview" src="http://michalisavraam.org/wp-content/uploads/2009/06/excelPreview.png" alt="excelPreview" width="461" height="280" />Before continuing, let&#8217;s discuss the basic idea of Excel. This programs stores data in what is called a <strong>Workbook</strong>. Think of this as the file on your computer (the .xls). A Workbook can then have one or more <strong>Sheets</strong>, the little tabs on the bottom left corner usually. Within each Sheet, you can find an arrangement of <strong>Cells</strong> in a matrix form, which are referenced by Column Name and Row Number (so the top left cell is A1, the one directly to its right is A2, the one below is B2, etc. The image should help shed some light if you are not familiar with the concept of spreadsheets.</p>
<p>In order to <strong>read</strong> Excel sheets in Python without using any Microsoft Office code, we need to use the excellent <a title="xlrd Package Website" href="http://www.lexicon.net/sjmachin/xlrd.htm">xlrd packge</a> by <a title="Lingfo Website" href="http://www.lexicon.net/sjmachin/">Lingfo</a>. The basic workflow is as follows:</p>
<ol>
<li>Open a workbook using <em>book = xlrd.open_workbook(&#8220;filetoread.xls&#8221;)</em></li>
<li>Access a sheet in the workbook using <em>sheet = book.sheet_by_index(0)</em> to open the first sheet, or if you know the name, <em>sheet = book.sheet_by_name(&#8220;Name of Sheet&#8221;)</em></li>
<li>Retrieve data using any of the multiple methods: <em>cellValue =sheet.cell_value(rowx, colx)</em>, or to retrieve a whole column use <em>colValues = sheet.col_values(colx, start_rowx=0, end_rowx=None)</em> or the retrieve a whole row use <em>rowValues = sheet.row_values(rowx, start_colx=0, end_colx=None)</em></li>
</ol>
<p>The basic idea is very simple, and we can easily write a little Python script that will allow us to read Excel files without the need to use Excel itself. The following example will offer a preview of an Excel file&#8217;s first sheet using the first 5 rows and columns of a file.</p>
<pre class="brush: python;">
import xlrd # Import the package
book = xlrd.open_workbook(&amp;amp;amp;quot;sample.xls&amp;amp;amp;quot;) # Open an .xls file
sheet = book.sheet_by_index(0) # Get the first sheet
for counter in range(5): # Loop for five times
# grab the current row
rowValues = sheet.row_values(counter,start_col=0, end_colx=4)
# Print the values of the row formatted to 10 characters wide
print &amp;amp;amp;quot;%-10s | %-10s | %-10s | %-10s | %-10s&amp;amp;amp;quot; % tuple(rowValues)
# Print row separator
print &amp;amp;amp;quot;-&amp;amp;amp;quot; *62
</pre>
<p>That is all there is to it. Quick, fast and no need for Excel whatsoever. Sample output is presented below:</p>
<p><img class="aligncenter size-full wp-image-46" title="sampleOutput" src="http://michalisavraam.org/wp-content/uploads/2009/06/sampleOutput.png" alt="sampleOutput" width="585" height="447" /></p>
Note: There is a rating embedded within this post, please visit this post to rate it.


<p>Related posts:<ol><li><a href='http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-2-writing-files/' rel='bookmark' title='Permanent Link: Manipulating Excel files using Python part 2: Writing Excel Files'>Manipulating Excel files using Python part 2: Writing Excel Files</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://michalisavraam.org/2009/06/manipulating-excel-files-using-python-part-1-reading-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
