The coordinate conversion API

Table of Contents

Introduction

LINZ offers a coordinate conversion API that is more suitable than the coordinate conversion web application for converting large numbers of coordinates. There are some differences between this service and the concord web application:

The conversion API is located at https://www.geodesy.linz.govt.nz/api/conversions/v1. This URL will return a JSON formatted OpenAPI specification defining the API, which can be used to support building application that interface with the API.

The API also supports a simple comma separated value (CSV) format for input and output coordinate lists.

OpenAPI style coordinate conversion

The coordinate list object

Coordinate conversions are applied to a "coordinate list object" and return a converted coordinate list object following the same structure. The coordinate list object is structured as in the following example:

{
    "crs": "LINZ:NZGD2000/NZVD2016",
    "coordinateOrder": [
        "east",
        "north",
        "up"
    ],
    "coordinateEpoch": 2019.53,
    "coordinates": [
        [
            173.218789,
            -41.89021,
            157.81
        ],
        [
            172.54831,
            -40.769019,
            23.28
        ]
    ]
}

The elements of this structure are:

Attribute Description Example
crs Defines the coordinate system in the format LINZ:crs or LINZ:crs/vcrs. where crs is a LINZ code for a geometric coordinate system such as NZGD2000, and vcrs is an optional code for a height coordinate system. vcrs can be either then value of a LINZ height coordinate system code, or ELLIPSOIDAL to use ellipsoidal heights (the default for geographic coordinate systems), or NONE for no heights (the default for projection coordinate systems). LINZ:NZGD2000/NZVD2016
coordinateOrder An array defining the order of ordinates in each coordinate. The elements of the array are one of "east","north", and "up" except for geocentric cartesian coordinate systems. For geocentric cartesian coordinate systems this can be omitted, or if present must be ["geocentricX","geocentricY","geocentricZ"]. For projection coordinate systems without height coordinate system defined and for geographic coordinate systems with height coordinate system NONE this should have just two elements ["east","north"] or ["north","east"] ["north", "east", "up"]
coordinateEpoch An optional element specifies the date at which the coordinates are correct. This is required for time-depending coordinate conversions. This may be formatted as a decimal year, or as a date or date/time string in formats yyyy-mm-dd or yyyy-mm-ddThh:mm:ss 2019.53
coordinates An array of coordinate specified each an array of two or three values as defined by the coordinateOrder element. [[173.218789, -41.89021, 157.81], [172.54831, -40.769019, 23.28]]

The conversion request format

A coodinate list object is converted to a different coordinate system by sending it in a POST request to https://www.geodesy.linz.govt.nz/api/conversions/v1/convert-to?crs=_targetCrs_&coordinate=_targetCoordinateOrder_, eg

curl --no-progress-meter -d @input_coords.json https://www.geodesy.linz.govt.nz/api/conversions/v1/convert-to?crs=LINZ:ITRF2014/NZVD2016&coordinateOrder=north/east/up

This has two parameters:

parameter description example
crs The coordinate reference system to convert to. This is formatted in the same way as the crs value in the coordinate list object (as described above) LINZ:ITRF2014/NZVD2016
coordinateOrder The order of the coordinates in the output coordinate list. In most cases this can be omitted and a default order based upon the input coordinates will be used. north/east/up

The conversion response object

The response JSON object contains the converted coordinate list with some summary information about the conversion. It is structured as in the following example:

{
    "coordinateErrors": [
        "Coordinates out of range for calculating geoid height (1)"
    ],
    "coordinateList": {
        "coordinateEpoch": 2019.53,
        "coordinateOrder": [
            "north",
            "east",
            "up"
        ],
        "coordinates": [
            [
                -41.890203953,
                173.21878889,
                157.81
            ],
            [
                -40.769011786,
                172.548310329,
                23.28
            ],
            null
        ],
        "crs": "LINZ:ITRF2014/NZVD2016"
    },
    "failCoordCount": 1,
    "inputCoordCount": 3,
    "status": "success"
}

The elements of this are:

Attribute Description status
status A string indicating the status of the conversion. This will be either “success” or “fail”. “fail” indicates some configuration error, such as an invalid crs. If one or more coordinates are not able to be converted this will still result in a status “success”. success
inputCoordCount The number of coordinates in the input coordinate list. 3
failCoordCount The number of coordinates that could not be converted. 1
coordinateErrors This element is only present if the fail count is greater than 0. ["Coordinates out of range for calculating geoid height (1)"]
coordinateList This is an structured exactly as the input coordinate JSON. It can be used as an input in another call to the conversion endpoint. The coordinates array will have the same number of entries as the input coordinates and in the same order. Coordinates which cannot be converted will be represented as null in this list. {"coordinateEpoch": 2019.53,"coordinateOrder": ["north","east","up"],"coordinates": [[-41.890203953,173.21878889,157.81],[-40.769011786,172.548310329,23.28],null],"crs": "LINZ:ITRF2014/NZVD2016"}

