These scripts convert source geospatial files into boundary vector tiles, and upload them to AWS S3.
It works on Node 8 (tested on v8.15.1), and fails on many other versions, due to missing binaries used by Sqlite3.
npm install
- GDAL 2.4.0 or later (GDAL 3 untested, but may work)
- Optional. Used for converting shapefile to GeoJSON in
toGeoJSON
step
- Optional. Used for converting shapefile to GeoJSON in
- Tippecanoe version 1.32.10 or later
- Required for creating vector tiles in
makeVectorTiles
step
- Required for creating vector tiles in
- Node 8 (tested on v8.15.1)
Each boundary type has a specific identifier (eg, DEMO_TRIANGLES).
- Add configuration options for the boundary type to
config.json5
(or other configuration file if usingBOUNDARYTYPESCONFIG
environment variable). - Place source files in
srcdata/DEMO_TRIANGLES
- Run gulp:
- Optionally set the configuration file to be read with environment variable:
export BOUNDARYTYPESCONFIG="./config-terria.json5"
- Optionally limit the boundary type(s) with comma-separated types in environment variable:
export BOUNDARYTYPES=DEMO_TRIANGLES
- Run
gulp <task>
:
- Optionally set the configuration file to be read with environment variable:
toGeoJSON
: unzips source files and converts to newline-delimited GeoJSONaddFeatureIds
: adds a FID field to each GeoJSON feature, writes to a new file.makeRegionIds
: generates a regionids file for each region prop.makeVectorTiles
: generatesmbtiles/DEMO_TRIANGLES.mbtiles
from the FID-enriched GeoJSON file.updateRegionMapping
: adds or updates an entry inregionMapping/regionMapping.json
.all
: does all of the abovedeploy
: uploads the invidiual tiles from thembtiles
file to S3. You will need your MFA device.
- In TerriaJS:
- Create a branch.
- Splice into wwwroot/data/regionMapping.json part of the generated regionMapping/regionMapping.json
- Update other entries in wwwroot/data/regionMapping.json if the default year for a region type has now changed.
- Copy into wwwroot/data/regionids/ the generated files in regionMapping/regionids/
- Open pull request.
First convert the GeoJSON to ndjson:
npm run geojson2ndjson triangles.geojson > ./geojson/DEMO_TRIANGLES.nd.json
Then run tasks as above, skipping toGeoJSON
.
Configuration should be added to config-terria.json5
and committed to the repo to preseve the options used.
To use the gulp deploy
script, first create a userconfig.json
file in this directory, as follows:
{
"role_arn": "arn:aws:iam::123457890:role/owner",
"profile": "terria"
}
You can find the correct values in your ~/.aws/config file.
Setting up AWS to serve vector tiles directly from S3 requires three main bits:
- an S3 bucket configured as a static website, with CORS enabled
- a Route53 subdomain pointing at it
- a CloudFront distribution pointing to the subdomain, with certificate and CORS settings
- Name it according to the subdomain you will use, eg
tiles.terria.io
- Region: Asia Pacific (Sydney)
- Uncheck all four "Manage public access control lists (ACLs) for this bucket" and "Manage public bucket policies for this bucket" options
- In the bucket, Permissions > Bucket Policy, paste this (updating the bucket name):
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadForGetBucketObjects",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::tiles.terria.io/*"
},
{
"Sid": "PublicReadForListBucketContents",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::tiles.terria.io"
}
]
}
- On Permissions > CORS Configuration, add this configuration:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>
- On Properties > Static website hosting, choose "Use this bucket to host a website"
- Set "index.html" as the index document, even though you won't be using one. (Can't save otherwise).
- Create a distribution, mode "Web".
- Origin domain name: select your S3 name:
tiles.terria.io.s3.amazonaws.com
- Scroll down, "Alternate domain names (CNAMEs)":
tiles.terria.io
- SSL Certificate: "Custom SSL Certificate", choose terria.io's certificate.
- Origin domain name: select your S3 name:
- On "Behaviors", edit the existing behaviour.
- Change "Cache based on Selected Request Headers" to "Whitelist"
- Add these to whitelist:
- Access-Control-Request-Headers
- Access-Control-Request-Method
- Origin
- Add these to whitelist:
- Set Object Caching to "Customize".
- Set Maximum TTL and default TTL to 120.
- Go to Hosted zones, terria.io
- Create a Record Set,
tiles.terria.io
- Check the Alias "Yes" box, find your Cloudfront distribution