From ea5bf9f6d98abcb9ef91da61419a8995e023b040 Mon Sep 17 00:00:00 2001 From: niels-flohr <34693249+niels-flohr@users.noreply.github.com> Date: Fri, 22 Dec 2017 13:22:03 +0100 Subject: [PATCH] Add files via upload --- scripts/nat_cities.py | 50 ++++++++++++++++++++++++++++++++++++++ scripts/nat_cities.py.help | 1 + 2 files changed, 51 insertions(+) create mode 100644 scripts/nat_cities.py create mode 100644 scripts/nat_cities.py.help diff --git a/scripts/nat_cities.py b/scripts/nat_cities.py new file mode 100644 index 0000000..36e126a --- /dev/null +++ b/scripts/nat_cities.py @@ -0,0 +1,50 @@ +#---------------------------------------------------------------------------------------- +# Natural Cities Algorithm # +# # +# Creates Natural City polygons out of input point vector file # +# more Information on methodology: # +# *jiang/miao 2014: https://arxiv.org/pdf/1401.6756.pdf # +# *jiang 2015: https://www.sciencedirect.com/science/article/pii/S026427511400198X # +# # +# requires saga and python-shapely # +#---------------------------------------------------------------------------------------- + +##natural_cities=name +##points=vector +##linelength=output vector +##natural_cities=output vector +##outputCRS=crs + +# create tin +tin=processing.runalg('qgis:delaunaytriangulation', points,None) + +# convert tin-polygons to lines +polygonToLines=processing.runalg('qgis:polygonstolines', tin['OUTPUT'],None) + +# explode lines +explodeLines=processing.runalg('qgis:explodelines', polygonToLines['OUTPUT'],None) + +# delete duplicates +deleteDup=processing.runalg('qgis:deleteduplicategeometries', explodeLines['OUTPUT'],None) + +# reproject for statistics +reproj=processing.runalg('qgis:reprojectlayer', deleteDup['OUTPUT'],outputCRS,None) + +#get lineproperties (requires saga geoalgorithms) +lineProp=processing.runalg('saga:lineproperties', reproj['OUTPUT'],False,False,True,linelength) + +#calc basic statistics +basicStat=processing.runalg('qgis:basicstatisticsfornumericfields', lineProp['OUTPUT'],'length',None) + +# extract mean (=cut-off-value) +extractbyAttribute=processing.runalg('qgis:extractbyattribute', lineProp['OUTPUT'],'length',4,basicStat['MEAN'],None) + +# create polgons out of line (requires python-shapely) +polygonize=processing.runalg('qgis:polygonize',extractbyAttribute['OUTPUT'],False,True,None) + +# dissolve +diss=processing.runalg('qgis:dissolve', polygonize['OUTPUT'],True,None,None) + +# multipartsToSingleParts +mtoSParts=processing.runalg('qgis:multiparttosingleparts', diss['OUTPUT'],natural_cities) + diff --git a/scripts/nat_cities.py.help b/scripts/nat_cities.py.help new file mode 100644 index 0000000..67a35d6 --- /dev/null +++ b/scripts/nat_cities.py.help @@ -0,0 +1 @@ +{"linelength": "", "ALG_DESC": "Creates Natural City polygons out of input point vector file \n\nmore Information on methodology: \njiang/miao 2014: https://arxiv.org/pdf/1401.6756.pdf \njiang 2015: https://www.sciencedirect.com/science/article/pii/S026427511400198X\n\n# requires saga and python-shapely ", "line_cropped": "", "ALG_CREATOR": "https://github.com/niels-flohr", "outputCRS": "choose output crs", "points": "requires point shapefile", "ALG_VERSION": "1", "ALG_HELP_CREATOR": "", "natural_cities": "natural cities polygon shapefile"} \ No newline at end of file