Skip to content

Instantly share code, notes, and snippets.

@baffioso
Created August 13, 2017 05:50
Show Gist options
  • Select an option

  • Save baffioso/eb61d5619edc1d7df93ae6c3cf98f683 to your computer and use it in GitHub Desktop.

Select an option

Save baffioso/eb61d5619edc1d7df93ae6c3cf98f683 to your computer and use it in GitHub Desktop.
Hent data fra DST og join på kommuner
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# tilføj kommune lag (Denne sti skal sættes til data folderen i statistikbank plugin mappen)
geom_path = '/home/baffioso/.qgis2/python/plugins/statistikbanken-treewidget/data/kommune.geojson'
kom = QgsVectorLayer(geom_path, 'kommune', 'ogr')
QgsMapLayerRegistry.instance().addMapLayer(kom)
# tilføj DST data (her bruges GET request)
uri = 'CSV:/vsicurl_streaming/http://api.statbank.dk/v1/data/folk1a/CSV?valuePresentation=Code&delimiter=Semicolon&OMR%C3%85DE=*&Tid=2017K2'
dst = QgsVectorLayer(uri, 'folk1a', 'ogr')
QgsMapLayerRegistry.instance().addMapLayer(dst)
#Lav join mellem kommunekode (Vi skal finde ud af om kommunekode altid hedder 'OMRÅDE' hos DST)
omr = u'OMRÅDE'
komkode = 'KOMKODE'
joinObject = QgsVectorJoinInfo()
joinObject.joinLayerId = dst.id()
joinObject.joinFieldName = omr
joinObject.targetFieldName = komkode
joinObject.memoryCache = True
kom.addJoin(joinObject)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment