Simplify shapefiles programmatically for mapbox Tileset/DataSource uploads using mapshaper.
Weighted Visvalingam simplification is used by default.
The following dependencies are used for this project. Feel free to use other dependency versions as needed.
- Windows 10 OS
- NVM for Windows
- v1.1.9
- NodeJS
- node version 10.16.3
- npm v6.9.0
- (installed via nvm)
(See package.json for more information.)
- mapshaper v0.5.28
-
Clone this repository.
git clone https://github.com/ciatph/shapefile-simplify.git
-
Install dependencies.
npm install
-
Create a .env file from the .env.example file. Update its defined variables in accordance with your personnal mapshaper cli command reference settings.
Variable Name Description PERCENTAGE Percentage of removable points to retain on the shapefile. INPUT_FORMAT input file format (i.e., .shp
for shapefile,.geojson
for GeoJSON)OUTPUT_FORMAT file format of the simplified (i.e., shapefile
for Shapefiles andgeojson
for GeoJSON)- The example .env file below will create a simplified GeoJSON file (small file size) from a (hi-resolution, big file size) shapefile:
PERCENTAGE=1.5% INPUT_FORMAT=shp OUTPUT_FORMAT=geojson
- The example .env file below will create a simplified
shapefile
from a (hi-resolution, big file size) shapefile:PERCENTAGE=4.0% INPUT_FORMAT=shp OUTPUT_FORMAT=shapefile
- The example .env file below will create a simplified GeoJSON file (small file size) from a (hi-resolution, big file size) shapefile:
- Create an INPUT directory named "shapefiles" inside the project's root directory. Put all shapefile-related input (
.shp
,.cpg
,.dbf
,.pfj
and.shx
) inside it. - Create an OUTPUT directory named "formatted" inside the project's root directory.
- Run the npm script.
npm start
- Wait for the simplification process to finish. Simplified files will be generated in the /formatted directory.
@ciatph
20200120