Convert locations to NUTS codes

The problem

You have addresses or geographic coordinates (longitude and latitude) and you want to know the NUTS codes of the location.

Overview

EU NUTS (an abbreviation for Nomenclature of Territorial Units for Statistics) codes are standardized codes used by the European Union to define administrative and statistical regions for the purpose of data collection and analysis. They are used to identify, classify, and aggregate data on regions within the EU for statistics, planning, and policy making.

Map of Europe showing NUTS2 regions

Map (taken from the Eurostat website) of NUTS2 regions across Europe

Converting addresses and/or geocoordinates (longitude, latitude) into NUTS codes as a way to aggregate data is a common task for statistical researchers.

You can use the OpenCage geocoding API to find the relevant NUTS codes for a location in EU countries (current member states) and EFTA countries (CH, IS, LI, NO), and some EU candidate countries

You can test our geocoding API manually on our demo page.

Background

When you send an API request to the OpenCage geocoding API with each result we return various fields about the location of the result (what we refer to in our API documentation as annotations). For locations in the EU member states we return a NUTS annotation for each result with the subfields:
  • NUTS0
    the NUTS country code
    Example: DE
  • NUTS1
    Example: DE9
  • NUTS2
    Example: DE92
  • NUTS3
    Example: DE929

Caveats / Points to Note

There are a few points you should note when working with the NUTS codes returned by the OpenCage geocoding API.
  • Countries are structured differently, as is perhaps to be expected given that some countries are very large, and others much smaller. Some countries have many level 3 NUTS codes, others only one.
  • Currently we return NUTS codes only for EU member states, EFTA countries (CH, IS, LI, NO), and some EU candidate countries (AL, ME, MK, RS, TR). We may in the future add more candidate countries and former EU member states (the UK). If this is preventing you from becoming a customer please get in touch with us, and let's discuss.
  • We do not currently offer LAU codes (the level below NUTS3)

Code Example

Here's a small example of making a geocoding request to the OpenCage API in javascript to determine the NUTS code of the coordinates 52.3877830, 9.7334394 - site of the OpenCage office in Hannover, Germany.
We also have libraries for over 30 other programming languages. including languages commonly used in research like python, R, stata, matlab, and many others.

<script>
  var api_key = 'YOUR-API-KEY';
  var coords = '52.3877830, 9.7334394';  // lat,lng

  var api_url = 'https://api.opencagedata.com/geocode/v1/json'

  var request_url = api_url
    + '?'
    + 'key=' + api_key
    + '&q=' + encodeURIComponent(coords)
    + '&pretty=1';

  // see full list of required and optional parameters:
  // https://opencagedata.com/api#forward

  var request = new XMLHttpRequest();
  request.open('GET', request_url, true);

  request.onload = function() {
      // see full list of possible response codes:
      // https://opencagedata.com/api#codes
      var data = JSON.parse(request.responseText);
      if (request.status === 200){  // Success!
          var nuts = 'no NUTS codes returned';
          if (data.results[0].annotations.NUTS != null){
              nuts = data.results[0].annotations.NUTS;
          }
          console.log('NUTS: ' + nuts);
      } else {
          console.log("unable to geocode! Response code: " + request.status);
          console.log('error msg: ' + data.status.message);
      }
  };

  request.onerror = function() {
      // There was a connection error of some sort
      console.log("unable to connect to server");
  };
  request.send();  // make the request
</script>

Further Reading

Happy geocoding!

Start your free trial

2,500 geocoding API requests per day.

No credit card required.