Skip to content

Instantly share code, notes, and snippets.

@desaiuditd
Forked from jeffaudi/get_meta.py
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save desaiuditd/4feb14a998a33cc4c608 to your computer and use it in GitHub Desktop.
Save desaiuditd/4feb14a998a33cc4c608 to your computer and use it in GitHub Desktop.
This python script uses the Airbus Geo Catalog API to retrieve the meta-data associated to a list of imagery identifiers
# Script : get_meta.py
# Source : https://gist.github.com/jeffaudi/9fcac727cf6251287ecc/
# Copyright (c) 2014, Jeff Faudi
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import csv
import httplib2
import json
from pprint import pprint
import time
# get API key from http://www.astrium-geo.com/en/5044-api-multi-catalog-user-guide-obtaining-an-api-key
key = 'paste-your-API-key-here'
# variables to store the results
idents = []
counter = 0
# create an httplib2.Http object to handle our HTTP requests
http = httplib2.Http()
# ident.csv is the list of Airbus imagery identifiers
with open('ident.csv', 'rb') as csvfile:
identreader = csv.reader(csvfile, delimiter=';')
for row in identreader:
# count the lines
counter += 1
# skip the first line, create the header on result file
if counter == 1:
idents.append(['ident', 'acquisitionDate', 'resolution', 'satellite',
'sensorFamily', 'productId', 'productType', 'qualityQuotes', 'cloudCoverPercentage',
'snowCoverPercentage', 'incidenceAngle', 'acrossTrackIncidenceAngle', 'alongTrackIncidenceAngle',
'combinedViewingAngle', 'roll', 'pitch', 'archivingStation', 'receivingStation', 'shift', 'maxShift',
'orbitNumber', 'orientationAngle', 'sunAzimuth', 'imageUrl', 'wktBounds', 'wktCenter', 'wktFootprint'])
continue
# for testing purposes, read only the first ident line
#if counter == 5:
# break
# print a note to the user
print '{:3d}: Querying {}'.format(counter, row[0])
# prepare and send the request to the API
request = 'http://api.astrium-geo.com/catalog/data/features.svc/features/'
request += row[0]
request += '?of=geojson&sk=' + key
response, content = http.request(request)
# if request returns
if response.status == 200:
# parse the JSON
resource = json.loads(content)
# for testing purposes, print the JSON
# pprint(resource)
# check for result code
if resource['code'] == 'OK':
# get properties of first image return
row.append(resource['features'][0]['properties']['acquisitionDate'][0:10])
row.append(resource['features'][0]['properties']['resolution'])
row.append(resource['features'][0]['properties']['satellite'])
row.append(resource['features'][0]['properties']['sensorFamily'])
row.append(resource['features'][0]['properties']['productId'])
row.append(resource['features'][0]['properties']['productType'])
row.append(resource['features'][0]['properties']['qualityQuotes'])
row.append(resource['features'][0]['properties']['cloudCoverPercentage'])
row.append(resource['features'][0]['properties']['snowCoverPercentage'])
row.append(resource['features'][0]['properties']['incidenceAngle'])
row.append(resource['features'][0]['properties']['acrossTrackIncidenceAngle'])
row.append(resource['features'][0]['properties']['alongTrackIncidenceAngle'])
row.append(resource['features'][0]['properties']['combinedViewingAngle'])
row.append(resource['features'][0]['properties']['roll'])
row.append(resource['features'][0]['properties']['pitch'])
row.append(resource['features'][0]['properties']['archivingStation'])
row.append(resource['features'][0]['properties']['receivingStation'])
row.append(resource['features'][0]['properties']['shift'])
row.append(resource['features'][0]['properties']['maxShift'])
row.append(resource['features'][0]['properties']['orbitNumber'])
row.append(resource['features'][0]['properties']['orientationAngle'])
row.append(resource['features'][0]['properties']['sunAzimuth'])
row.append(resource['features'][0]['properties']['imageUrl'])
row.append(resource['features'][0]['properties']['wktBounds'])
row.append(resource['features'][0]['properties']['wktCenter'])
row.append(resource['features'][0]['properties']['wktFootprint'])
# add the row to the result file
idents.append(row)
# wait for 1 second before the next request
time.sleep(1)
# write all content to a CSV file
with open('ident_meta.csv', 'wb') as output:
identwriter = csv.writer(output, delimiter=';')
for row in idents:
identwriter.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment