0

I use QGIS 3.10 (Python 3.7 via the console) and want to automate a few processes through a Python script (I'm a beginner in programming with Python). I have a layer with many polygons ('polygons') and want to create the centerline between them. When I do this step without a script I use the HCMGIS plugin --> "Geometry Processing" --> "Centerline in polygons' gaps". How can I call this function in my script?

1

In HCMGIS ver 20.4.20 (approved soon), try this in QGIS Console:

from HCMGIS.hcmgis_library import *
input = "D:\\osm\\block.shp" # your polygon input
output = "D:\\osm\\centerline.shp" #  your centerline output in .sqlite, .shp, .geojson, .gpkg,  or kml
hcmgis_centerline(input, 1, True, 2,output,status_callback = None)
##hcmgis_centerline(layer,density,chksurround,distance,output,status_callback = None):
##density (float value): densify geometries with given an interval (in this case the density is 1 meter). Smaller density value returns smoother centerline but slower
##chksurround: if chksurround is True, then the function will also create a surrounding 'centerline' with a "distance" to the bounding box of building block

You can also call other functions of HCMGIS Plugin Library in QGIS Python Console or even in stand alone PyQGIS application in HCMGIS Plugin Library Call

Call QGIS Plugin Library in QGIS Pythong Console

| improve this answer | |
1

I'm going to upload new version of HCMGIS Plugin and I will show u how to call HCMGIS function in QGIS Python console or PyQGIS as soon as it's approved on HCMGIS Plugin repo.

| improve this answer | |
  • I use the hcmgis_centerline function (and it works great). The only problem I have is, that I can not change the value of "density". It is always =1 [m] but I need smother centerlines (density < 1). I have polygons (e.g. rectangles with four edges). Is there a way to solve this problem? – Julz_Mos Jun 29 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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