Skip to content

Instantly share code, notes, and snippets.

@craigds
Created November 15, 2017 23:58
Show Gist options
  • Save craigds/af4ae640297a3d88b7cc042ac39f8d22 to your computer and use it in GitHub Desktop.
Save craigds/af4ae640297a3d88b7cc042ac39f8d22 to your computer and use it in GitHub Desktop.
Sample python code for creating a simple export on LDS
# coding: utf-8
from __future__ import absolute_import, division, print_function, unicode_literals
import os
import time
import koordinates
def progress(so_far, total):
print('%.1f%%' % (100 * so_far / total))
def main():
client = koordinates.Client(host='data.linz.govt.nz', token=os.environ['LDS_API_TOKEN'])
# Do a shapefile export in WGS84
export = koordinates.Export()
export.crs = "EPSG:4326"
export.formats = {
"vector": "application/x-zipped-shp"
}
# https://data.linz.govt.nz/layer/50525-airport-airfield-polygon-hydro-122k-190k/
export.add_item(client.layers.get(id=50525))
print("Starting the export")
client.exports.create(export)
print("Waiting for it to be ready")
while export.state == 'processing':
time.sleep(5)
export.refresh()
print("Checking it's completed successfully")
if export.state != 'complete':
raise ValueError("Can't download a %r export" % export.state)
print("Actually downloading it")
export.download('./%s.zip' % export.name, progress_callback=progress)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment