51 votes
Accepted

How to polygonize raster to shapely polygons

Use rasterio of Sean Gillies. It can be easily combined with Fiona (read and write shapefiles) and shapely of the same author. In the script rasterio_polygonize.py the beginning is import rasterio ...
  • 52.9k
25 votes

Converting line to polygon using QGIS

The "Polygonize" tool from the Processing toolbox still works fine for me on simple lines: It is however necessary that the lines intersect, or share common vertices. And lines should have ...
  • 75.7k
17 votes

How to speed up raster to polygon conversion in R?

There is a "new" method from the stars package, which revolutionized the workflow for me (I was using the gdal_polygonizeR function previously). It has been faster than the John Baumgartner solution ...
  • 365
11 votes
Accepted

QGIS 2.14.6 Processing Extension, 'Polygonize' Tool missing

As the Processing plugin has become core, you don't need the .qgis2/ version anymore. In the recent QGIS version, the plugin can be found in (for example, in QGIS 2.16.1 standalone): C:/Program ...
  • 73.8k
9 votes
Accepted

Convert a group of lines into a single polygone to style it

If you need to handle the polylines just for styling, you don't need to manipulate the geometry. E.g. you want to get rid of overlapping edges at a street intersection, you can to this by activating "...
  • 827
9 votes
Accepted

Cannot select input layers for the "Polygonize" tool in QGIS

When you search for Polygonize in the Processing Toolbox, there appear several tools. 1) Polygonize tool converts line layer to polygon layer, turning an area inside three line segments into a ...
  • 29.6k
8 votes

Why is GDALPolygonize so much slower than ArcGIS Raster to Polygon?

I have the same experience. The algorithm is really slow for huge rasters, although quite fast for smaller ones. There is one possible workaround: Split huge raster file into smaller files by ...
8 votes

How to polygonize raster to shapely polygons

Here is my implementation. from osgeo import ogr, gdal, osr from osgeo.gdalnumeric import * from osgeo.gdalconst import * import fiona from shapely.geometry import shape import rasterio.features #...
8 votes
Accepted

How to speed up raster to polygon conversion in R?

Gdal Installation Install Gdal command line tools and check to see if its binaries are added to path environment variable. e.g. in windows: open Run and type: rundll32.exe sysdm.cpl,...
8 votes
Accepted

Converting Lines to Polygons in QGIS produces Sliver Polygons

Got the exact polygons as desired using the 'Polygonize' algorithm (Processing Toolbox --> QGIS Geoalgorithms --> Polygonize) in the python console. import processing polygon_path = "C:\\Documents ...
  • 967
8 votes
Accepted

Polygonizing a raster yields lots of little squares?

The reason for this is that while you see yellow pixels, or pink pixels, QGIS sees thousands of discrete colours Zoom in really close to scanned map you'll see lots of noise - neighbouring pixels ...
  • 19.9k
7 votes

Converting line to polygon using QGIS

Just a hint if you can't find the Polygonize tool. In my QGIS 2.18.3 installation (Windows) I could not find the Polygonize tool at Vector geometry tools within the Toolbox. It took me some time to ...
  • 320
7 votes

Converting raster to vector and creating polygons based on each pixel in QGIS

Yet another option would be SAGA Raster values to points tool (QGIS Processing Toolbox | SAGA | Vector <-> raster). Choose [1] cells as Type option. SAGA - Raster values to points note white ...
  • 29.6k
7 votes
Accepted

Divide a polygon into multiple small polygons using a MultiLineString

You may not need to use this MultiLineString variable for what you aim at. This works: from shapely.geometry import Polygon, LineString from shapely.ops import linemerge, unary_union, polygonize poly ...
  • 10.1k
7 votes
Accepted

How to extract the boundaries of Shapely MultiPoint?

For a grid-like multipoint, you can use buffer method to get the boundary of points as a polygon. For a multipoint geometry with 100 meters between each point as in the image, the following script ...
6 votes
Accepted

Raster to vector (polygons) with generalisation

You can use a Majority Filter followed by Polygonize for this type of operation. QGIS has a majority filter in the SAGA toolbox. Polygonize is found in the Raster tab > Conversion > Polygonize (...
  • 50.9k
6 votes
Accepted

It is possible to get single polygon using gdal.Polygonize()?

From the documentation: The algorithm will generally produce very dense polygon geometries, with edges that follow exactly on pixel boundaries for all non-interior pixels. For non-thematic ...
  • 56.6k
6 votes
Accepted

Convert multiple polylines to polygons in QGIS

Using QGIS processing: v.clean [snap] Polyline test The threshold is determined by attempts: final results To get the polygons: polygonize polygons
  • 4,071
6 votes
Accepted

sf lines to polygons with holes

The problem is that you have created a GEOMETRYCOLLECTION which can be an unstructured set of linear features, in other words there's no concept of holes and islands. What you want is a MULTIPOLYGON....
  • 56.7k
6 votes
Accepted

Vectorize raster

I found a solution using USGS landcover dataset and gdal_sieve . The raw dataset looks like this: And using gdal_sieve led to that: Which is exactly what I wanted :) . Now I "just" have to choose ...
  • 584
6 votes
Accepted

Create polygons (representing boundaries) from lines

Starting with nc borders from the example(st_read) code, I'll first make a set of lines like in your data and then put them back together again. So we start with 100 North Carolina polygons in a ...
  • 56.7k
6 votes
Accepted

Transforming line into polygon with Geometry Generator

Let's assume there is a polyline layer "line", see image below. Proceed with RMT > Symbology > Single Symbol > Line > Geometry Generator Use the following code make_polygon($...
  • 27.3k
6 votes
Accepted

How to polygonize raster with range of values?

What you want to do is the re-classify the raster before polygonizing. You can GRASS tool r.recode for that (available in QGIS). For a solution with raster calculator, see below. Using GRASS r.recode ...
  • 52.3k
5 votes

Building a polygon over a reachable area

Setting aside the GeoJSON serialization, the following takes about 6.3 seconds on my laptop: SELECT ST_MakePolygon( ST_ExteriorRing( (ST_Dump( ST_Union( ST_Buffer(geom, ...
  • 12.7k
5 votes

Converting line to polygon using QGIS

If the polylines overlap each other, Polygonize tool cannot handle it as follows: However Lines to polygons tool works as expected as follows:
5 votes

Gdal Polygonize, empty attribute table

Found out that the reason the attribute table was empty was due to gdal.Polygonize( band, None, outLayer, -1, [], callback=None ) Updated it to gdal.Polygonize( band, None, outLayer, 0, [], ...
  • 81
5 votes
Accepted

Smoothing raster with binary cell values

Similar to what @WhiteboxDev suggested, another filter type that could be used is a sieve filter. Instead of looking at whether the 0s or 1s "win" for a given region, it looks at the number of ...
5 votes

Smoothing raster with binary cell values

In addition to the use of a majority filter, there is another alternative approach that I will list below. This approach is more involved than simply filtering the raster and should only be used when ...
  • 10.9k
5 votes
Accepted

Merging cluster of points into polygons

This will work when each cluster has an attribute that defines it. If there is no such attribute, you can achieve it by means of "DBSCAN clustering" geoalgorithm. Clusters point features ...
  • 27.3k
5 votes

QGIS - How do I select features in a particular location precisely, the location is a raster

Open the Raster calculator tool and use this expression to create a mask, "layer@band" != no-data. Replace layer with the name of your raster, band with the number of your band and no-data ...
  • 2,391

Only top scored, non community-wiki answers of a minimum length are eligible