<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Century Gothic";
        panose-1:2 11 5 2 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Century Gothic","sans-serif";
        color:windowtext;
        font-weight:normal;
        font-style:normal;}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:12.0pt;background:white;mso-fareast-language:EN-GB">Hello folks</span><span style="font-size:12.0pt;mso-fareast-language:EN-GB"><br>
<br>
<span style="background:white">I've come across a problem using the geo-processing tools in QGIS and the extents of layers from PostGIS.</span><br>
<br>
<span style="background:white">It seems like QGIS is using an estimated extent for a PostGIS layer which then leads to issues when using geo-processing tools (creating a TIN or Voronoi polygon set, for example).  Loading the same dataset as a shapefile returns
 an exact extent.</span><br>
<br>
<span style="background:white">For a point dataset, for example, I get the following extents in QGIS and PostGIS:</span><br>
<br>
<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.65pt;background:white"><span style="font-size:12.0pt;mso-fareast-language:EN-GB">QGIS extents as PostGIS layer<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.65pt;background:white"><span style="font-size:12.0pt;mso-fareast-language:EN-GB">xMin,yMin 318359.56,731243.81 : xMax,yMax 373588.41,779145.12<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.65pt;background:white"><span style="font-size:12.0pt;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:13.65pt;background:white"><span style="font-size:12.0pt;mso-fareast-language:EN-GB">QGIS extents as Shapefile layer<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.65pt;background:white"><span style="font-size:12.0pt;mso-fareast-language:EN-GB">xMin,yMin 316723.00,731481.00 : xMax,yMax 373315.00,782722.00<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.65pt;background:white"><span style="font-size:12.0pt;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:13.65pt;background:white"><span style="font-size:12.0pt;mso-fareast-language:EN-GB">PostGIS extents<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.65pt;background:white"><span style="font-size:12.0pt;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:13.65pt;background:white"><span style="font-size:12.0pt;mso-fareast-language:EN-GB">SELECT ST_EstimatedExtent('schema','tablename','geometry') AS estextent,<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.65pt;background:white"><span style="font-size:12.0pt;mso-fareast-language:EN-GB"> ST_Extent(geometry) AS bextent<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.65pt;background:white"><span style="font-size:12.0pt;mso-fareast-language:EN-GB"> FROM schema.tablename;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.65pt;background:white"><span style="font-size:12.0pt;mso-fareast-language:EN-GB"> <o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.65pt;background:white"><span style="font-size:12.0pt;mso-fareast-language:EN-GB">Estimated - BOX(318359.5625 731243.8125,373588.40625 779145.125) ; <br>
<br>
Exact - BOX(316722.999997809 731480.999996626,373314.999999305 782721.999996855)<br>
<br>
The PostGIS estimated extent matches the QGIS estimated extent and is smaller than the exact extent.  The shapefile exact extent matches the PostGIS exact extent. In this case the estimated extent is 91% of the exact extent which is somewhat sub-optimal...<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">I’m running QGIS 2.6, 2.8.3 and 2.10.1 with PostgreSQL 9.2.13 and PostGIS 2.1.8 on Windows 7 32bit.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">I have tried with my PostGIS connection set with and without the “use estimated metadata” and have updated the table statistics in the database with VACUUM ANALYSE but still get the same results.  I imagine
 the estimated extents make things a bit faster.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">There are also a number of reports on this<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><a href="https://hub.qgis.org/issues/13232">https://hub.qgis.org/issues/13232</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><a href="https://hub.qgis.org/issues/10335">https://hub.qgis.org/issues/10335</a> (in this case the PostGIS extent was bigger than the shapefile extent)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Anyone got any suggestions as to how to fix this?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Thanks<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Ross<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:13.0pt;font-family:"Century Gothic","sans-serif";color:#4F6228;mso-fareast-language:EN-GB">Ross McDonald
</span></b><span style="font-size:13.0pt;font-family:"Century Gothic","sans-serif";color:#4F6228;mso-fareast-language:EN-GB">|<b>
</b>GIS Data Coordinator | Resources Department, IT Division | Angus Council, Angus House, Orchardbank Business Park, Forfar, DD8 1AT<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Century Gothic","sans-serif";color:#4F6228;mso-fareast-language:EN-GB">T:
<b>01307 476419</b> | F: 01307 476401 | E: <a href="mailto:mcdonaldr@angus.gov.uk">
<span style="color:#4F6228">mcdonaldr@angus.gov.uk</span></a> <b><o:p></o:p></b></span></p>
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:13.0pt;font-family:"Century Gothic","sans-serif";color:#4F6228;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
</div>
<div> </div>
<div>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="FONT-SIZE: 7.5pt; FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 8.0pt; mso-bidi-font-family: 'Times New Roman'"><font size="2">This message is strictly confidential. If you have received
 this in error, please inform the sender and remove it from your system. If received in error you may not copy, print, forward or use it or any attachment in any way. This message is not capable of creating a legal contract or a binding representation and does
 not represent the views of Angus Council. Emails may be monitored for security and network management reasons.<span style="mso-spacerun: yes">
</span>Messages containing inappropriate content may be intercepted. Angus Council does not accept any liability for any harm that may be caused to the recipient system or data on it by this message or any attachment.
</font></span></p>
</div>
</body>
</html>