Thursday, October 19, 2023

Plotting NUTS-2 maps from GAMS

 NUTS-2 regions are statistical subnational regions (often provinces), mainly for the EU and UK [1]. 


NUTS hierarchy (from [1])

In [2] we can find mapping information in the form of Shapefiles[3] and related formats. I used the GeoJSON[4] format, and created a Python notebook script to extract a GAMS set from that file. The file is reproduced in the appendix below. The NUTS-2 codes form the set elements, and the name is stored as explanatory text. There is an option to generate Latin names instead of using the native alphabet. The Latin names are also inside the geojson file. E.g. we have: 

EL65  'Πελοπόννησος'

which is in the Greek alphabet. Using the Latin name, this would look like:

EL65  'Peloponnisos'

I like to have this set available for use in a GAMS model, so we don't have to guess what the plottable regions are. Furthermore, we can use this set as a domain, so GAMS will check we don't use an unknown region. The include file is written using UTF-8 encoding to allow accurate representation of the region names. In GAMS, we can use unicode string only for set elements and explanatory text. Programming languages like Python and Julia allow unicode identifiers, but GAMS does not.

To make a map, I generate from GAMS an HTML document that uses the d3 Javascript library [5]. Using random values:

*-----------------------------------------------------------------------
* random data
*-----------------------------------------------------------------------
alias(r,nuts2);

parameter data(r) 'random data';
data(r) = uniform(0,100);
display data;

a demo map looks like:



The map is interactive. Hovering the mouse cursor over a region gives more information:

Again, this map can be configured to display the Latin names instead.

Conclusion


This is a simple tool to generate maps from GAMS model results. It is useful to produce quick visualizations. I have used this approach also for other projects, using different maps.


References


  1. NUTS - Nomenclature of territorial units for statistics, Background, https://ec.europa.eu/eurostat/web/nuts/background
  2. https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units/nuts
  3. Shapefile, https://en.wikipedia.org/wiki/Shapefile
  4. GeoJSON, https://en.wikipedia.org/wiki/GeoJSON
  5. https://d3js.org/

Appendix: Generated GAMS include file


*---------------------------------------------------------------

* Regions extracted from c:/users/erwin/nuts2map/nuts2.geojson

* Contents:

*   set  nuts2:  all nuts2 regions in the geojson file

*                ordered alphabetically

*

* Generated: 2023-10-18

*---------------------------------------------------------------

 

