Tu pregunta me hizo curioso.
Esta solución solo funciona para QGIS 2.x en la consola de Python
Como mencioné en mi comentario aquí, es mi idea crear el arco de líneas con Python.
Tengo dos capas de puntos:
yo. Uno que tiene la capital (id, capital)
ii. Uno que tiene las ciudades (id, ciudad, viajeros)
La cantidad de viajeros se "separa en billetes" y estas serán las líneas que construirán el arco. Entonces, 371 viajeros son una combinación de 3x100, 1x50, 2x10 y 1x1 y en total 7 billetes. Posteriormente, las líneas se diseñan con un estilo basado en reglas.
Aquí está el código:
from qgis.gui import *
from qgis.utils import *
from qgis.core import *
from PyQt4 import QtGui, uic
from PyQt4.QtGui import *
from PyQt4.QtCore import *
for lyr in QgsMapLayerRegistry.instance().mapLayers().values():
if lyr.name() == "capital":
capital_layer = lyr
for lyr in QgsMapLayerRegistry.instance().mapLayers().values():
if lyr.name() == "town":
town_layer = lyr
# creating the memory layer
d_lyr = QgsVectorLayer('LineString', 'distance', 'memory')
QgsMapLayerRegistry.instance().addMapLayer(d_lyr)
prov = d_lyr.dataProvider()
prov.addAttributes( [ QgsField("id", QVariant.Int), QgsField("banknote",QVariant.Int)])
# function to create the banknotes
def banknoteOutput(number):
number_list = []
number_list.append(number)
banknote_count = []
temp_list = []
banknote_list = []
for n in number_list:
total_sum = 0
total = int(n/100)
total_sum = total_sum + total
if total > 0:
banknote_count.append([total, 100])
n = n-(total*100)
total = int(n/50)
total_sum = total_sum + total
if total > 0:
banknote_count.append([total, 50])
n = n-(total*50)
total = int(n/10)
total_sum = total_sum + total
if total > 0:
banknote_count.append([total, 10])
n = n-(total*10)
total = int(n/5)
total_sum = total_sum + total
if total > 0:
banknote_count.append([total, 5])
n = n-(total*5)
total = int(n/1)
total_sum = total_sum + total
if total > 0:
banknote_count.append([total, 1])
for i in banknote_count:
temp_list.append(i*i[0])
banknote_list = [item for sublist in temp_list for item in sublist][1::2]
return banknote_list
# creating lines with the amount of banknotes
for capital in capital_layer.getFeatures():
for town in town_layer.getFeatures():
commuter_splitting = banknoteOutput(town['commuters'])
for i,banknote in enumerate(commuter_splitting):
angle = 2
distance = QgsDistanceArea()
distance.measureLine(capital.geometry().asPoint(), town.geometry().asPoint())
vect = QgsFeature()
vect.setGeometry(QgsGeometry.fromPolyline([capital.geometry().asPoint(), town.geometry().asPoint()]))
vect.geometry().rotate(0+(i*angle), capital.geometry().asPoint())
vect.setAttributes([int(town["id"]), int(banknote)])
prov.addFeatures([vect])
d_lyr.updateExtents()
d_lyr.triggerRepaint()
d_lyr.updateFields()
El resultado podría verse así:
ACTUALIZACIÓN: distinción hombre / mujer
Resultados en 4 capas de memoria.
from qgis.gui import *
from qgis.utils import *
from qgis.core import *
from PyQt4 import QtGui, uic
from PyQt4.QtGui import *
from PyQt4.QtCore import *
for lyr in QgsMapLayerRegistry.instance().mapLayers().values():
if lyr.name() == "capital":
capital_layer = lyr
for lyr in QgsMapLayerRegistry.instance().mapLayers().values():
if lyr.name() == "town":
town_layer = lyr
# function to create the banknotes
def banknoteOutput(number):
number_list = []
number_list.append(number)
banknote_count = []
temp_list = []
banknote_list = []
for n in number_list:
total_sum = 0
total = int(n/100)
total_sum = total_sum + total
if total > 0:
banknote_count.append([total, 100])
n = n-(total*100)
total = int(n/50)
total_sum = total_sum + total
if total > 0:
banknote_count.append([total, 50])
n = n-(total*50)
total = int(n/10)
total_sum = total_sum + total
if total > 0:
banknote_count.append([total, 10])
n = n-(total*10)
total = int(n/5)
total_sum = total_sum + total
if total > 0:
banknote_count.append([total, 5])
n = n-(total*5)
total = int(n/1)
total_sum = total_sum + total
if total > 0:
banknote_count.append([total, 1])
for i in banknote_count:
temp_list.append(i*i[0])
banknote_list = [item for sublist in temp_list for item in sublist][1::2]
return banknote_list
# creating the male memory layer
cmt_male = QgsVectorLayer('LineString', 'Commuters_Male', 'memory')
QgsMapLayerRegistry.instance().addMapLayer(cmt_male)
prov_male = cmt_male.dataProvider()
prov_male.addAttributes( [ QgsField("id", QVariant.Int), QgsField("banknote",QVariant.Int)])
# creating the male polygon memory layer
cmt_male_polygon = QgsVectorLayer('Polygon', 'Commuters_Male_Poly', 'memory')
QgsMapLayerRegistry.instance().addMapLayer(cmt_male_polygon)
prov_cmt_male_polygon = cmt_male_polygon.dataProvider()
prov_cmt_male_polygon.addAttributes( [ QgsField("id", QVariant.Int), QgsField("banknote",QVariant.Int)])
# creating lines with the amount of banknotes
for capital in capital_layer.getFeatures():
for town in town_layer.getFeatures():
commuter_splitting = banknoteOutput(town['cmt_male'])
points = []
for i,banknote in enumerate(reversed(commuter_splitting)):
angle = 2
distance = QgsDistanceArea()
distance.measureLine(capital.geometry().asPoint(), town.geometry().asPoint())
vect = QgsFeature()
vect.setGeometry(QgsGeometry.fromPolyline([capital.geometry().asPoint(), town.geometry().asPoint()]))
vect.geometry().rotate(0+(i*angle), capital.geometry().asPoint())
vect.setAttributes([int(town["id"]), int(banknote)])
points.append(vect.geometry().asPolyline()[1])
prov_male.addFeatures([vect])
polygon = QgsFeature()
points.insert(0,capital.geometry().asPoint())
points.insert(len(points),capital.geometry().asPoint())
polygon.setGeometry(QgsGeometry.fromPolygon([points]))
polygon.setAttributes([1, 2])
prov_cmt_male_polygon.addFeatures([polygon])
cmt_male.updateExtents()
cmt_male.triggerRepaint()
cmt_male.updateFields()
cmt_male_polygon.updateExtents()
cmt_male_polygon.triggerRepaint()
cmt_male_polygon.updateFields()
# creating the female memory layer
cmt_female = QgsVectorLayer('LineString', 'Commuters_Female', 'memory')
QgsMapLayerRegistry.instance().addMapLayer(cmt_female)
prov_female = cmt_female.dataProvider()
prov_female.addAttributes( [ QgsField("id", QVariant.Int), QgsField("banknote",QVariant.Int)])
# creating the female polygon memory layer
cmt_female_polygon = QgsVectorLayer('Polygon', 'Commuters_Female_Poly', 'memory')
QgsMapLayerRegistry.instance().addMapLayer(cmt_female_polygon)
prov_cmt_female_polygon = cmt_female_polygon.dataProvider()
prov_cmt_female_polygon.addAttributes( [ QgsField("id", QVariant.Int), QgsField("banknote",QVariant.Int)])
# creating lines with the amount of banknotes
for capital in capital_layer.getFeatures():
for town in town_layer.getFeatures():
commuter_splitting = banknoteOutput(town['cmt_female'])
points = []
for i,banknote in enumerate(commuter_splitting):
angle = 2
distance = QgsDistanceArea()
distance.measureLine(capital.geometry().asPoint(), town.geometry().asPoint())
vect = QgsFeature()
vect.setGeometry(QgsGeometry.fromPolyline([capital.geometry().asPoint(), town.geometry().asPoint()]))
vect.geometry().rotate(-angle-(i*angle), capital.geometry().asPoint())
vect.setAttributes([int(town["id"]), int(banknote)])
points.append(vect.geometry().asPolyline()[1])
prov_female.addFeatures([vect])
polygon = QgsFeature()
points.insert(0,capital.geometry().asPoint())
points.insert(len(points),capital.geometry().asPoint())
polygon.setGeometry(QgsGeometry.fromPolygon([points]))
polygon.setAttributes([1, 2])
prov_cmt_female_polygon.addFeatures([polygon])
cmt_female.updateExtents()
cmt_female.triggerRepaint()
cmt_female.updateFields()
cmt_female_polygon.updateExtents()
cmt_female_polygon.triggerRepaint()
cmt_female_polygon.updateFields()
El resultado podría verse así:
Una cosa que no es ideal desde el punto de vista cartográfico:
El tamaño de un arco de línea puede ser irritante a primera vista, en la forma en que un arco más grande podría representar a más viajeros. Un arco puede ser más grande con menos viajeros (289 viajeros / 11 billetes) que otro con más viajeros (311 viajeros / 5 billetes).