[gdal-dev] Dissolve large amount of geometries

Jon Morris Jon.Morris at jbarisk.com
Fri Jun 29 03:01:54 PDT 2018


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.

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.

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.

Are there any plans for a Dissolve method on OGRLayer?

Jon

From: gdal-dev <gdal-dev-bounces at lists.osgeo.org> On Behalf Of Paul Meems
Sent: 29 June 2018 09:51
To: gdal-dev at lists.osgeo.org
Subject: Re: [gdal-dev] Dissolve large amount of geometries


Thanks Even for the suggestion.

We already thought about polygonizing the raster. But then I would have less control about where the vector geometry is created.
The squares/rectangle need to align with the tractor tracks/path.

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.
Making them less regular in the field.
I've attached an image I manually created with Inkscape for some clarification.

[tracks.png]
Of course, the whole field will have the green rectangles.
I have not yet created the algorithm to create these non-fishnet rectangles, but that is the end goal.
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.

Regards,

Paul

Op do 28 jun. 2018 om 13:25 schreef Even Rouault <even.rouault at spatialys.com<mailto:even.rouault at spatialys.com>>:
On jeudi 28 juin 2018 12:53:27 CEST Paul Meems wrote:
> Hi list,
>
> I've been working on this for months (off and on) and still no satisfying
> outcome.
> Either the process takes too long (multiple hours) or the result has
> invalid geometries.
>
> I want to try a different angle now. Instead of asking technical questions
> I want to explain what I try to do. Hopefully, somebody has a
> suggestion/hint which gives me some new insights.
>
> I have a high-resolution geotiff (drone image). And I need to create a
> taskmap in shapefile format.
> This taskmap is used in the tractor (precision farming) for variable
> spraying crop protection agents or variable fertilization using GPS, etc.
>
> The user starts by giving the precision (width and height) of the taskmap.
> I then create a fishnet over the tiff using the given width and height.
> Typical values can 1 by 1 meter or less. This results in a dataset with a
> lot of square/rectangles (1.5 - 2 million). Next step is to rotate the
> fishnet to align with the tractor path and clip with the field border. Then
> for each geometry, I get the pixel values from the tiff inside the
> geometry. I calculate the average and add this value as 'Rating' to the
> geometry.
> This process is fast enough, about 20-30 seconds.
>
> Next step is the slow part.
> I need to merge the adjacent geometries with the same rating. Multipolygons
> are not needed. If created I will break them apart later.
>
> Of course, I tried using GDAL+GEOS and the result seems OK, but it takes
> hours to finish.
>
> Reading my long description, how would you handle this challenge?
> I'm open to any suggestion.

What about rotating your raster so that the fishnet is horizontal/vertical
lines in that rotated raster ? Then you could clip, resample it to desired
resolution. And you would use gdal_polygonize, which would merge the cells of
same value quickly


--
Spatialys - Geospatial professional services
http://www.spatialys.com

T +44 (0) 1756 799919
www.jbarisk.com<http://www.jbarisk.com>

[Visit our website]<http://www.jbarisk.com> [http://www.jbagroup.co.uk/imgstore/JBA-Email-Sig-Icons-LINKEDIN.png] <https://www.linkedin.com/in/jon-morris-a2897b4/>  [Follow us on Twitter] <https://twitter.com/jbarisk>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20180629/a3917062/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 55474 bytes
Desc: image002.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20180629/a3917062/attachment-0001.png>


More information about the gdal-dev mailing list