set nuts2 'NUTS2 regions' /

  AL01  'Veri'

  AL02  'Qender'

  AL03  'Jug'

  AT11  'Burgenland'

  AT12  'Niederösterreich'

  AT13  'Wien'

  AT21  'Kärnten'

  AT22  'Steiermark'

  AT31  'Oberösterreich'

  AT32  'Salzburg'

  AT33  'Tirol'

  AT34  'Vorarlberg'

  BE10  'Région de Bruxelles-Capitale/ Brussels Hoofdstedelijk Gewest'

  BE21  'Prov. Antwerpen'

  BE22  'Prov. Limburg (BE)'

  BE23  'Prov. Oost-Vlaanderen'

  BE24  'Prov. Vlaams-Brabant'

  BE25  'Prov. West-Vlaanderen'

  BE31  'Prov. Brabant Wallon'

  BE32  'Prov. Hainaut'

  BE33  'Prov. Liège'

  BE34  'Prov. Luxembourg (BE)'

  BE35  'Prov. Namur'

  BG31  'Северозападен'

  BG32  'Северен централен'

  BG33  'Североизточен'

  BG34  'Югоизточен'

  BG41  'Югозападен'

  BG42  'Южен централен'

  CH01  'Région lémanique'

  CH02  'Espace Mittelland'

  CH03  'Nordwestschweiz'

  CH04  'Zürich'

  CH05  'Ostschweiz'

  CH06  'Zentralschweiz'

  CH07  'Ticino'

  CY00  'Κύπρος'

  CZ01  'Praha'

  CZ02  'Střední Čechy'

  CZ03  'Jihozápad'

  CZ04  'Severozápad'

  CZ05  'Severovýchod'

  CZ06  'Jihovýchod'

  CZ07  'Střední Morava'

  CZ08  'Moravskoslezsko'

  DE11  'Stuttgart'

  DE12  'Karlsruhe'

  DE13  'Freiburg'

  DE14  'Tübingen'

  DE21  'Oberbayern'

  DE22  'Niederbayern'

  DE23  'Oberpfalz'

  DE24  'Oberfranken'

  DE25  'Mittelfranken'

  DE26  'Unterfranken'

  DE27  'Schwaben'

  DE30  'Berlin'

  DE40  'Brandenburg'

  DE50  'Bremen'

  DE60  'Hamburg'

  DE71  'Darmstadt'

  DE72  'Gießen'

  DE73  'Kassel'

  DE80  'Mecklenburg-Vorpommern'

  DE91  'Braunschweig'

  DE92  'Hannover'

  DE93  'Lüneburg'

  DE94  'Weser-Ems'

  DEA1  'Düsseldorf'

  DEA2  'Köln'

  DEA3  'Münster'

  DEA4  'Detmold'

  DEA5  'Arnsberg'

  DEB1  'Koblenz'

  DEB2  'Trier'

  DEB3  'Rheinhessen-Pfalz'

  DEC0  'Saarland'

  DED2  'Dresden'

  DED4  'Chemnitz'

  DED5  'Leipzig'

  DEE0  'Sachsen-Anhalt'

  DEF0  'Schleswig-Holstein'

  DEG0  'Thüringen'

  DK01  'Hovedstaden'

  DK02  'Sjælland'

  DK03  'Syddanmark'

  DK04  'Midtjylland'

  DK05  'Nordjylland'

  EE00  'Eesti'

  EL30  'Aττική'

  EL41  'Βόρειο Αιγαίο'

  EL42  'Νότιο Αιγαίο'

  EL43  'Κρήτη'

  EL51  'Aνατολική ΜακεδονίαΘράκη'

  EL52  'Κεντρική Μακεδονία'

  EL53  'Δυτική Μακεδονία'

  EL54  'Ήπειρος'

  EL61  'Θεσσαλία'

  EL62  'Ιόνια Νησιά'

  EL63  'Δυτική Ελλάδα'

  EL64  'Στερεά Ελλάδα'

  EL65  'Πελοπόννησος'

  ES11  'Galicia'

  ES12  'Principado de Asturias'

  ES13  'Cantabria'

  ES21  'País Vasco'

  ES22  'Comunidad Foral de Navarra'

  ES23  'La Rioja'

  ES24  'Aragón'

  ES30  'Comunidad de Madrid'

  ES41  'Castilla y León'

  ES42  'Castilla-La Mancha'

  ES43  'Extremadura'

  ES51  'Cataluña'

  ES52  'Comunitat Valenciana'

  ES53  'Illes Balears'

  ES61  'Andalucía'

  ES62  'Región de Murcia'

  ES63  'Ciudad de Ceuta'

  ES64  'Ciudad de Melilla'

  FI19  'Länsi-Suomi'

  FI1B  'Helsinki-Uusimaa'

  FI1C  'Etelä-Suomi'

  FI1D  'Pohjois- ja Itä-Suomi'

  FI20  'Åland'

  FR10  'Ile-de-France'

  FRB0  'Centre — Val de Loire'

  FRC1  'Bourgogne'

  FRC2  'Franche-Comté'

  FRD1  'Basse-Normandie'

  FRD2  'Haute-Normandie'

  FRE1  'Nord-Pas de Calais'

  FRE2  'Picardie'

  FRF1  'Alsace'

  FRF2  'Champagne-Ardenne'

  FRF3  'Lorraine'

  FRG0  'Pays de la Loire'

  FRH0  'Bretagne'

  FRI1  'Aquitaine'

  FRI2  'Limousin'

  FRI3  'Poitou-Charentes'

  FRJ1  'Languedoc-Roussillon'

  FRJ2  'Midi-Pyrénées'

  FRK1  'Auvergne'

  FRK2  'Rhône-Alpes'

  FRL0  'Provence-Alpes-Côte d’Azur'

  FRM0  'Corse'

  HR02  'Panonska Hrvatska'

  HR03  'Jadranska Hrvatska'

  HR05  'Grad Zagreb'

  HR06  'Sjeverna Hrvatska'

  HU11  'Budapest'

  HU12  'Pest'

  HU21  'Közép-Dunántúl'

  HU22  'Nyugat-Dunántúl'

  HU23  'Dél-Dunántúl'

  HU31  'Észak-Magyarország'

  HU32  'Észak-Alföld'

  HU33  'Dél-Alföld'

  IE04  'Northern and Western'

  IE05  'Southern'

  IE06  'Eastern and Midland'

  IS00  'Ísland'

  ITC1  'Piemonte'

  ITC2  'Valle d’Aosta/Vallée d’Aoste'

  ITC3  'Liguria'

  ITC4  'Lombardia'

  ITF1  'Abruzzo'

  ITF2  'Molise'

  ITF3  'Campania'

  ITF4  'Puglia'

  ITF5  'Basilicata'

  ITF6  'Calabria'

  ITG1  'Sicilia'

  ITG2  'Sardegna'

  ITH1  'Provincia Autonoma di Bolzano/Bozen'

  ITH2  'Provincia Autonoma di Trento'

  ITH3  'Veneto'

  ITH4  'Friuli-Venezia Giulia'

  ITH5  'Emilia-Romagna'

  ITI1  'Toscana'

  ITI2  'Umbria'

  ITI3  'Marche'

  ITI4  'Lazio'

  LI00  'Liechtenstein'

  LT01  'Sostinės regionas'

  LT02  'Vidurio ir vakarų Lietuvos regionas'

  LU00  'Luxembourg'

  LV00  'Latvija'

  ME00  'Црна Гора'

  MK00  'Северна Македонија'

  MT00  'Malta'

  NL11  'Groningen'

  NL12  'Friesland (NL)'

  NL13  'Drenthe'

  NL21  'Overijssel'

  NL22  'Gelderland'

  NL23  'Flevoland'

  NL31  'Utrecht'

  NL32  'Noord-Holland'

  NL33  'Zuid-Holland'

  NL34  'Zeeland'

  NL41  'Noord-Brabant'

  NL42  'Limburg (NL)'

  NO02  'Innlandet'

  NO06  'Trøndelag'

  NO07  'Nord-Norge'

  NO08  'Oslo og Viken'

  NO09  'Agder og Sør-Østlandet'

  NO0A  'Vestlandet'

  PL21  'Małopolskie'

  PL22  'Śląskie'

  PL41  'Wielkopolskie'

  PL42  'Zachodniopomorskie'

  PL43  'Lubuskie'

  PL51  'Dolnośląskie'

  PL52  'Opolskie'

  PL61  'Kujawsko-pomorskie'

  PL62  'Warmińsko-mazurskie'

  PL63  'Pomorskie'

  PL71  'Łódzkie'

  PL72  'Świętokrzyskie'

  PL81  'Lubelskie'

  PL82  'Podkarpackie'

  PL84  'Podlaskie'

  PL91  'Warszawski stołeczny'

  PL92  'Mazowiecki regionalny'

  PT11  'Norte'

  PT15  'Algarve'

  PT16  'Centro (PT)'

  PT17  'Área Metropolitana de Lisboa'

  PT18  'Alentejo'

  RO11  'Nord-Vest'

  RO12  'Centru'

  RO21  'Nord-Est'

  RO22  'Sud-Est'

  RO31  'Sud-Muntenia'

  RO32  'Bucureşti-Ilfov'

  RO41  'Sud-Vest Oltenia'

  RO42  'Vest'

  RS11  'Београдски регион'

  RS12  'Регион Војводине'

  RS21  'Регион Шумадије и Западне Србије'

  RS22  'Регион Јужне и Источне Србије'

  SE11  'Stockholm'

  SE12  'Östra Mellansverige'

  SE21  'Småland med öarna'

  SE22  'Sydsverige'

  SE23  'Västsverige'

  SE31  'Norra Mellansverige'

  SE32  'Mellersta Norrland'

  SE33  'Övre Norrland'

  SI03  'Vzhodna Slovenija'

  SI04  'Zahodna Slovenija'

  SK01  'Bratislavský kraj'

  SK02  'Západné Slovensko'

  SK03  'Stredné Slovensko'

  SK04  'Východné Slovensko'

  TR10  'İstanbul'

  TR21  'TekirdağEdirneKırklareli'

  TR22  'BalıkesirÇanakkale'

  TR31  'İzmir'

  TR32  'Aydın, Denizli, Muğla'

  TR33  'ManisaAfyonkarahisarKütahyaUşak'

  TR41  'Bursa, EskişehirBilecik'

  TR42  'KocaeliSakaryaDüzceBoluYalova'

  TR51  'Ankara'

  TR52  'Konya, Karaman'

  TR61  'Antalya, IspartaBurdur'

  TR62  'Adana, Mersin'

  TR63  'HatayKahramanmaraşOsmaniye'

  TR71  'KırıkkaleAksarayNiğdeNevşehirKırşehir'

  TR72  'Kayseri, SivasYozgat'

  TR81  'ZonguldakKarabükBartın'

  TR82  'KastamonuÇankırıSinop'

  TR83  'SamsunTokatÇorum, Amasya'

  TR90  'Trabzon, Ordu, Giresun, RizeArtvinGümüşhane'

  TRA1  'Erzurum, Erzincan, Bayburt'

  TRA2  'Ağrı, Kars, IğdırArdahan'

  TRB1  'Malatya, Elazığ, Bingöl, Tunceli'

  TRB2  'Van, MuşBitlis, Hakkari'

  TRC1  'Gaziantep, Adıyaman, Kilis'

  TRC2  'ŞanlıurfaDiyarbakır'

  TRC3  'Mardin, Batman, ŞırnakSiirt'

  UKC1  'Tees Valley and Durham'

  UKC2  'Northumberland and Tyne and Wear'

  UKD1  'Cumbria'

  UKD3  'Greater Manchester'

  UKD4  'Lancashire'

  UKD6  'Cheshire'

  UKD7  'Merseyside'

  UKE1  'East Yorkshire and Northern Lincolnshire'

  UKE2  'North Yorkshire'

  UKE3  'South Yorkshire'

  UKE4  'West Yorkshire'

  UKF1  'Derbyshire and Nottinghamshire'

  UKF2  'Leicestershire, Rutland and Northamptonshire'

  UKF3  'Lincolnshire'

  UKG1  'Herefordshire, Worcestershire and Warwickshire'

  UKG2  'Shropshire and Staffordshire'

  UKG3  'West Midlands'

  UKH1  'East Anglia'

  UKH2  'Bedfordshire and Hertfordshire'

  UKH3  'Essex'

  UKI3  'Inner London — West'

  UKI4  'Inner London — East'

  UKI5  'Outer London — East and North East'

  UKI6  'Outer London — South'

  UKI7  'Outer London — West and North West'

  UKJ1  'Berkshire, Buckinghamshire and Oxfordshire'

  UKJ2  'Surrey, East and West Sussex'

  UKJ3  'Hampshire and Isle of Wight'

  UKJ4  'Kent'

  UKK1  'Gloucestershire, Wiltshire and Bristol/Bath area'

  UKK2  'Dorset and Somerset'

  UKK3  'Cornwall and Isles of Scilly'

  UKK4  'Devon'

  UKL1  'West Wales and The Valleys'

  UKL2  'East Wales'

  UKM5  'North Eastern Scotland'

  UKM6  'Highlands and Islands'

  UKM7  'Eastern Scotland'

  UKM8  'West Central Scotland'

  UKM9  'Southern Scotland'

  UKN0  'Northern Ireland'

/;

 

No comments:

Post a Comment