Skip to content

Commit

Permalink
Add list4vrt helper
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Jun 6, 2019
1 parent fd8044a commit 16725e4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*
!npm-packages
!bin/
!webpack.config.js
!commons/c2cgeoportal_commons/
!commons/setup.py
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.mako
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ RUN \
done && \
curl --output /opt/jasperreport.xsd http://jasperreports.sourceforge.net/xsd/jasperreport.xsd

COPY bin/list4vrt /usr/bin/
COPY commons /opt/c2cgeoportal_commons
COPY geoportal /opt/c2cgeoportal_geoportal
COPY admin /opt/c2cgeoportal_admin
Expand Down
28 changes: 28 additions & 0 deletions bin/list4vrt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3

import boto3
import os
import argparse


def main():
parser = argparse.ArgumentParser(description='Get the list of geotiff files for `gdalbuildvrt`')
parser.add_argument('bucket')
parser.add_argument('prefix')
parser.add_argument('postfix', default='.bt')
args = parser.parse_args()

session = boto3.session.Session()

s3_client = session.client(
service_name='s3',
endpoint_url=f"https://{os.environ['AWS_S3_ENDPOINT']}/",
region_name=os.environ['AWS_DEFAULT_REGION']
)
keys = [i['Key'] for i in s3_client.list_objects(Bucket=args.bucket, Prefix=args.prefix)['Contents']]
filtered_keys = list(filter(lambda i: i.endswith(args.postfix), keys))
full_keys = [f'/vsis3/{args.bucket}/{i}' for i in filtered_keys]
print('\n'.join(full_keys))


main()
7 changes: 3 additions & 4 deletions doc/integrator/objectstorage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ Create the vrt file for a raster layer:

.. prompt:: bash

gdalbuildvrt `aws --endpoint-url https://sos-ch-dk-2.exo.io/ ${'\\'}
--region ch-dk-2 s3 ls s3://<bucket>/<folder>/*.geotiff ${'\\'}
|awk '{print $4}'` s3://<bucket>/<folder>/index.vrt

docker-compose exec geoportal ${'\\'}
gdalbuildvrt /vsis3/<bucket>/<folder>/index.vrt ${'\\'}
$(list4vrt <bucket> <folder>/)

MapServer
---------
Expand Down

0 comments on commit 16725e4

Please sign in to comment.