<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=utf-8"><meta name=Generator content="Microsoft Word 15 (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;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",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;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:"Consolas",serif;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@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><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>We've discussed this before I've especially wanted a BOX 3D geometry primitive as that's a very big thing in 3D augmented reality<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>I think all the 3D toolkits (I know X3Dom has it, I believe three js has it too).<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>I think we tried to get at least the concept of a true BOX type in 2.0 and we got into arguments about moving forward on it.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Only one I can think of is SQL/MM specs don't support the thing so we'd be deviating from the specs.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>I forget what other arguments were against it. <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> postgis-devel [mailto:postgis-devel-bounces@lists.osgeo.org] <b>On Behalf Of </b>Darafei "Kom?pa" Praliaskouski<br><b>Sent:</b> Friday, October 26, 2018 9:09 AM<br><b>To:</b> PostGIS Development Discussion <postgis-devel@lists.osgeo.org><br><b>Subject:</b> Re: [postgis-devel] Faster ST_Intersection<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>It looks like for polygon / box intersection area can be calculated in O(n), by just clamping the ordinates (<a href="https://github.com/postgis/postgis/commit/3233ccd19cdb6958b53164262cd812d3f6d70fb2">https://github.com/postgis/postgis/commit/3233ccd19cdb6958b53164262cd812d3f6d70fb2</a>). <o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>It also may be adapted for any convex polygons, with O(n*m) though. Convex check also seems to be O(n). Building dataset tends to be mostly convex (and mostly 4-corner), so this may be a specialized fast path.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Is there a chance we may want BOX() as new geometry primitive to save a is_convex / is_box check? :)<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Any other thoughts?<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>On Tue, Oct 23, 2018 at 8:04 PM Paul Ramsey <<a href="mailto:pramsey@cleverelephant.ca">pramsey@cleverelephant.ca</a>> wrote:<o:p></o:p></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><div><p class=MsoNormal>The first GIS system I ever used had an “intersection area” function that was distinct from, and faster than, the full-on “intersection” function that output a new geometry. I wonder if there is some possibility there…<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>P<o:p></o:p></p><div><p class=MsoNormal><br><br><o:p></o:p></p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal>On Oct 23, 2018, at 6:01 PM, Darafei Komяpa Praliaskouski <<a href="mailto:me@komzpa.net" target="_blank">me@komzpa.net</a>> wrote:<o:p></o:p></p></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>Hi,<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>I have two polygonal layers to intersect and need to measure area of intersections.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>ST_Area(ST_Intersection(a.geom, b.geom)) works fine, but is rather slow. Typical polygon on first side has <10 edges, on second 200..1000 edges.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>What are my options to make it faster? Any ideas, links, experiences to share are welcome.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>For starters, this seems to work faster than vanilla ST_Intersection in my case:<o:p></o:p></p></div><div><pre><b><span style='color:navy'>create or replace function </span></b><i>clipped_st_intersection</i>(geom1 <b><span style='color:navy'>geometry</span></b>, geom2 <b><span style='color:navy'>geometry</span></b>)<br> <b><span style='color:navy'>returns geometry<br>as </span><span style='color:green'>$$</span><span style='color:navy'>select </span></b><i>ST_Intersection</i>(<br> <b><span style='color:navy'>case<br> when </span></b><i>ST_MemSize</i>(geom1) > <span style='color:blue'>160 </span><b><span style='color:navy'>then </span></b><i>ST_ClipByBox2D</i>(geom1, geom2)<br> <b><span style='color:navy'>else </span></b>geom1 <b><span style='color:navy'>end</span></b>, <b><span style='color:navy'>case<br> when </span></b><i>ST_MemSize</i>(geom2) > <span style='color:blue'>160 </span><b><span style='color:navy'>then </span></b><i>ST_ClipByBox2D</i>(geom2, geom1)<br> <b><span style='color:navy'>else </span></b>geom2 <b><span style='color:navy'>end</span></b>)<b><span style='color:green'>$$<br></span><span style='color:navy'>language sql<br>immutable<br>strict<br>parallel safe</span></b>;<o:p></o:p></pre></div></div><p class=MsoNormal>-- <o:p></o:p></p><div><div><p class=MsoNormal>Darafei Praliaskouski<br>Support me: <a href="http://patreon.com/komzpa" target="_blank">http://patreon.com/komzpa</a><o:p></o:p></p></div></div><p class=MsoNormal>_______________________________________________<br>postgis-devel mailing list<br><a href="mailto:postgis-devel@lists.osgeo.org" target="_blank">postgis-devel@lists.osgeo.org</a><br><a href="https://lists.osgeo.org/mailman/listinfo/postgis-devel" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-devel</a><o:p></o:p></p></div></blockquote></div><p class=MsoNormal><o:p> </o:p></p></div></div><p class=MsoNormal>_______________________________________________<br>postgis-devel mailing list<br><a href="mailto:postgis-devel@lists.osgeo.org" target="_blank">postgis-devel@lists.osgeo.org</a><br><a href="https://lists.osgeo.org/mailman/listinfo/postgis-devel" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-devel</a><o:p></o:p></p></blockquote></div><p class=MsoNormal><br clear=all><o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><p class=MsoNormal>-- <o:p></o:p></p><div><div><div><div><p class=MsoNormal>Darafei Praliaskouski<o:p></o:p></p></div><div><p class=MsoNormal>Support me: <a href="http://patreon.com/komzpa" target="_blank">http://patreon.com/komzpa</a><o:p></o:p></p></div></div></div></div></div></div></div></div></div></body></html>