2

I have a line layer representing a street grid. I need to select a bunch of these street segments and turn them into a polygon. I have tried using Vector > Geometry > Lines to Polygons, but the results aren't what I'm hoping for:

Input Selected street segments

Expected polygon (blue hatched area) Expected polygon

"Lines to Polygons" result Result

This GitHub issue comment suggests that I may want to be using Polygonize instead "Lines to Polygons." When I do that in the Processing Toolbox, checking "Selected features only," no polygons are created:

Input parameters:
{ 'INPUT' : QgsProcessingFeatureSourceDefinition('/Users/nick/Projects/gannett-all/gannett-pipeline/gis_data_test/1930-40/stgrids_edited_both/stgrids_edited_both/BirminghamAL_stgird.shp', selectedFeaturesOnly=True, featureLimit=-1, geometryCheck=QgsFeatureRequest.GeometryAbortOnInvalid), 'KEEP_FIELDS' : False, 'OUTPUT' : 'TEMPORARY_OUTPUT' }

Collecting lines…
Noding lines…
Polygonizing…
No polygons were created.
Execution completed in 0.27 seconds
Results:
{'NUM_POLYGONS': 0, 'OUTPUT': 'Polygons_17441c13_d43c_4507_9f2e_1ac7b9321dba'}

Loading resulting layers
Algorithm 'Polygonize' finished

Here is a GeoJSON of the selected features. What am I doing wrong?

1

1 Answer 1

2

The problem was that there were tiny gaps in my street segments. For example, the long top segment (the city limits) were separated from the vertical connector street in the center by 6cm.

I diagnosed the problem using a function selection on a layer I had created with just the relevant street segments.

I then used Processing Toolbox > Vector geometry > Snap geometries to layer to fix the gaps. (Learn more in answers to this SO question.) Once the gaps were gone, I used Vector geometry > Polygonize to generate the polygon from the snapped version of the street grid, being sure to specify that I only want to use the selected features in the input layer. Et voilà!

Polygon as expected

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.