<?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>Spatial Galaxy &#187; Python</title>
	<atom:link href="http://spatialgalaxy.net/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://spatialgalaxy.net</link>
	<description>Exploring the Realms of GIS</description>
	<lastBuildDate>Mon, 30 Jan 2012 02:24:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Script Runner: A Plugin to Run Python Scripts in QGIS</title>
		<link>http://spatialgalaxy.net/2012/01/29/script-runner-a-plugin-to-run-python-scripts-in-qgis/</link>
		<comments>http://spatialgalaxy.net/2012/01/29/script-runner-a-plugin-to-run-python-scripts-in-qgis/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 02:24:34 +0000</pubDate>
		<dc:creator>Gary Sherman</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Quantum GIS]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[qgis]]></category>

		<guid isPermaLink="false">http://spatialgalaxy.net/?p=807</guid>
		<description><![CDATA[Following up on my last post, Running Scripts in the Python Console, I created a plugin to simplify running scripts: The Script Runner plugin allows you to add your scripts to a list so they are readily available. You can then run them to automate QGIS tasks and have full access to the PyQGIS API. In addition, you can view information about the classes, methods, and functions in your module as well as browse the source: In order for your script to work with ScriptRunner it has to implement a single function as an entry point. Here is some additional information from the Help tab of the plugin: Requirements In order for Script Runner to execute your script you must define a run_script function that accepts a single argument. This is the standard entry point used by Script Runner. A reference to the qgis.utils.iface object will be passed to your run_script function. You don&#8217;t have to use the iface object in your script but your run_script function must accept it as an argument. Here is an example of a simple run_script function: def run_script&#40;iface&#41;: ldr = Loader&#40;iface&#41; ldr.load_shapefiles&#40;'/vmap0_shapefiles'&#41; In this example, the run_script creates an instance (ldr) of a class [...]]]></description>
			<content:encoded><![CDATA[<p>Following up on my last post, <a href="http://spatialgalaxy.net/2012/01/27/qgis-running-scripts-in-the-python-console/" title="QGIS: Running Scripts in the Python Console"><em>Running Scripts in the Python Console</em></a>, I created a plugin to simplify running scripts:</p>
<p><a href="http://spatialgalaxy.net/2012/01/29/script-runner-a-plugin-to-run-python-scripts-in-qgis/script_runner1/" rel="attachment wp-att-808"><img src="http://spatialgalaxy.net/wp-content/script_runner1.png" alt="" title="script_runner1" width="714" height="558" class="aligncenter size-full wp-image-808" /></a></p>
<p>The <em>Script Runner</em> plugin allows you to add your scripts to a list so they are readily available. You can then run them to automate QGIS tasks and have full access to the PyQGIS API. In addition, you can view information about the classes, methods, and functions in your module as well as browse the source:</p>
<p><a href="http://spatialgalaxy.net/2012/01/29/script-runner-a-plugin-to-run-python-scripts-in-qgis/script_runner2/" rel="attachment wp-att-817"><img src="http://spatialgalaxy.net/wp-content/script_runner2.png" alt="" title="script_runner2" width="714" height="558" class="aligncenter size-full wp-image-817" /></a></p>
<p>In order for your script to work with ScriptRunner it has to implement a single function as an entry point. Here is some additional information from the Help tab of the plugin:</p>
<h3>Requirements</h3>
<p>
    In order for Script Runner to execute your script you must define a <em>run_script</em> function that accepts a single argument. This is the standard entry point used by Script Runner. A reference to the qgis.utils.iface object will be passed to your <em>run_script</em> function.  You don&#8217;t have to use the iface object in your script but your <em>run_script</em> function must accept it as an argument.
    </p>
<p>
   Here is an example of a simple <em>run_script</em> function:
   </p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">    <span style="color: #ff7700;font-weight:bold;">def</span> run_script<span style="color: black;">&#40;</span>iface<span style="color: black;">&#41;</span>:
        ldr = Loader<span style="color: black;">&#40;</span>iface<span style="color: black;">&#41;</span>
        ldr.<span style="color: black;">load_shapefiles</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/vmap0_shapefiles'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>
   In this example, the <em>run_script</em> creates an instance (ldr) of a class named Loader that is defined in the same source file. It then calls a method in the Loader class named load_shapefiles to do something useful&#8212;in this case, load all the shapefiles in a specified directory.
   </p>
<p>
   Alternatively, you could choose not to use classes and just do everything within the <em>run_script</em> function, including having it call functions in the same script or others you might import. The important thing is to be sure you have defined a <em>run_script</em> function. If not, Script Runner won&#8217;t load your script.
   </p>
<h3>Working with Scripts</h3>
<p>
   To run a script, you must add it to Script Runner using the <em>Add Script</em> tool on the toolbar. This will add it to a list in the left panel. This list of scripts is persisted between uses of QGIS. You can remove a script using the <em>Remove Script</em> tool. This just removes it from the list; it does nothing to the script file on disk.
   </p>
<p>
   Once you have a script loaded, you can click the <em>Script Info</em> tool to populate the Info and Source tabs in the panel on the right. The Info tab contains the docstring from your module and then a list of the classes, methods, and functions found in the script. Having a proper docstring at the head of your script will help you determine the puprose of script.  </p>
<p>
   You can view the source of the script on the Source tab. This allows you to quickly confirm that you are using the right script and it does what you think it will.
   </p>
<h3>Installing the Plugin</h3>
<p>To install the plugin:</p>
<ol>
<li>Open the Python plugin installer: Plugins->Fetch Python Plugins</li>
<li>Check to see if you have the new Official repository in your list of plugins by clicking on  <em>Repositories</em> tab. The URL is http://plugins.qgis.org/plugins/plugins.xml.</li>
<li>If you have it, skip to step 5. If the new repository isn&#8217;t in the list, add it by clicking the Add button. Give it a name and insert the URL http://plugins.qgis.org/plugins/plugins.xml</li>
<li>Click on the <em>Plugins</em> tab</li>
<li>Enter scriptrunner in the Filter box</li>
<li>Select the ScriptRunner plugin and click Install</li>
</ol>
<p>ScriptRunner adds an entry to the Plugins menu as well as a tool on the Plugins toolbar: <img src="http://spatialgalaxy.net/wp-content/icon.png" alt="" title="icon" width="32" height="32" align="absmiddle" size-full wp-image-844" />. Click it and you are off and running.</p>
]]></content:encoded>
			<wfw:commentRss>http://spatialgalaxy.net/2012/01/29/script-runner-a-plugin-to-run-python-scripts-in-qgis/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>QGIS: Running Scripts in the Python Console</title>
		<link>http://spatialgalaxy.net/2012/01/27/qgis-running-scripts-in-the-python-console/</link>
		<comments>http://spatialgalaxy.net/2012/01/27/qgis-running-scripts-in-the-python-console/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 17:10:51 +0000</pubDate>
		<dc:creator>Gary Sherman</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Quantum GIS]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[qgis]]></category>

		<guid isPermaLink="false">http://spatialgalaxy.net/?p=709</guid>
		<description><![CDATA[The QGIS Python console is great for doing one-off tasks or experimenting with the API. Sometimes you might want to automate a task using a script, and do it without writing a full blown plugin. Currently QGIS does not have a way to load an arbitrary Python script and run it1. Until it does, this post illustrates a way you can create a script and run it from the console. There are a couple of requirements to run a script in the console: The script must be in your PYTHONPATH Just like a QGIS plugin, the script needs a reference to qgis.utils.iface Setting up the Environment By default, the Python path includes the .qgis/python directory. The location depends on your platform: Windows: in your home directory under .qgis\python. For example, C:\Documents and Settings\gsherman\.qgis\python Linux and OS X: $HOME/.qgis/python To see what is in your PYTHONPATH you can do the following in QGIS Python console: import sys sys.path While you could use the .qgis\python directory for your custom scripts, a better way is to create a directory specifically for that purpose and add that directory to the PYTHONPATH environment variable. On Windows you can do this using the Environment Variables page [...]]]></description>
			<content:encoded><![CDATA[<p>The QGIS Python console is great for doing one-off tasks or experimenting with the API. Sometimes you might want to automate a task using a script, and do it without writing a full blown plugin. Currently QGIS does not have a way to load an arbitrary Python script and run it<sup><b><a href="#fn1">1</a></b></sup>. Until it does, this post illustrates a way you can create a script and run it from the console.</p>
<p>There are a couple of requirements to run a script in the console:</p>
<ol>
<li>The script must be in your PYTHONPATH</li>
<li>Just like a QGIS plugin, the script needs a reference to <em>qgis.utils.iface</em></li>
</ol>
<h3>Setting up the Environment</h3>
<p>By default, the Python path includes the <em>.qgis/python</em> directory. The location depends on your platform:</p>
<ul>
<li>Windows: in your home directory under .qgis\python. For example, C:\Documents and Settings\gsherman\.qgis\python</li>
<li>Linux and OS X: $HOME/.qgis/python</li>
</ul>
<p>To see what is in your PYTHONPATH you can do the following in QGIS Python console:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span></pre></div></div>

<p>While you could use the <em>.qgis\python</em> directory for your custom scripts, a better way is to create a directory specifically for that purpose and add that directory to the PYTHONPATH environment variable. On Windows you can do this using the <em>Environment Variables</em> page in your system properties:</p>
<p><a href="http://spatialgalaxy.net/2012/01/27/qgis-running-scripts-in-the-python-console/python_path_win/" rel="attachment wp-att-726"><img src="http://spatialgalaxy.net/wp-content/python_path_win.png" alt="" title="python_path_win" width="384" height="430" class="aligncenter size-full wp-image-726" /></a></p>
<p>On Linux or OS X, you can add it to your <em>.bash_profile</em>, <em>.profile</em>, or other login script in your home directory:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">export PYTHONPATH=$PYTHONPATH:/home/gsherman/qgis_scripts</pre></div></div>

<h3>Writing the Script</h3>
<p>With the environment set, we can create scripts to automate QGIS tasks and run them from the console. For this example, we will use a simple script to load all shapefiles in a specified directory. There are a couple of ways to do this:</p>
<ol>
<li>Write a simple script with a function that accepts <em>qgis.utils.iface</em> as an argument, along with a path to the shapefiles</li>
<li>Create a Python class that uses an __init__ method to store a reference to the <em>iface</em> object and then add methods to do the work</li>
</ol>
<p>We will use the latter approach because it is more flexible and allows us to initialize once and then call methods without having to pass the <em>iface</em> object each time.</p>
<p>The script looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env Python</span>
<span style="color: #483d8b;">&quot;&quot;&quot;Load all shapefiles in a given directory.
  This script (loader.py) runs from the QGIS Python console.
  From the console, use:
    from loader import Loader
    ldr = Loader(qgis.utils.iface)
    ldr.load_shapefiles('/my/path/to/shapefile/directory')
&nbsp;
  &quot;&quot;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">glob</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">glob</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">os</span> <span style="color: #ff7700;font-weight:bold;">import</span> path
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Loader:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, iface<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;Initialize using the qgis.utils.iface 
        object passed from the console.
&nbsp;
        &quot;&quot;&quot;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">iface</span> = iface
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> load_shapefiles<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, shp_path<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;Load all shapefiles found in shp_path&quot;&quot;&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Loading shapes from %s&quot;</span> <span style="color: #66cc66;">%</span> path.<span style="color: black;">join</span><span style="color: black;">&#40;</span>shp_path, <span style="color: #483d8b;">&quot;*.shp&quot;</span><span style="color: black;">&#41;</span>
        shps = <span style="color: #dc143c;">glob</span><span style="color: black;">&#40;</span>path.<span style="color: black;">join</span><span style="color: black;">&#40;</span>shp_path, <span style="color: #483d8b;">&quot;*.shp&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> shp <span style="color: #ff7700;font-weight:bold;">in</span> shps:
            <span style="color: black;">&#40;</span>shpdir, shpfile<span style="color: black;">&#41;</span> = path.<span style="color: black;">split</span><span style="color: black;">&#40;</span>shp<span style="color: black;">&#41;</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">iface</span>.<span style="color: black;">addVectorLayer</span><span style="color: black;">&#40;</span>shp, shpfile, <span style="color: #483d8b;">'ogr'</span> <span style="color: black;">&#41;</span></pre></div></div>

<h3>Running the Script</h3>
<p>To open the console use the <em>Plugins->Python Console</em> menu item.</p>
<p>The comment at the head of the script explains how to use it.</p>
<p>First we import the <em>Loader</em> class from the script file (named loader.py). This script resides in the qgis_scripts directory that is our PYTHONPATH.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> loader <span style="color: #ff7700;font-weight:bold;">import</span> Loader</pre></div></div>

<p>We then create an instance of <em>Loader</em>, passing it the reference to the <em>iface</em> object:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">ldr = Loader<span style="color: black;">&#40;</span>qgis.<span style="color: black;">utils</span>.<span style="color: black;">iface</span><span style="color: black;">&#41;</span></pre></div></div>

<p>This creates the <em>Loader</em> object and calls the __init__ method to initialize things.</p>
<p>Once we have an instance of <em>Loader</em> we can load all the shapefiles in a directory by calling the <em>load_shapefiles</em> method, passing it the full path to the directory containing the shapefiles:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">ldr.<span style="color: black;">load_shapefiles</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/home/gsherman/qgis_sample_data/vmap0_shapefiles'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>The <em>load_shapefiles</em> method uses the path to get a list of all the shapefiles and then adds them to QGIS using <em>addVectorLayer</em>.</p>
<p>Here is the result, rendered in the random colors and order that the shapefiles were loaded:</p>
<p><a href="http://spatialgalaxy.net/2012/01/27/qgis-running-scripts-in-the-python-console/console_loading_of_shps/" rel="attachment wp-att-796"><img src="http://spatialgalaxy.net/wp-content/console_loading_of_shps-1024x720.png" alt="" title="console_loading_of_shps" width="779" height="547" class="aligncenter size-large wp-image-796" /></a></p>
<h3>Some Notes</h3>
<ul>
<li>When testing a script in the console you may need to reload it as you make changes. This can be done using <em>reload</em> and the name of the module. In our example, <em>reload(loader)</em> does the trick.</li>
<li>You can add more methods to your class to do additional tasks</li>
<li>You can create a &#8220;driver&#8221; script that accepts the <em>iface</em> object and then initializes additional classes to do more complex tasks</li>
</ul>
<p><font size="-1"><a name="fn1"><b>1</b></a>. I have plans on the drawing board to implement this feature.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://spatialgalaxy.net/2012/01/27/qgis-running-scripts-in-the-python-console/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>QGIS Plugin of the Week: OpenLayers</title>
		<link>http://spatialgalaxy.net/2012/01/14/qgis-plugin-of-the-week-openlayers/</link>
		<comments>http://spatialgalaxy.net/2012/01/14/qgis-plugin-of-the-week-openlayers/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 17:28:14 +0000</pubDate>
		<dc:creator>Gary Sherman</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Quantum GIS]]></category>
		<category><![CDATA[openlayers]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[qgis]]></category>

		<guid isPermaLink="false">http://spatialgalaxy.net/?p=594</guid>
		<description><![CDATA[This week we look at the OpenLayers plugin for QGIS. This plugin allows you to add a number of image services to your map canvas: Google Physical Streets Hybrid Satellite OpenStreetMap Yahoo Street Hybrid Satellite Bing Road Aerial Aerial with labels Installing the Plugin The OpenLayers plugin is installed like all other Python plugins. From the the Plugins menu in QGIS, choose Fetch Python Plugins. This brings up the plugin installer. To find the plugin, enter openlayers in the Filter box, then select OpenLayers Plugin from the list. Once it’s highlighted, click the Install plugin button. This will download the plugin from the repository, install it, and load it into QGIS. Using the Plugin The OpenLayers Plugin uses your view extent to fetch the data from the service you choose. For this reason you should load at least one of your own layers first. Since each of the services are expecting a request in latitude/longitude your layer either has to be geographic or you must enable on the fly projection. To add one of the services you have two choices; you can pick the service from the Plugins->OpenLayers plugin menu or you can use the OpenLayers Overview. The Overview opens [...]]]></description>
			<content:encoded><![CDATA[<p>This week we look at the <a href="http://hub.qgis.org/projects/openlayers">OpenLayers plugin</a> for QGIS. This plugin allows you to add a number of image services to your map canvas:</p>
<ul>
<li>Google</li>
<ul>
<li>Physical</li>
<li>Streets</li>
<li>Hybrid</li>
<li>Satellite</li>
</ul>
<li>OpenStreetMap</li>
<li>Yahoo</li>
<ul>
<li>Street</li>
<li>Hybrid</li>
<li>Satellite</li>
</ul>
<li>Bing</li>
<ul>
<li>Road</li>
<li>Aerial</li>
<li>Aerial with labels</li>
</ul>
</ul>
<p><span id="more-594"></span></p>
<h3>Installing the Plugin</h3>
<p>The OpenLayers plugin is installed like all other Python plugins. From the the Plugins menu in QGIS, choose Fetch Python Plugins. This brings up the plugin installer. To find the plugin, enter openlayers in the Filter box, then select <i>OpenLayers Plugin</i> from the list. Once it’s highlighted, click the Install plugin button. This will download the plugin from the repository, install it, and load it into QGIS.</p>
<h3>Using the Plugin</h3>
<p>The OpenLayers Plugin uses your view extent to fetch the data from the service you choose. For this reason you should load at least one of your own layers first. Since each of the services are expecting a request in latitude/longitude your layer either has to be geographic or you must enable on the fly projection.</p>
<p>To add one of the services you have two choices; you can pick the service from the <em>Plugins->OpenLayers plugin</em> menu or you can use the <em>OpenLayers Overview</em>. The Overview opens a new panel that allows you to choose a service from a drop-down list. Click the <em>Enable map</em> checkbox to enable the drop-down list and preview the service you want to add. If you are happy with what you see, you can add it to the map by clicking the <em>Add map</em> button.</p>
<p>In the screenshot below we have enabled the Overview panel, added the world boundaries layer<sup><strong><a href="#world_borders">1</a></strong></sup>, zoomed to an area of interest, and added the Google terrain (physical) data:</p>
<p><a href="http://spatialgalaxy.net/2012/01/14/qgis-plugin-of-the-week-openlayers/openlayers_plugin/" rel="attachment wp-att-606"><img src="http://spatialgalaxy.net/wp-content/openlayers_plugin-1024x720.png" alt="" title="openlayers_plugin" width="779" height="547" class="aligncenter size-large wp-image-606" /></a></p>
<p>You can add as many services as you want, previewing them using the OpenLayers Overview panel.</p>
<p><a name="world_borders"><sup>1</sup></a> You can get the world boundaries layer from the <a href="http://geospatialdesktop.com/data">Geospatial Desktop</a> sample data set.</p>
]]></content:encoded>
			<wfw:commentRss>http://spatialgalaxy.net/2012/01/14/qgis-plugin-of-the-week-openlayers/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>QGIS Plugin of the Week: Profile</title>
		<link>http://spatialgalaxy.net/2012/01/06/qgis-plugin-of-the-week-profile/</link>
		<comments>http://spatialgalaxy.net/2012/01/06/qgis-plugin-of-the-week-profile/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 18:58:07 +0000</pubDate>
		<dc:creator>Gary Sherman</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Quantum GIS]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[qgis]]></category>

		<guid isPermaLink="false">http://spatialgalaxy.net/?p=535</guid>
		<description><![CDATA[This week we take a look at a how to plot a terrain profile using the Profile plugin. The plugin can be used with any raster format supported by QGIS. You can can display profiles from up to three rasters at once, allowing you to compare the results. To illustrate, we&#8217;ll create a simple profile using a DEM of a 1:63,360 quadrangle in Alaska. Installing the Plugin The Profile plugin is installed like all other Python plugins. From the the Plugins menu in QGIS, choose Fetch Python Plugins. This brings up the plugin installer. To find the plugin, enter profile in the Filter box, then select Profile from the list. Once it&#8217;s highlighted, click the Install plugin button. This will download the plugin from the repository, install it, and load it into QGIS.1 Using the Plugin Here we have loaded the DEM as well as a raster (DRG) of the topography for the same quadrangle and zoomed in a bit to an area of interest: The yellow line has been added to indicate where we will take the profile. While the Profile plugin allows you to interactively select the profile line it doesn&#8217;t display the line on the map. To [...]]]></description>
			<content:encoded><![CDATA[<p>This week we take a look at a how to plot a terrain profile using the Profile plugin. The plugin can be used with any raster format supported by QGIS. You can can display profiles from up to three rasters at once, allowing you to compare the results. To illustrate, we&#8217;ll create a simple profile using a DEM of a 1:63,360 quadrangle in Alaska.</p>
<p><span id="more-535"></span></p>
<h3>Installing the Plugin</h3>
<p>The Profile plugin is installed like all other Python plugins. From the the Plugins menu in QGIS, choose Fetch Python Plugins. This brings up the plugin installer. To find the plugin, enter <em>profile</em> in the Filter box, then select Profile from the list. Once it&#8217;s highlighted, click the <em>Install plugin</em> button. This will download the plugin from the repository, install it, and load it into QGIS.<sup><font size=-2><a href="#dependency">1</a></font></sup></p>
<h3>Using the Plugin</h3>
<p>Here we have loaded the DEM as well as a raster (DRG) of the topography for the same quadrangle and zoomed in a bit to an area of interest:</p>
<p><a href="http://spatialgalaxy.net/2012/01/06/qgis-plugin-of-the-week-profile/qgis_profile_data-2/" rel="attachment wp-att-541"><img src="http://spatialgalaxy.net/wp-content/qgis_profile_data1.png" alt="" title="qgis_profile_data" width="849" height="633" class="aligncenter size-full wp-image-541" /></a></p>
<p>The yellow line has been added to indicate where we will take the profile. While the Profile plugin allows you to interactively select the profile line it doesn&#8217;t display the line on the map.</p>
<p>To create a profile, first make sure the raster you want to profile is selected in the layer list, then activate the plugin from the Plugins toolbar by clicking on it. The cursor becomes a cross that you use to create the profile line: click at the start point, move to the end and click again. Once you have created the profile line, the plugin pops up the result:</p>
<p><a href="http://spatialgalaxy.net/2012/01/06/qgis-plugin-of-the-week-profile/qgis_profile_result1/" rel="attachment wp-att-546"><img src="http://spatialgalaxy.net/wp-content/qgis_profile_result1.png" alt="" title="qgis_profile_result1" width="726" height="457" class="aligncenter size-full wp-image-546" /></a></p>
<p>The profile is taken from the northeast towards the southwest, based on where we clicked first. You can change the exaggeration of the profile by using the slider on the left. The X axis shows the distance along the profile line in map units and the Y axis shows the cell values from the raster&#8212;in this case, elevation in meters.</p>
<p>You can save the result as a PDF or SVG using the buttons at the bottom of the dialog. </p>
<p>The Statistics tab displays some information for the raster layer and the profile line:</p>
<p><a href="http://spatialgalaxy.net/2012/01/06/qgis-plugin-of-the-week-profile/qgis_profile_statistics/" rel="attachment wp-att-551"><img src="http://spatialgalaxy.net/wp-content/qgis_profile_statistics.png" alt="" title="qgis_profile_statistics" width="726" height="457" class="aligncenter size-full wp-image-551" /></a></p>
<p>If we had additional rasters loaded, we could use the Setup tab to add them to the profile analysis. This would display the results using the colors specified for each layer and we could compare them on the Profile tab. </p>
<p><a href="http://spatialgalaxy.net/2012/01/06/qgis-plugin-of-the-week-profile/qgis_profile_setup/" rel="attachment wp-att-572"><img src="http://spatialgalaxy.net/wp-content/qgis_profile_setup.png" alt="" title="qgis_profile_setup" width="726" height="457" class="aligncenter size-full wp-image-572" /></a></p>
<p>This is just one of several QGIS plugins that deal with profiles. You can check out the rest of them using the Python Plugin installer.</p>
<p><a name="dependency">1</a><font size=-1> The Profile plugin requires the Python module for QWT5. If you don&#8217;t have this installed, a warning will be displayed during the installation process.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://spatialgalaxy.net/2012/01/06/qgis-plugin-of-the-week-profile/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>QGIS Plugin of the Week: Points to Paths</title>
		<link>http://spatialgalaxy.net/2011/12/30/qgis-plugin-of-the-week-points-to-paths/</link>
		<comments>http://spatialgalaxy.net/2011/12/30/qgis-plugin-of-the-week-points-to-paths/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 18:43:58 +0000</pubDate>
		<dc:creator>Gary Sherman</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Quantum GIS]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tracking]]></category>

		<guid isPermaLink="false">http://spatialgalaxy.net/?p=480</guid>
		<description><![CDATA[This week we highlight the Points to Paths plugin, a handy way to convert a series of points into line features. This plugin lets you &#8220;connect the dots&#8221; based on an common attribute and a sequence field. The attribute field determines which points should be grouped together into a line. The sequence field determines the order in which the points will connected. The output from this plugin is a shapefile. Let&#8217;s take a look at some example data. Here we have some fictional wildlife tracking data for two moose. The tracking data is in shapefile format, but you can use any vector format supported by QGIS. The tracking data is symbolized by our two animals: Moose1 and Moose2: The moose_tracks layer has an animal tracking id field (animal_tid) and a sequence field (id). This is all we need to convert the individual observations into a line feature that represents the animals path. Installing the Plugin The Points to Paths plugin is installed like all other Python plugins. From the the Plugins menu in QGIS, choose Fetch Python Plugins. This brings up the plugin installer. To find the plugin, enter points to in the Filter box, then select Points to Paths [...]]]></description>
			<content:encoded><![CDATA[<p>This week we highlight the <em>Points to Paths</em> plugin, a handy way to convert a series of points into line features. This plugin lets you &#8220;connect the dots&#8221; based on an common attribute and a sequence field. The attribute field determines which points should be grouped together into a line. The sequence field determines the order in which the points will connected. The output from this plugin is a shapefile.</p>
<p><span id="more-480"></span></p>
<p>Let&#8217;s take a look at some example data. Here we have some fictional wildlife tracking data for two moose. The tracking data is in shapefile format, but you can use any vector format supported by QGIS. The tracking data is symbolized by our two animals: Moose1 and Moose2:</p>
<p><a href="http://spatialgalaxy.net/2011/12/30/qgis-plugin-of-the-week-points-to-paths/moose_tracks_points/" rel="attachment wp-att-481"><img src="http://spatialgalaxy.net/wp-content/moose_tracks_points.png" alt="" title="moose_tracks_points" width="879" height="638" class="aligncenter size-full wp-image-481" /></a></p>
<p>The <em>moose_tracks</em> layer has an animal tracking id field (animal_tid) and a sequence field (id). This is all we need to convert the individual observations into a line feature that represents the animals path.</p>
<h3>Installing the Plugin</h3>
<p>The Points to Paths plugin is installed like all other Python plugins. From the the Plugins menu in QGIS, choose Fetch Python Plugins. This brings up the plugin installer. To find the plugin, enter <em>points to</em> in the Filter box, then select Points to Paths from the list. Once it&#8217;s highlighted, click the <em>Install plugin</em> button. This will download the plugin from the repository, install it, and load it into QGIS.</p>
<h3>Using the Plugin</h3>
<p>Let&#8217;s convert the tracking data to paths. To get started, choose Plugins->Points to Paths from the menu or click on the Points to Paths tool on the Plugin toolbar. This brings up the PointsToPaths dialog box where we specify the paramaters needed to create the paths. Below is the completed dialog for our moose tracks:</p>
<p><a href="http://spatialgalaxy.net/2011/12/30/qgis-plugin-of-the-week-points-to-paths/moose_tracks_dialog/" rel="attachment wp-att-494"><img src="http://spatialgalaxy.net/wp-content/moose_tracks_dialog.png" alt="" title="moose_tracks_dialog" width="421" height="490" class="aligncenter size-full wp-image-494" /></a></p>
<p>The first drop-down box contains a list of the vector layers loaded in QGIS&#8212;in our case we have just one: <em>moose_tracks</em>. For the group field drop-down we chose the field that contains the tracking identifier for each animal. This determines which points will be selected and grouped to form an individual line. The point order field drop-down specifies the field that contains the ordering for the observations. In this case, the id field is incremented with each observation and can be used to construct the paths. We don&#8217;t have a date/time field in this data, but your observations may be sequenced in this way. The Python date format field allows you to specify a format string so the plugin can determine how to sequence your points based on date/time.</p>
<p>The last thing we need to specify is the output shapefile. You can do this by typing in the full path to a new shapefile or by using the Browse button.</p>
<p>With these options set, clicking the OK button will create the new shapefile containing the paths created from our point observations. Once the shapefile is created, the plugin gives you the option to add the new shapefile directly to QGIS. </p>
<h3>The Result</h3>
<p>The result of our simple example are shown below:</p>
<p><a href="http://spatialgalaxy.net/2011/12/30/qgis-plugin-of-the-week-points-to-paths/moose_tracks_result/" rel="attachment wp-att-499"><img src="http://spatialgalaxy.net/wp-content/moose_tracks_result.png" alt="" title="moose_tracks_result" width="879" height="638" class="aligncenter size-full wp-image-499" /></a></p>
<p>We symbolized the individual tracks using the Categorized renderer on the Style tab of the vector properties dialog. You can see we now have a track for each animal. The attribute table created by the plugin contains the following fields:</p>
<ul>
<li>group &#8211; the name of the animal taken from the field we chose as the group field</li>
<li>begin &#8211; the value of the first point order field used to create the path</li>
<li>end &#8211; the value of the last point order field used to create the path</li>
</ul>
<p>In our data, <em>group</em> contains the animal name, <em>begin</em> the value of the lowest id field for animal, and <em>end</em> contains the greatest id value. In a more typical data set, begin and end would contain the start and end date/time values for the observation. Labeling the observation points with our sequence field or date/time values would allow us to determine the direction of movement.</p>
<p>If you have point data that represent a movement of an object, this plugin is a great way to convert it into a path that can be used for visualization, analysis, or map composition.</p>
]]></content:encoded>
			<wfw:commentRss>http://spatialgalaxy.net/2011/12/30/qgis-plugin-of-the-week-points-to-paths/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>QGIS Plugin of the Week: Time Manager</title>
		<link>http://spatialgalaxy.net/2011/12/23/qgis-plugin-of-the-week-time-manager/</link>
		<comments>http://spatialgalaxy.net/2011/12/23/qgis-plugin-of-the-week-time-manager/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 19:26:26 +0000</pubDate>
		<dc:creator>Gary Sherman</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Quantum GIS]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[qgis]]></category>

		<guid isPermaLink="false">http://spatialgalaxy.net/?p=434</guid>
		<description><![CDATA[QGIS has a lot of plugins, including over 180 that have been contributed by users. If you aren&#8217;t using plugins, you are missing out on a lot that QGIS has to offer. I&#8217;m starting what I hope to be a regular feature: Plugin of the Week. This week we&#8217;ll take a look at Time Manager. Time Manager lets you browse spatial data that has a temporal component. Essentially this includes anything that changes location through time. Examples include: Wildlife tracking Vehicles Storm centers QGIS users Data Preparation Expanding on our last post about QGIS Users Around the World, we&#8217;ll use Time Manager to watch access to the QGIS Python plugin repository through time. If you refer to the previous post, you&#8217;ll see that all the IP addresses contacting the repository were extracted from the web server log and geocoded to get the approximate geographic coordinates. To use Time Manager all we need is the time for each access to the repository. A important part (for our purpose) of the web server log entry looks like this: 66.58.228.196 - - [23/Oct/2011:21:17:54 +0000] "GET /repo/contributed HTTP/1.1" 200 256 Time Manager supports date/time in the following formats: YYYY-MM-DD HH:MM:SS YYYY-MM-DD HH:MM YYYY-MM-DD As [...]]]></description>
			<content:encoded><![CDATA[<p>QGIS has a lot of plugins, including over 180 that have been contributed by users. If you aren&#8217;t using plugins, you are missing out on a lot that QGIS has to offer. I&#8217;m starting what I hope to be a regular feature: <em>Plugin of the Week</em>. This week we&#8217;ll take a look at <a href="http://www.geofrogger.net/trac/wiki">Time Manager</a>.</p>
<p><span id="more-434"></span><br />
<a href="http://spatialgalaxy.net/2011/12/23/qgis-plugin-of-the-week-time-manager/time_manager_pyqgis-3/" rel="attachment wp-att-454"><img src="http://spatialgalaxy.net/wp-content/time_manager_pyqgis2-1024x591.png" alt="Time Manger and QGIS Users" title="time_manager_pyqgis" width="779" height="449" class="aligncenter size-large wp-image-454" /></a><br />
Time Manager lets you browse spatial data that has a temporal component. Essentially this includes anything that changes location through time. Examples include:</p>
<ul>
<li>Wildlife tracking</li>
<li>Vehicles</li>
<li>Storm centers</li>
<li>QGIS users</li>
</ul>
<h3>Data Preparation</h3>
<p>Expanding on our last post about <a href="http://spatialgalaxy.net/2011/12/19/qgis-users-around-the-world/">QGIS Users Around the World</a>, we&#8217;ll use Time Manager to watch access to the QGIS Python plugin repository through time. If you refer to the previous post, you&#8217;ll see that all the IP addresses contacting the repository were extracted from the web server log and geocoded to get the approximate geographic coordinates. To use Time Manager all we need is the time for each access to the repository.</p>
<p>A important part (for our purpose) of the web server log entry looks like this:</p>
<p><code>66.58.228.196 - - [23/Oct/2011:21:17:54 +0000] "GET /repo/contributed HTTP/1.1" 200 256 </code></p>
<p>Time Manager supports date/time in the following formats:</p>
<ul>
<li>YYYY-MM-DD HH:MM:SS</li>
<li>YYYY-MM-DD HH:MM</li>
<li>YYYY-MM-DD</li>
</ul>
<p>As you can see, this doesn&#8217;t work with the format in the web server log. </p>
<p>The geocoding process created a file containing IP address, country, city (where available), latitude and longitude. This file is used to create a Python dictionary to look up locations by IP address. Using this file and a bit of Python, the web server log entries were converted into a CSV file containing:</p>
<p><code>ip,date_time,country,latitude,longitude<br />
66.58.228.196,2011-10-23 21:13:53,United States,61.2149,-149.258<br />
66.58.228.196,2011-10-23 21:14:22,United States,61.2149,-149.258<br />
66.58.228.196,2011-10-23 21:17:54,United States,61.2149,-149.258<br />
66.58.228.196,2011-10-23 21:18:04,United States,61.2149,-149.258<br />
...<br />
</code></p>
<p>The CSV file was first converted to a shapefile using the QGIS Delimited Text plugin. Performance with Time Manager was somewhat slow using a shapefile containing 134,171 locations. The shapefile was imported into a SpatiaLite database (you can do this using ogr2ogr or the SpatiaLite GUI).</p>
<h2>Using Time Manager</h2>
<p>To display the progression of access to the repository (and thus users of QGIS), we first have to have the Time Manager plugin installed.<a href="#install"><sup>[1]</sup></a> Once installed, we enable it using the Plugin Manger. </p>
<p>As you can see from the screenshot above, Time Manager installs a new panel in QGIS that sits below the map canvas. You can set a number of options by clicking Settings; the most important being the layer to use in the visualization. For the QGIS users, we use the <em>time_manager_req</em> layer that was created from the web server logs. With the location and date/time data in the proper format, you can click the &#8220;Play&#8221; button to start the display. For each time interval, the plugin selects the appropriate entries and displays a frame for the duration specified in the settings.</p>
<p>You can use the time slider to move around or move the time interval forward or backward using the buttons on each end of the slider. </p>
<p>A really nice feature is the ability to export to video. At present this saves a PNG file and world file for each time interval. You can then use another software package to combine these to create a video animation of the time sequence. Once solution is to use <em>mencoder</em><sup><a href="#install">[1]</a></sup>:</p>
<p><code>mencoder "mf://*.PNG" -mf fps=10 -o output.avi -ovc lavc -lavcopts vcodec=mpeg4</code></p>
<p>Putting all this together gives us the following visualization of QGIS user activity from October 23 through December 19, 2011:</p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/iwJImIhYyxQ" frameborder="0" allowfullscreen></iframe><br/><br />
<a href='http://youtu.be/iwJImIhYyxQ'>QGIS User Activity</a></p>
<p>You can see the &#8220;wave&#8221; of activity progress from east to west as the daylight hours come and go.</p>
<h3>Summary</h3>
<p>If you have spatial data with a date or time component, the Time Manager plugin provides a convenient way to visualize the temporal relationships. </p>
<p><a anchor="install">[1]</a><a href="http://www.geofrogger.net/trac/wiki">http://www.geofrogger.net/trac/wiki</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://spatialgalaxy.net/2011/12/23/qgis-plugin-of-the-week-time-manager/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using the QGIS Plugin Builder</title>
		<link>http://spatialgalaxy.net/2011/10/27/using-the-qgis-plugin-builder/</link>
		<comments>http://spatialgalaxy.net/2011/10/27/using-the-qgis-plugin-builder/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 16:14:55 +0000</pubDate>
		<dc:creator>Gary Sherman</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Quantum GIS]]></category>
		<category><![CDATA[plugin builder]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[qgis]]></category>

		<guid isPermaLink="false">http://spatialgalaxy.net/?p=345</guid>
		<description><![CDATA[The Plugin Builder allows you to quickly create a skeleton Python plugin by generating all that boring boilerplate that every plugin requires. Here is a short video showing how to create, compile, and install a new plugin. For more information, see QGIS Workshop Documentation and the PyQGIS Cookbook.]]></description>
			<content:encoded><![CDATA[<p>The Plugin Builder allows you to quickly create a skeleton Python plugin by generating all that boring boilerplate that every plugin requires.</p>
<p>Here is a short video showing how to create, compile, and install a new plugin.</p>
<p><object width="640" height="480"><param name="movie" value="http://www.youtube.com/v/eWNEcJYnkPQ?version=3&#038;feature=oembed"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/eWNEcJYnkPQ?version=3&#038;feature=oembed" type="application/x-shockwave-flash" width="640" height="480" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>For more information, see <a href="http://www.qgisworkshop.org/html/index.html">QGIS Workshop Documentation</a> and the <a href="http://www.qgis.org/pyqgis-cookbook">PyQGIS Cookbook</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://spatialgalaxy.net/2011/10/27/using-the-qgis-plugin-builder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GeoApt Spatial Data Browser</title>
		<link>http://spatialgalaxy.net/2010/12/15/geoapt-spatial-data-browser/</link>
		<comments>http://spatialgalaxy.net/2010/12/15/geoapt-spatial-data-browser/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 01:25:10 +0000</pubDate>
		<dc:creator>Gary Sherman</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Quantum GIS]]></category>

		<guid isPermaLink="false">http://spatialgalaxy.net/?p=201</guid>
		<description><![CDATA[This is a project I have had lingering around for a while. It is a geospatial data browser written in Python using the PyQt and QGIS bindings. It allows you to navigate a tree structure and preview raster and vector datasets. Metadata extracted from the data can be viewed as well. It supports drag and drop for any target that accepts filenames (e.g. QGIS). For screenshots and more, see http://geoapt.com/geoapt-data-browser. The code is now available on GitHub (see https://github.com/g-sherman/GeoApt) and ready for you to contribute. Take a look and if you want to get your hands dirty fork the project and start coding. Lots of features are missing&#8212;consider this an alpha version&#8230;]]></description>
			<content:encoded><![CDATA[<p>This is a project I have had lingering around for a while. It is a geospatial data browser written in Python using the PyQt and QGIS bindings. It allows you to navigate a tree structure and preview raster and vector datasets. Metadata extracted from the data can be viewed as well. It supports drag and drop for any target that accepts filenames (e.g. QGIS). For screenshots and more, see <a href="http://geoapt.com/geoapt-data-browser">http://geoapt.com/geoapt-data-browser</a>.</p>
<p>The code is now available on GitHub (see <a href="https://github.com/g-sherman/GeoApt">https://github.com/g-sherman/GeoApt</a>) and ready for you to contribute. Take a look and if you want to get your hands dirty fork the project and start coding.  </p>
<p>Lots of features are missing&#8212;consider this an alpha version&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://spatialgalaxy.net/2010/12/15/geoapt-spatial-data-browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyQGIS Plugin Builder</title>
		<link>http://spatialgalaxy.net/2009/02/21/pyqgis-plugin-builder/</link>
		<comments>http://spatialgalaxy.net/2009/02/21/pyqgis-plugin-builder/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 02:26:33 +0000</pubDate>
		<dc:creator>Gary Sherman</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Quantum GIS]]></category>

		<guid isPermaLink="false">http://spatialgalaxy.net/?p=90</guid>
		<description><![CDATA[One of the hurdles in developing a QGIS plugin with Python is just getting the basics down. Getting the plugin setup so it is recognized by QGIS and properly adds it&#8217;s menu and toolbar items can be a bit of a chore, especially the first time. To make the process easier, I put together a web tool to generate a plugin that can be used as a starting point. The tool creates a fully functional plugin that can be loaded in QGIS 1.x. The generated plugin contains an icon and a simple dialog with Ok and Cancel buttons. Give the PyQGIS Plugin Builder a try and feel free to provide comments and suggestions.]]></description>
			<content:encoded><![CDATA[<p>One of the hurdles in developing a QGIS plugin with Python is just getting the basics down. Getting the plugin setup so it is recognized by QGIS and properly adds it&#8217;s menu and toolbar items can be a bit of a chore, especially the first time. </p>
<p>To make the process easier, I put together a web tool to generate a plugin that can be used as a starting point. The tool creates a fully functional plugin that can be loaded in QGIS 1.x. The generated plugin contains an icon and a simple dialog with Ok and Cancel buttons.</p>
<p>Give the <a href="http://pyqgis.org/builder/plugin_builder.py">PyQGIS Plugin Builder</a> a try and feel free to provide comments and suggestions.</p>
]]></content:encoded>
			<wfw:commentRss>http://spatialgalaxy.net/2009/02/21/pyqgis-plugin-builder/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

