Created
August 13, 2017 05:50
-
-
Save baffioso/eb61d5619edc1d7df93ae6c3cf98f683 to your computer and use it in GitHub Desktop.
Hent data fra DST og join på kommuner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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