 <?xml-stylesheet type="text/css" href="https://www.esdm.co.uk/Data/style/rss1.css" ?> <?xml-stylesheet type="text/xsl" href="https://www.esdm.co.uk/Data/style/rss1.xsl" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  <channel>
    <title>The knowledge base blog</title>
    <link>https://www.esdm.co.uk/knowledge</link>
    <description />
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>mojoPortal Blog Module</generator>
    <language>en-GB</language>
    <ttl>120</ttl>
    <atom:link href="https://www.esdm.co.uk/Blog/RSS.aspx?p=138~108~2" rel="self" type="application/rss+xml" />
    <itunes:owner />
    <itunes:explicit>no</itunes:explicit>
    <item>
      <title>Opening ESRI Personal Geodatabases in QGIS</title>
      <description><![CDATA[<p>In the more recent 64-bit versions of QGIS it is no&nbsp;longer possible&nbsp;to open ESRI personal geodatabases using the 'Add vector layer' functionality. However, it is possible to enable access to personal geodatabases by doing the following:</p>

<ol>
	<li>Download the 64-bit version on the MS Access ODBC driver (AccessDatabaseEngine_x64.exe): <a href="http://www.microsoft.com/en-gb/download/details.aspx?id=13255">http://www.microsoft.com/en-gb/download/details.aspx?id=13255</a></li>
	<li>If you <strong>don’t</strong> have 32-bit MS Office installed you can just run the exe, however if you <strong>do</strong> have 32-bit office installed then you need to start an admin command prompt and run the installer in passive mode as follows:</li>
</ol>

<pre class="Indent1">
AccessDatabaseEngine_x64.exe /passive</pre>

<ol start="3">
	<li>For QGIS 2: Then you need to edit the qgis-ltr.bat (normally in C:\Program Files\QGIS x.xx\bin, in previous versions used to be qgis.bat) and add the following lines (before the ‘start’ command)</li>
</ol>

<pre class="Indent1">
set OGR_SKIP=ODBC
set PGEO_DRIVER_TEMPLATE=DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%%s</pre>

<ol start="4">
	<li>For QGIS 3: In QGIS Settings panel -&gt; Options | System | Environment add the following two variables:
	<p>variable name: PGEO_DRIVER_TEMPLATE&nbsp;<br />
	value: DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s<br />
	Or if being used on a shared server add a system environment variable&nbsp;<br />
	PGEO_DRIVER_TEMPLATE=DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s</p>
	</li>
	<li>
	<div>Now you should be able to start QGIS and simply drag the geodatabase mdb file onto the QGIS workspace and it will open.</div>
	</li>
</ol>

<div>Note: This solution has been tested using QGIS v2.14.11 (Essen)&nbsp; &amp; QGIS v3.4.13 (Madeira)</div>

<div>Note: This post is based on information taken from the web page listed below, however that page&nbsp;was based on an older version of QGIS (2.8.1) which used the qgis.bat file rather than qgis-ltr.bat.</div>

<div><a href="http://gis.stackexchange.com/questions/129514/opening-esri-personal-geodatabase-mdb-using-qgis">http://gis.stackexchange.com/questions/129514/opening-esri-personal-geodatabase-mdb-using-qgis</a></div>
<br /><a href='https://www.esdm.co.uk/opening-esri-personal-geodatabases-in-qgis'>Steve Ellwood</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/opening-esri-personal-geodatabases-in-qgis'>...</a>]]></description>
      <link>https://www.esdm.co.uk/opening-esri-personal-geodatabases-in-qgis</link>
      <author>stevee@esdm.co.uk (Steve Ellwood)</author>
      <comments>https://www.esdm.co.uk/opening-esri-personal-geodatabases-in-qgis</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/opening-esri-personal-geodatabases-in-qgis</guid>
      <pubDate>Wed, 01 Mar 2017 10:13:00 GMT</pubDate>
    </item>
    <item>
      <title>ArcGIS MapLink: finding and checking dll registration</title>
      <description><![CDATA[<p>The ArcGIS extension (XGMapLinkArcGISExtension.dll) is located using COM registration.</p>

<p>If you have multiple installations it can be confusing working out which copy you are actually running.&nbsp; Looking in the registry at:</p>

<blockquote>
<p>HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{EDFA6FE2-C2C5-4BE1-9F12-F1ED37D85EE2}\InprocServer32</p>
</blockquote>

<p>will tell you where the file(s) are being run from.</p>

<p>If you want to manually register the dll to a particular location you need to open a cmd window as Administrator and then run:</p>

<blockquote>
<p>C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe /codebase /tlb C:\AMS\CMSI_v2.2.0a\code\XGMapLinkArcgisExtension.dll</p>
</blockquote>

<blockquote>
<p>C:\Program Files (x86)\Common Files\ArcGIS\bin\ESRIRegasm.exe" /p:Desktop C:\AMS\CMSI_v2.2.0a\code\XGMapLinkArcgisExtension.dll</p>
</blockquote>
<br /><a href='https://www.esdm.co.uk/arcgis-maplink-finding-and-checking-dll-registration'></a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/arcgis-maplink-finding-and-checking-dll-registration'>...</a>]]></description>
      <link>https://www.esdm.co.uk/arcgis-maplink-finding-and-checking-dll-registration</link>
      <author>()</author>
      <comments>https://www.esdm.co.uk/arcgis-maplink-finding-and-checking-dll-registration</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/arcgis-maplink-finding-and-checking-dll-registration</guid>
      <pubDate>Wed, 25 Sep 2013 08:17:00 GMT</pubDate>
    </item>
    <item>
      <title>Fixing ArcGIS personal geodatabase autonumber problem</title>
      <description><![CDATA[<p>A number of HBSMR&nbsp;clients have been experiencing problems with creating new features in ArcGIS personal geodatabases via MapLink, resulting in a error similar to this:</p>

<pre style="line-height: 21.59375px;">
<em><strong>Your edits could not be saved
Error HRESULT E-FAIL has been returned from a call to a COM component.
Would you like to keep the temporary edit layers in the map?</strong></em></pre>

<p style="font-size: 19px;">The problem is due to a fault with the MS Access database that forms the geodatabase, which means after a feature has been moved or deleted the database tries to reuse that ID value and this upsets the autonumber process, or so we believe.</p>

<p style="font-size: 19px;">At present we do not have a solution to this problem but we do have a bit of code that can be used to reset the autonumber values for any chosen field. This code can be used as a function and bundled in an mdb with a macro that runs the function and sent out to clients as needed. The code for the functions is as follows (this was originally Hartmut's code but I modified from the a sub to a function adding the return and msgbox, just so I could see that something was happening):</p>

<p style="font-size: 19px;">&nbsp;</p>

<p style="font-size: 19px;">Public Function ResetAutoNumber(ByVal tableName As String, ByVal autoNumberColumnName As String)<br />
&nbsp;&nbsp;&nbsp; Dim maxAutoNumber As Long<br />
&nbsp;&nbsp;&nbsp; maxAutoNumber = DMax(autoNumberColumnName, tableName) + 1<br />
&nbsp;&nbsp;&nbsp; DoCmd.RunSQL "ALTER TABLE " &amp; tableName &amp; " ALTER COLUMN " &amp; autoNumberColumnName &amp; " COUNTER(" &amp; maxAutoNumber &amp; ",1)"<br />
&nbsp;&nbsp;&nbsp; ResetAutoNumber = True<br />
&nbsp;&nbsp;&nbsp; MsgBox tableName + " done!"<br />
End Function</p>

<p style="font-size: 19px;">&nbsp;</p>

<p style="font-size: 19px;">And macro simple needs to have a number of RunCode lines that call this function for each of the layers in the personal geodatabase, like so:</p>

<p style="font-size: 19px;">&nbsp;</p>

<p style="font-size: 19px;">RunCode</p>

<p style="font-size: 19px;">&nbsp; &nbsp; &nbsp; &nbsp;Function Name ResetAutoNumber ("Mon_point", "OBJECTID")</p>

<p style="font-size: 19px;">RunCode</p>

<p style="font-size: 19px;">&nbsp; &nbsp; &nbsp; &nbsp;Function Name ResetAutoNumber ("Mon_poly", "OBJECTID")</p>

<p style="font-size: 19px;">RunCode</p>

<p style="font-size: 19px;">&nbsp; &nbsp; &nbsp; &nbsp;Function Name ResetAutoNumber ("Mon_line", "OBJECTID")</p>

<p style="font-size: 19px;">&nbsp;</p>
<br /><a href='https://www.esdm.co.uk/fixing-arcgis-personal-geodatabase-autonumber-problem'>Steve Ellwood</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/fixing-arcgis-personal-geodatabase-autonumber-problem'>...</a>]]></description>
      <link>https://www.esdm.co.uk/fixing-arcgis-personal-geodatabase-autonumber-problem</link>
      <author>stevee@esdm.co.uk (Steve Ellwood)</author>
      <comments>https://www.esdm.co.uk/fixing-arcgis-personal-geodatabase-autonumber-problem</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/fixing-arcgis-personal-geodatabase-autonumber-problem</guid>
      <pubDate>Wed, 29 May 2013 12:42:00 GMT</pubDate>
    </item>
    <item>
      <title>Find "Godzillas" in your ArcGIS feature class (by counting vertices)</title>
      <description><![CDATA[<p>To count the number of vertices:</p>

<ul>
	<li>Add a new field to the feature class called, for example, VertexCount</li>
	<li>Use the Calculate Field tool within the attribute table, or in ArcToolbox, with the following Python expression - !shape!.pointcount</li>
	<li>Sort the feature class on the VertexCount field to find the worst offenders. If there is any bad geometry the expression may trip up, which is informative in itself.</li>
	<li>You can now select only the most complex features for generalising.</li>
</ul>

<p>See the following article for more information. I have not tried the dicing method that is discussed later in the article: <a href="http://blogs.esri.com/esri/arcgis/2010/07/23/dicing-godzillas-features-with-too-many-vertices/">http://blogs.esri.com/esri/arcgis/2010/07/23/dicing-godzillas-features-with-too-many-vertices/ </a></p>

<p>&nbsp;</p>
<br /><a href='https://www.esdm.co.uk/find-godzillas-in-your-arcgis-feature-class-by-counting-vertices'>Sylvina Tilbury</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/find-godzillas-in-your-arcgis-feature-class-by-counting-vertices'>...</a>]]></description>
      <link>https://www.esdm.co.uk/find-godzillas-in-your-arcgis-feature-class-by-counting-vertices</link>
      <author>sylvinat@esdm.co.uk (Sylvina Tilbury)</author>
      <comments>https://www.esdm.co.uk/find-godzillas-in-your-arcgis-feature-class-by-counting-vertices</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/find-godzillas-in-your-arcgis-feature-class-by-counting-vertices</guid>
      <pubDate>Wed, 15 May 2013 11:07:00 GMT</pubDate>
    </item>
    <item>
      <title>ArcGIS: Table of Contents problems with dual monitors</title>
      <description><![CDATA[<p>
	&nbsp;</p>
<p>
	Basically the user was complaining that they could not turn layers on and off in the Table of Contents (the left hand pane) but they could go in to the properties of the layer and turn things on and off from there, but this was very frustrating and tedious. They had tried multiple MXD files, both their own and those created by other users and still no joy, and other people had opened their MXDs and they were fine.</p>
<p>
	What the problem actually came down, after some serious google-ling, &nbsp;to was the fact that the user was using two monitors and had them set-up with the right monitor as the primary and the left as the secondary. Once I got them to switch them around, i.e. the left monitor as the primary display, everything worked fine.</p>
<p>
	An odd a very obscure issue, which I thought I share in case anybody every encounters it again.&nbsp;</p>
<br /><a href='https://www.esdm.co.uk/arcgis-table-of-contents-problems-with-dual-monitors'>Steve Ellwood</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/arcgis-table-of-contents-problems-with-dual-monitors'>...</a>]]></description>
      <link>https://www.esdm.co.uk/arcgis-table-of-contents-problems-with-dual-monitors</link>
      <author>stevee@esdm.co.uk (Steve Ellwood)</author>
      <comments>https://www.esdm.co.uk/arcgis-table-of-contents-problems-with-dual-monitors</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/arcgis-table-of-contents-problems-with-dual-monitors</guid>
      <pubDate>Wed, 06 Jun 2012 15:21:00 GMT</pubDate>
    </item>
    <item>
      <title>ArcGIS 10 - tips to improve editing responsiveness</title>
      <description><![CDATA[<p>
	If you are experiencing poor performance/responsiveness whilst editing features in ArcGIS v10 this can in many cases be remedied by turning off the new snapping tools, which are on as default in v10.&nbsp;This is especially true if the mxd contains a lot of vector layers that are stored on remote servers because ArcGIS appears to query the layers each time you move the mouse to determine the snapping information. The snapping can be turned back on if it is needed, but you can also set the snapping to the ‘classic’ v9.3 mode as well.</p>
<p>
	To turn the snapping off you need to first turn on the Snapping toolbar, you can then use the Snapping menu and un-tick the ‘use snapping’ option.</p>
<p>
	To revert to ‘classic snapping’ select ‘Options’ from the Editor menu, on the Editor toolbar, and tick the ‘use classic snapping’ option on the ‘General’ tab.</p>
<p>
	On this same tab you can also turn off the ‘mini toolbar’ that follows you around whilst editing, which some people find annoying.</p>
<br /><a href='https://www.esdm.co.uk/arcgis-10-tips-to-improve-editing-responsiveness'>Steve Ellwood</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/arcgis-10-tips-to-improve-editing-responsiveness'>...</a>]]></description>
      <link>https://www.esdm.co.uk/arcgis-10-tips-to-improve-editing-responsiveness</link>
      <author>stevee@esdm.co.uk (Steve Ellwood)</author>
      <comments>https://www.esdm.co.uk/arcgis-10-tips-to-improve-editing-responsiveness</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/arcgis-10-tips-to-improve-editing-responsiveness</guid>
      <pubDate>Thu, 08 Dec 2011 11:59:00 GMT</pubDate>
    </item>
    <item>
      <title>Some jottings on SQL Azure and GIS</title>
      <description><![CDATA[<p>I have set up a SQL Azure 90 day trial (as of 18th November) to test whether ArcSquirrel can work with Azure. This was prompted by an email from Robert Cheetham, CEO at Azavea, who is investigating cloud solutions for their Cicero product. Here are some notes about</p>

<ol>
	<li>setting up and accessing SQL Azure databases</li>
	<li>using SQL Azure with ArcGIS + ArcSquirrel and MapLink</li>
	<li>using SQL Azure with Quantum GIS and MapServer.</li>
</ol>

<h4>Azure Management Portal</h4>

<p>Although I’ve never set up any cloud services before (other than <a href="http://www.arvixe.com/" target="_blank" title="Arvixe web site">Arvixe web hosting</a>) it was incredibly easy to setup a trial SQL Azure subscription (“Windows Azure Platform Introductory Special”), create a database, and add some firewall rules to control access. I didn’t dig deep, but the “Management Portal” seems nice and simple:</p>

<p><a href="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_10.png"><img alt="Azure Management Portal" border="0" height="188" src="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_thumb_4.png" style="padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" title="Azure Management Portal" width="244" />&nbsp;</a></p>

<p>It helpfully tells you your connection string for ADO.Net, ODBC and PHP (passwords not included!):</p>

<p><a href="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_8.png"><img alt="SQL Azure connection strings" border="0" height="180" src="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_thumb_3.png" style="padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" title="SQL Azure connection strings" width="244" />&nbsp;</a></p>

<p>See this page for <a href="http://www.microsoft.com/windowsazure/offers/popup/popup.aspx?lang=en&amp;locale=en-gb&amp;offer=ms-azr-0018p&amp;no-rewrite=true" target="_blank" title="Details of the Windows Azure Platform Introductory Special">details of the Windows Azure Platform Introductory Special</a> including what you get for no charge and the pricing for the rest.</p>

<h4>MapLink, ArcSquirrel and Azure</h4>

<p>Hartmut connected up our MapLink to the database and pushed some spatial data into my Azure database from ArcGIS – 20,000 polygons took about 75 minutes.&nbsp; Hartmut had the layers drawing in ArcMAP, performing as well as in a normal SQL Server instance apparently, with only minor mods to our code to make the initial connection. However editing will not work without some more tweaks - MapLink and ArcSquirrel rely on some SQL metadata that is a little different on Azure.</p>

<h4>SQL Server Management Studio and MS Access</h4>

<p>Connecting with SSMS is simple, however you get reduced functionality – for example you cannot right-click &gt; edit top 200 records or anything, so quick edits of a small table need to be done with SQL or in MS Access or some other client. Fortunately connecting with MS Access (ODBC + SQL Native Client 10) is also simple, and&nbsp; the Azure database behaves just like a local SQL instance – remarkable querying speed (all things considered), though slower inserts (10,000 records took something like 15 minutes). NB you cannot directly link a spatial table into Access because it doesn’t recognize the geometry data type; but to update attributes you can link a view.</p>

<p>Also, in SSMS you get no designer tools, e.g. for creating a view; everything has to be done with T-SQL.</p>

<h4>SQL Azure Database Manager</h4>

<p>After writing the above I found the database manager in the Azure control panel, which has functionality similar to SSMS, including the ability to edit the tables*:</p>

<p><a href="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_12.png"><img alt="SQL Azure database manager" border="0" height="154" src="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_thumb_5.png" style="padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" title="SQL Azure database manager" width="244" />&nbsp;</a></p>

<p>* spatial data types not supported for view or edit.</p>

<p>You get a designer for creating/modifying tables, but views and stored procedures are T-SQL only.</p>

<h4>MapServer, OGR and Azure</h4>

<p>Next I wanted to try serving the data through MapServer, and viewing/editing the data in Quantum GIS or MapInfo.&nbsp; MapServer and QGIS require the “geometry_columns” and “spatial_ref_sys” tables, and the easiest way to create these is to push some data in with ogr2ogr.</p>

<p>So I tried this from one of our London servers. I loaded a few hundred linear features, but got four errors like “INSERT command for new feature failed… incorrect syntax…”. On checking the results, a) while the geometries had loaded fine, all the attribute fields were NULL, and b) the spatial_ref_sys table was empty.&nbsp; I had four attribute fields, so my guess is that each syntax error was one field update across all records using a join on the incoming data.</p>

<p>Next I hooked up a MapServer WMS to my SQL Azure tables. MapServer had no trouble connecting to my Azure tables, but initially wouldn’t draw anything…&nbsp; on investigating I found that ogr2ogr had not correctly set the SRID of the geometries, so I had to update them “manually” with:</p>

<pre class="csharpcode">
<span class="kwrd">update</span> esdm_waters <span class="kwrd">set</span> ogr_geometry.STSrid = 4326</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>(which, incidentally, took 1 minute 52 seconds for 788 rows, demonstrating that updating an Azure database ain’t quick).</p>

<p>Clearly OGR needs a little work to do on SQL Azure support, but this was enough to get me going.</p>

<p>The WMS worked, so to challenge it a little more I set up another WMS onto a table with about 8000 sub-tidal habitat polygons, showing red in this OpenLayers map:</p>

<p><a href="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_2.png"><img alt="MapServer WMS from SQL Azure table" border="0" height="127" src="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_thumb.png" style="padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" title="MapServer WMS from SQL Azure table" width="244" />&nbsp;</a></p>

<p>And here showing the rivers WMS as well (blue lines):</p>

<p><a href="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_4.png"><img alt="MapServer WMS from SQL Azure table" border="0" height="127" src="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_thumb_1.png" style="padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" title="MapServer WMS from SQL Azure table" width="244" />&nbsp;</a></p>

<p>Performance of these two layers was perfectly acceptable, though actually about 100% slower than the same WMS working from a local SQL Server 2008 Express instance. It would be interesting to see what it could do with MapServer also running on Azure.</p>

<p>I also tried a WFS – again, performance was acceptable though significantly slower than running with a local SQL instance (though I didn’t do strict comparisons).</p>

<h4>Quantum GIS and SQL Azure</h4>

<p>I found this really helpful blog post to get started: <a href="http://woostuff.wordpress.com/2011/03/13/opening-ms-sql-spatial-in-qgis/" title="http://woostuff.wordpress.com/2011/03/13/opening-ms-sql-spatial-in-qgis/">http://woostuff.wordpress.com/2011/03/13/opening-ms-sql-spatial-in-qgis/</a></p>

<p>Adding the layers requires some python script, but I’m sure someone will write a GUI plugin for QGIS soon.</p>

<p>First make sure you are running a version of QGIS that has GDAL/OGR 1.8 libraries – I’m on 1.7.0 which is OK.</p>

<p>Open the Plugins menu &gt; Python Console</p>

<p>and type in these two commands (modified for your data):</p>

<pre class="csharpcode">
uri = <span class="str">"MSSQL:server={serverName};database={databaseName};tables={tableName};trusted_connection=yes"</span>
qgis.utils.iface.addVectorLayer(uri,<span class="str">'{yourLayerNameHere}'</span>,<span class="str">'ogr'</span>)
</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>In my case:</p>

<pre class="csharpcode">
uri = <span class="str">"MSSQL:server=tcp:a0awtn7gg9.database.windows.net;database=ArcSquirrel1;tables=esdm_waters;Uid=exegesis@a0awtn7gg9;Pwd=myPassword;"</span>
qgis.utils.iface.addVectorLayer(uri,<span class="rem">'Rivers','ogr')</span>
</pre>

<pre class="csharpcode">
Without any fuss my rivers dataset appeared:</pre>

<p><a href="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_14.png"><img alt="SQL Azure table in Quantum GIS" border="0" height="237" src="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_thumb_6.png" style="padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" title="SQL Azure table in Quantum GIS" width="244" />&nbsp;</a></p>

<p>And I can create and edit features and their attributes, here adding a test line off the Hebrides:</p>

<p><a href="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_16.png"><img alt="Editing SQL Azure features in QGIS" border="0" height="237" src="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_thumb_7.png" style="padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" title="Editing SQL Azure features in QGIS" width="244" />&nbsp;</a></p>

<p>And to prove it, here’s my new feature in OpenLayers…</p>

<p><a href="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_18.png"><img alt="Edited features from QGIS and SQL Azure" src="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_thumb_8.png" style="margin: 0px; width: 244px; height: 127px; padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" title="Edited features from QGIS and SQL Azure" />&nbsp;</a></p>

<p>And finally, here we have the habitat polygons (EPSG:27700) colour coded by habitat type, as well as the rivers (EPSG:4326), in QGIS. Polygon editing also worked fine, once I’d worked out why my new polygons kept vanishing (doh, classified symbols).</p>

<p><a href="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_20.png"><img alt="SQL Azure polygons thematically mapped in QGIS" border="0" height="237" src="https://www.esdm.co.uk/Data/Sites/1/Windows-Live-Writer/Some-jottings-on-SQL-Azure-and-GIS_5C47/image_thumb_9.png" style="padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" title="SQL Azure polygons thematically mapped in QGIS" width="244" />&nbsp;</a></p>

<p>Lots to think about, and I look forward to editing the same data with ArcGIS and ArcSquirrel soon…</p>
<br /><a href='https://www.esdm.co.uk/some-jottings-on-sql-azure-and-gis'>Crispin Flower</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/some-jottings-on-sql-azure-and-gis'>...</a>]]></description>
      <link>https://www.esdm.co.uk/some-jottings-on-sql-azure-and-gis</link>
      <author>crispin.flower@idoxgroup.com (Crispin Flower)</author>
      <comments>https://www.esdm.co.uk/some-jottings-on-sql-azure-and-gis</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/some-jottings-on-sql-azure-and-gis</guid>
      <pubDate>Sat, 19 Nov 2011 11:42:00 GMT</pubDate>
    </item>
    <item>
      <title>Notes on importing spatial data into SQL Server 2008</title>
      <description><![CDATA[<p>
	There are a variety of ways to do this, but often you will hit issues with data validity.</p>
<ul>
	<li>
		If you have our ArcGIS Maplink product (or ArcSquirrel) then loading data in using this into a temporary SQL table is probably best as it will do a reasonable amount of checking.</li>
	<li>
		MapInfo has its own SQL loader tool ("Easy Loader" - find it in the Tool Manager)</li>
	<li>
		If you are just using open source you can use OGR2OGR</li>
</ul>
<p>
	ogr2ogr -overwrite -f "MSSQLSpatial" "MSSQL:server=MyServer;database=MyDatabase;Trusted_Connection=yes;" "C:\Temp\MyShapeFile.shp" -a_srs "EPSG:27700"</p>
<p>
	Once the data is in SQL there can still be issues:</p>
<h2>
	Incorrect SRID</h2>
<ul>
	<li>
		Make sure you specified the correct SRID when the data was loaded (if you didn’t specify it – it may well be 0). You can check this with the SQL: SELECT geom.STSrid from SitesGeom Where geom.STSrid &lt;&gt; 27700</li>
</ul>
<h2>
	Invalid ring</h2>
<ul>
	<li>
		You may also have invalid ring geometries – a good post on this is <a href="http://blogs.msdn.com/b/edkatibah/archive/2008/08/19/working-with-invalid-data-and-the-sql-server-2008-geography-data-type-part-1b.aspx"><font color="#0066cc">http://blogs.msdn.com/b/edkatibah/archive/2008/08/19/working-with-invalid-data-and-the-sql-server-2008-geography-data-type-part-1b.aspx</font></a> but the key SQL command is:</li>
</ul>
<p>
	UPDATE foo SET geom = geom.STUnion(geom.STStartPoint());</p>
<h2>
	Invalid geometries</h2>
<p>
	UPDATE foo SET geom = geom.MakeValid()</p>
<h2>
	SRID not imported</h2>
<p>
	Import geometry data into temp SQL table (e.g. foo) – with tempGeom column</p>
<p>
	Then try to populate a geometry column from the WKB of the validated column:</p>
<p>
	ALTER TABLE foo ADD geomFinal geometry;</p>
<p>
	SET geomFinal = geometry::STGeomFromWKB(geomTemp.STAsBinary(), 27700)</p>
<br /><a href='https://www.esdm.co.uk/notes-on-importing-spatial-data-into-sql-server-2008'>Crispin Flower</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/notes-on-importing-spatial-data-into-sql-server-2008'>...</a>]]></description>
      <link>https://www.esdm.co.uk/notes-on-importing-spatial-data-into-sql-server-2008</link>
      <author>crispin.flower@idoxgroup.com (Crispin Flower)</author>
      <comments>https://www.esdm.co.uk/notes-on-importing-spatial-data-into-sql-server-2008</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/notes-on-importing-spatial-data-into-sql-server-2008</guid>
      <pubDate>Thu, 17 Nov 2011 09:24:00 GMT</pubDate>
    </item>
    <item>
      <title>Where to find the Ordnance Survey registration files</title>
      <description><![CDATA[<p>The registration files (world files and tab files) for all Ordnance Survey raster datasets can be downloaded from: <p><a title="http://www.ordnancesurvey.co.uk/oswebsite/products/geo-referencing.html" href="http://www.ordnancesurvey.co.uk/oswebsite/products/geo-referencing.html" target="_blank">http://www.ordnancesurvey.co.uk/oswebsite/products/geo-referencing.html</a> <p>These are available as *.tfw "world files" for ArcGIS<sup>®</sup>, or *.tab files for MapInfo Professional<sup>®</sup></p><br /><a href='https://www.esdm.co.uk/where-to-find-the-ordnance-survey-registration-files'>Crispin Flower</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/where-to-find-the-ordnance-survey-registration-files'>...</a>]]></description>
      <link>https://www.esdm.co.uk/where-to-find-the-ordnance-survey-registration-files</link>
      <author>crispin.flower@idoxgroup.com (Crispin Flower)</author>
      <comments>https://www.esdm.co.uk/where-to-find-the-ordnance-survey-registration-files</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/where-to-find-the-ordnance-survey-registration-files</guid>
      <pubDate>Tue, 15 Nov 2011 14:21:04 GMT</pubDate>
    </item>
  </channel>
</rss>