This project was created for educational purposes, but if you want to use any ideas in your own work, you are more than welcome.
This project includes AWS CDK definitions for the GeoJSON simplify service. The service has one endpoint that is used to submit a simplify job for the GeoJSON files that are stored in S3. GeoJSON is a very popular format for drawing geographical borders on the web; however, sometimes the files are too large for Web Applications more than 10 mb. To solve this issue, we can decrease the size of the files by simplifying the border polygons using the mapshaper library.
When you deploy the infrastructure via 'cdk deploy', it will create two S3 buckets for original and processed images, a REST API endpoint to submit the request, a DynamoDB table to keep track of submitted orders, an SQS, and two Lambdas: one for enqueuing the task and the second one to process the task.
- AWS Account: Sign up for a free tier account.
- AWS CLI: Install and configure.
- Node.js: AWS CDK requires Node.js (LTS version recommended). Download.
- AWS CDK: Installation guide.
Before you can deploy the final version of the service, you have to call npm install from the src folder to install the
mapshaper dependency. Otherwise, you will recieve the error from the processing lambda, that mapshaper module could not be imported.
After you call cdk deploy, AWS CDK will create an AWS stack for the project on your AWS account. It will show a "Deployment is
successful" message along with the RestAPI endpoint, in a format like this:
"✨ Deployment time: 27.32s
Outputs:
GeoJsonSimplifyStack.GeoJsonApiEndpointF10593D3 = https://b34f32ogde.execute-api.eu-central-1.amazonaws.com/prod/
"This is your endpoint, which has only one resource, /process. Before starting the simplification process for your GeoJSONs,
you need to save them in the original_bucket on your S3 that was just created. The S3 bucket names must be unique globally, so the name is auto-generated and will look something like this:
geojsonsimplifystack-s3stackprocessedbucket74b25c-zo8kg7zjok67sGeoJSONs for all the countries can be downloaded from GADM website, pick big countries like USA, China, Brazil, for demonstration purpose.
After you uploaded required GEOJSON to s3, call the REST API enpoint resource /process with the similar POST body:
{
"bucket_name": "geojsonsimplifystack-s3stackprocessedbucket74b25c-zo8kg7zjok67s",
"simplifyCoefficient": 0.2,
"orders": [
{
"filename": "usa_states.geojson",
"force": true
}
]
}- 'bucket_name' - backet name that was created on you AWS account where not simplified files are stored.
- 'simplifyCoefficient': a value between 0 and 1, that corresponds to the level of simplification. The default value is 0.2. This repository is using mapshapper library where you can learn more about this parameter.
- 'orders': - array of orders, every order contains:
- 'filename' - the file stored in S3 that you want to simplify.
- 'force' - a parameter specifying if you want to rewrite already existing files.
After you submit the post request, 'enqueue' lambda will put these items into SQS and they will be processed one by one, after few minutes you should see you simplified geojsons in the "processed" S3 bucket (it will also have auto generated name).
npm run buildcompile typescript to jsnpm run watchwatch for changes and compilenpm run testperform the jest unit testscdk diffcompare deployed stack with current statecdk synthemits the synthesized CloudFormation template