Skip to content
This repository has been archived by the owner on Jun 11, 2019. It is now read-only.

natural_cities script added #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions scripts/nat_cities.py
Original file line number Diff line number Diff line change
@@ -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)

1 change: 1 addition & 0 deletions scripts/nat_cities.py.help
Original file line number Diff line number Diff line change
@@ -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"}