<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)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><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:0cm;
        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;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Arial",sans-serif;
        color:black;
        font-weight:normal;
        font-style:normal;
        text-decoration:none none;}
.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-family:"Arial",sans-serif;color:black;mso-fareast-language:EN-US">We recently had a requirement to dissolve a large amount of geometries (using python) - it's not quite the same as your situation, but involved taking one
 postcode layer and one building layer covering the whole UK and dissolving to have one building multipolygon per postcode.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black;mso-fareast-language:EN-US">Unfortunately OGRLayer does not have a Dissolve method, unlike Intersect, Erase, Clip, etc., which are really fast. We tried iterating through features
 and dissolving each one, but it was taking a long time.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black;mso-fareast-language:EN-US">In the end (and I'm sorry to say this here ;-)), we used geopandas - the dissolve method is very fast, but you have to convert the OGRLayer to a geodataframe,
 calling ExportToJSON on each feature. This step is slow, but the whole UK can be processed in about 2h. Not sure how long calling dissolve on each feature would have taken, because I killed it after about a day.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black;mso-fareast-language:EN-US">Are there any plans for a Dissolve method on OGRLayer?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black;mso-fareast-language:EN-US">Jon<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> gdal-dev <gdal-dev-bounces@lists.osgeo.org>
<b>On Behalf Of </b>Paul Meems<br>
<b>Sent:</b> 29 June 2018 09:51<br>
<b>To:</b> gdal-dev@lists.osgeo.org<br>
<b>Subject:</b> Re: [gdal-dev] Dissolve large amount of geometries<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><br clear="all">
<o:p></o:p></p>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">Thanks Even for the suggestion.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">We already thought about polygonizing the raster. But then I would have less control about where the vector geometry is created.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">The squares/rectangle need to align with the tractor tracks/path.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The scenario I described is the first version: creating a fishnet. The next version will be more complicated because it will really create the square/rectangle along the tracks.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Making them less regular in the field. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I've attached an image I manually created with Inkscape for some clarification.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><img width="562" height="444" style="width:5.8541in;height:4.625in" id="_x0000_i1025" src="cid:image002.png@01D40F97.9FB059C0" alt="tracks.png"><o:p></o:p></p>
</div>
<p class="MsoNormal">Of course, the whole field will have the green rectangles.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">I have not yet created the algorithm to create these non-fishnet rectangles, but that is the end goal.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">That's why I can't use polygonize (at least I think I can't) but need to create the geometries first, then fill them with the pixel values and next merge/dissolve the geometries with the same values.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Regards,<br>
<br>
Paul<o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">Op do 28 jun. 2018 om 13:25 schreef Even Rouault <<a href="mailto:even.rouault@spatialys.com">even.rouault@spatialys.com</a>>:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal">On jeudi 28 juin 2018 12:53:27 CEST Paul Meems wrote:<br>
> Hi list,<br>
> <br>
> I've been working on this for months (off and on) and still no satisfying<br>
> outcome.<br>
> Either the process takes too long (multiple hours) or the result has<br>
> invalid geometries.<br>
> <br>
> I want to try a different angle now. Instead of asking technical questions<br>
> I want to explain what I try to do. Hopefully, somebody has a<br>
> suggestion/hint which gives me some new insights.<br>
> <br>
> I have a high-resolution geotiff (drone image). And I need to create a<br>
> taskmap in shapefile format.<br>
> This taskmap is used in the tractor (precision farming) for variable<br>
> spraying crop protection agents or variable fertilization using GPS, etc.<br>
> <br>
> The user starts by giving the precision (width and height) of the taskmap.<br>
> I then create a fishnet over the tiff using the given width and height.<br>
> Typical values can 1 by 1 meter or less. This results in a dataset with a<br>
> lot of square/rectangles (1.5 - 2 million). Next step is to rotate the<br>
> fishnet to align with the tractor path and clip with the field border. Then<br>
> for each geometry, I get the pixel values from the tiff inside the<br>
> geometry. I calculate the average and add this value as 'Rating' to the<br>
> geometry.<br>
> This process is fast enough, about 20-30 seconds.<br>
> <br>
> Next step is the slow part.<br>
> I need to merge the adjacent geometries with the same rating. Multipolygons<br>
> are not needed. If created I will break them apart later.<br>
> <br>
> Of course, I tried using GDAL+GEOS and the result seems OK, but it takes<br>
> hours to finish.<br>
> <br>
> Reading my long description, how would you handle this challenge?<br>
> I'm open to any suggestion.<br>
<br>
What about rotating your raster so that the fishnet is horizontal/vertical <br>
lines in that rotated raster ? Then you could clip, resample it to desired <br>
resolution. And you would use gdal_polygonize, which would merge the cells of <br>
same value quickly<br>
<br>
<br>
-- <br>
Spatialys - Geospatial professional services<br>
<a href="http://www.spatialys.com" target="_blank">http://www.spatialys.com</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
<p><strong><span style="color: #f6a125; font-family:arial;">T</span></strong><span style="text-decoration: none; color: #000000; font-family:arial;"> +44 (0) 1756 799919</span><br>
<a style="text-decoration: none; color: #f6a125; font-family:arial;" href="http://www.jbarisk.com">www.jbarisk.com</a></p>
<p><a href="http://www.jbarisk.com"><img src="http://www.jbagroup.co.uk/imgstore/JBA-Email-Sig-Icons-JBA.png" alt="Visit our website" width="33" height="26"></a> <a href="https://www.linkedin.com/in/jon-morris-a2897b4/"><img src="http://www.jbagroup.co.uk/imgstore/JBA-Email-Sig-Icons-LINKEDIN.png" alt="" height="26"></a>
<a href="https://twitter.com/jbarisk"><img src="http://www.jbagroup.co.uk/imgstore/JBA-Email-Sig-Icons-TWITTER.png" alt="Follow us on Twitter" width="33" height="26"></a></p>
</body>
</html>