Example usage in Python

This example demonstrates using the API to convert coordinates using the Python language. This example uses the Python requests module to simplify the API call:

import requests
import json

api = "https://www.geodesy.linz.govt.nz/api/conversions/v1/convert-to"

coordlist = {
    "crs": "LINZ:NZGD2000/NZVD2016",
    "coordinateOrder": ["east", "north", "up"],
    "coordinateEpoch": 2019.53,
    "coordinates": [
        [173.218789, -41.89021, 157.81],
        [172.54831, -40.769019, 23.28]
    ],
}

params = {"crs": "LINZ:NZTM", "coordinateOrder": "north/east"}

response = requests.post(api, params=params, json=coordlist)

if response.status_code == 200:
    nztmcoords = response.json()
    print(json.dumps(nztmcoords, indent=2))
else:
    print(f"Error: {response.text}")

Supported coordinate systems

The API also has an endpoint for listing the supported coordinate systems: https://www.geodesy.linz.govt.nz/api/conversions/v1/list-coordinate-systems. This returns an object as shown below with two elements, “crs” and “verticalCrs”. “crs” is a list of geometric coordinate systems and “verticalCrs” is a list of height coordinate systems.

{
    "crs": [
        {
            "linzCrsCode": "AGD66",
            "name": "Australian Geodetic Datum 1966"
        },
        {
            "linzCrsCode": "AGD84",
            "name": "Australian Geodetic Datum 1984"
        },
        {
            "linzCrsCode": "AITM2000",
            "name": "Antipodes Islands Transverse Mercator 2000"
        },
        ...
    ],
    "status": "success",
    "verticalCrs": [
        {
            "linzVerticalCrsCode": "AUCKHT1946",
            "name": "Auckland 1946 (from NZVD2016)"
        },
        {
            "linzVerticalCrsCode": "AUCKHT1946_NZVD09",
            "name": "Auckland 1946 (NZVD09)"
        },
        {
            "linzVerticalCrsCode": "BLUFHT1955",
            "name": "Bluff 1955 (from NZVD2016)"
        },
        {
            "linzVerticalCrsCode": "BLUFHT1955_NZVD09",
            "name": "Bluff 1955 (NZVD09)"
        },
        ...
    ]
}

Comma separated value (CSV) based coordinate conversions

In data analysis work it is often more convenient to convert CSV formatted lists of coordinates than to build JSON formatted objects containing the coordinates.

The CSV format is a simple comma separated list of coordinates. It may include a header record specifying the order of the coordinates. For example:

east,north,up
173.218789,-41.89021,157.81
172.54831,-40.769019,23.28

If the CSV does have a header with coordinate orders it can only contain values "east", "north", "up", "geocentricX", "geocentricY", and "geocentricZ".

Note that for CSV conversions which include a height ordinate the height ordinate must be the third one. It will not accept an order such as "up/north/east".

This is converted to a different coordinate system using an API call such as:

curl --no-progress-meter -d @input_coords.csv https://www.geodesy.linz.govt.nz/api/conversions/v1/convert-csv?crs=LINZ:NZGD2000/NZVD2016&useCsvHeaders=Y&toCrs='ITRF2014'

The convert-csv URL can include the following parameters:

parameter description example
useCsvHeaders Specifies that the input file has a CSV header defining the order of the coordinates and that the output file will also have a coordinate order header. This must have the value "Y". A header on the input CSV file will not be recognised if this parameter is not specified Y
crs the coordinate reference system of the coordinates in the input CSV file. This is formatted in the same way as in the coordinate list object described above, that is LINZ:crs or LINZ:crs/vcrs. where crs is a LINZ code for a geometric coordinate system such as NZGD2000, and vcrs is an optional code for a height coordinate system such as NZVD2016. LINZ:NZGD2000/NZVD2016
coordinateOrder defines the order of the coordinates in the input CSV file. This is only used if useCsvHeaders is not Y. This is formatted as ordinate names separated by the "/" character. north/east/up
coordinateEpoch defines the date of the coordinates - required for some conversions. This may be formatted as a decimal year, or as a date or date/time string in formats yyyy-mm-dd or yyyy-mm-ddThh:mm:ss 2019.53
toCrs The coordinate reference system for the converted output CSV file ITRF2014
toCoordinateOrder The coordinate order to use for the output CSV file east/north/up

The output coordinate CSV file is will be formatted in the same way as the input file. If a coordinate cannot be converted then the output ordinates will be blank, and they will be followed by an error message describing why they have not been converted.

If the conversion is incorrectly defined, for example if it uses an invalid CRS definition such as NZGD2001, then the call will return an error status code (rather than the normal 200 OK status code from a web request). The call will also return a JSON formatted error text in the same way as the OpenAPI conversion.