<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 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
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:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
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-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Hi everyone.<o:p></o:p></p><p class=MsoNormal>And so this is my first post to this mailing list, and since I registered, I haven’t seen so many messages so I hope the level of this email is up to this list’s standards.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Here is the situation.<o:p></o:p></p><p class=MsoNormal>At Expedia, we are working on upgrading our geo system and that implies migrating to PostGIS. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>During my tests, I did the following:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I have two tables for regions, one, say region_geometry, keeps the polygon as a geometry(4326). The second one, say region_geography, keeps the polygon of a region as a Geography(4326).<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>We also have other tables mapping hotels and points of interests, both storing their location as a geography point(4326).<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The test case is to find everything that is within a region. In other words, find all hotels and points of interests that are within a given region’s polygon.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The first test uses the region_geometry table, and the query uses ST_Within function (using geometries and the && operator).<o:p></o:p></p><p class=MsoNormal>The second test uses the region_geography table, and the query uses ST_Intersects function (using geographies).<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I was expecting the geometry version to be much faster, but I actually find that performance is somewhat the same. Both queries use the special index, perform the index scan and so on.  So how can this be possible, how can I be sure that geometries are actually faster than geographies ?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The main issue with these two tests is regarding polygons crossing the international date line. So suppose I have a polygon that maps the Fiji islands. That polygon will cross the international date line. The geography method works fine, but the polygon, when used in geometry world, is actually a ribbon around the planet. I absolutely understand the reason, but if I really want to stay in the geometry world, how can I work around this problem ? Do I really have to split my polygon to create 2 polygons not crossing the line ? Do I have to filter my requests, find if the polygon crosses the date line and if so, “revert” to geographic calculations ?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I have somewhat the same questions regarding distance calculations. In geometry world, if I want all the hotels in a 200 meters radius of a given point, I would use something like ST_Distance_spheroid(p1, p2) < 200. In geography, I would use ST_DWithin(p1, p2, 200). My tests shows that STD_Within (geography, geography) is most of the time faster than st_distance(p1, p2) with or without spheroid. Again, in both cases, the spatial indexes are used.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I have many quite precise and edgy questions regarding good practices and performance tuning for PostGIS.  I would like to provide samples and discuss around them, see what I / we can find. Is this list the right place to ask ? <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Maxime Poulin.<o:p></o:p></p></div></body></html>