mapshaper 0.6.121 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/mapshaper.js +1342 -275
- package/package.json +5 -2
- package/www/assets/jetbrains-mono-regular.woff2 +0 -0
- package/www/assets/static-page.css +179 -0
- package/www/docs/_assets/cmd-search.js +213 -0
- package/www/docs/_assets/docs.css +712 -0
- package/www/docs/_assets/docs.js +75 -0
- package/www/docs/_assets/highlight.css +10 -0
- package/www/docs/essentials/command-line.html +127 -0
- package/www/docs/essentials/command-line.html.md +112 -0
- package/www/docs/essentials/web-app.html +138 -0
- package/www/docs/essentials/web-app.html.md +106 -0
- package/www/docs/examples/basics.html +276 -0
- package/www/docs/examples/basics.html.md +371 -0
- package/www/docs/examples/data/Makefile +31 -0
- package/www/docs/examples/data/globe.msx +0 -0
- package/www/docs/examples/data/globe.svg +616 -0
- package/www/docs/examples/data/globe.txt +21 -0
- package/www/docs/examples/data/globe.zip +0 -0
- package/www/docs/examples/data/ne_50m_admin_0_countries.geojson +1 -0
- package/www/docs/examples/data/ne_50m_admin_1_states_provinces_lakes.geojson +1 -0
- package/www/docs/examples/data/us-states.msx +0 -0
- package/www/docs/examples/data/us-states.svg +56 -0
- package/www/docs/examples/data/us-states.txt +6 -0
- package/www/docs/examples/data/us-states.zip +0 -0
- package/www/docs/examples/globe.html +108 -0
- package/www/docs/examples/globe.html.md +64 -0
- package/www/docs/examples/us-states.html +88 -0
- package/www/docs/examples/us-states.html.md +44 -0
- package/www/docs/formats/csv.html +127 -0
- package/www/docs/formats/csv.html.md +97 -0
- package/www/docs/formats/dbf.html +87 -0
- package/www/docs/formats/dbf.html.md +39 -0
- package/www/docs/formats/flatgeobuf.html +86 -0
- package/www/docs/formats/flatgeobuf.html.md +42 -0
- package/www/docs/formats/geojson.html +107 -0
- package/www/docs/formats/geojson.html.md +65 -0
- package/www/docs/formats/geopackage.html +87 -0
- package/www/docs/formats/geopackage.html.md +42 -0
- package/www/docs/formats/json.html +83 -0
- package/www/docs/formats/json.html.md +35 -0
- package/www/docs/formats/kml.html +82 -0
- package/www/docs/formats/kml.html.md +39 -0
- package/www/docs/formats/overview.html +192 -0
- package/www/docs/formats/overview.html.md +35 -0
- package/www/docs/formats/shapefile.html +123 -0
- package/www/docs/formats/shapefile.html.md +84 -0
- package/www/docs/formats/snapshot.html +87 -0
- package/www/docs/formats/snapshot.html.md +39 -0
- package/www/docs/formats/svg.html +99 -0
- package/www/docs/formats/svg.html.md +51 -0
- package/www/docs/formats/topojson.html +102 -0
- package/www/docs/formats/topojson.html.md +54 -0
- package/www/docs/gallery/index.html +80 -0
- package/www/docs/gallery/index.html.md +29 -0
- package/www/docs/guides/combining-layers.html +105 -0
- package/www/docs/guides/combining-layers.html.md +81 -0
- package/www/docs/guides/expressions.html +600 -0
- package/www/docs/guides/expressions.html.md +376 -0
- package/www/docs/guides/programmatic.html +117 -0
- package/www/docs/guides/programmatic.html.md +91 -0
- package/www/docs/guides/projections.html +158 -0
- package/www/docs/guides/projections.html.md +118 -0
- package/www/docs/guides/simplification.html +110 -0
- package/www/docs/guides/simplification.html.md +94 -0
- package/www/docs/guides/topology.html +90 -0
- package/www/docs/guides/topology.html.md +63 -0
- package/www/docs/images/simplification-detail.png +0 -0
- package/www/docs/images/simplification-dp.png +0 -0
- package/www/docs/images/simplification-mod2.png +0 -0
- package/www/docs/index.html +101 -0
- package/www/docs/index.html.md +59 -0
- package/www/docs/reference.html +1302 -0
- package/www/docs/reference.html.md +1817 -0
- package/www/docs/whats-new.html +76 -0
- package/www/docs/whats-new.html.md +53 -0
- package/www/index.html +30 -3
- package/www/llms-full.txt +4040 -0
- package/www/llms.txt +55 -0
- package/www/mapshaper-gui.js +7 -1
- package/www/mapshaper.js +1342 -275
- package/www/page.css +1 -1
- package/www/privacy.html +1 -112
- package/www/sponsor.html +4 -164
- package/www/terms.html +1 -112
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Basics
|
|
3
|
+
description: A scannable collection of short Mapshaper recipes for common GIS tasks — format conversion, joins, simplification, dissolves, projection, classification, web export and more.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Basics
|
|
7
|
+
|
|
8
|
+
Short Mapshaper recipes for common GIS tasks. The filenames and field names are illustrative — substitute your own. Most recipes also work in the [web app's](/docs/essentials/web-app.html.md) console: drop the leading `mapshaper` and the input filename, since the GUI already has the layer loaded.
|
|
9
|
+
|
|
10
|
+
> Looking for the syntax of a particular command or option? See the [command reference](/docs/reference.html.md). For the JS expression context used by `-each`, `-filter`, `calc=` and other commands, see [JavaScript expressions](/docs/guides/expressions.html.md).
|
|
11
|
+
|
|
12
|
+
## Inspecting and exploring
|
|
13
|
+
|
|
14
|
+
### Print a summary of a dataset
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
mapshaper input.shp -info
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`-info` prints the geometry type, feature count, CRS (if known), bounding box, and the name and type of every attribute field. It's the fastest way to remind yourself what a file actually contains. Add `save-to=info.json` to capture it as JSON.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Count features grouped by a field
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
mapshaper counties.shp \
|
|
27
|
+
-drop geometry \
|
|
28
|
+
-dissolve STATE calc='N = count(), POP = sum(POP)' \
|
|
29
|
+
-o state_data.csv
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
A dissolve with a `calc=` clause is an idiomatic way to aggregate data values.
|
|
33
|
+
|
|
34
|
+
## Filtering and selecting
|
|
35
|
+
|
|
36
|
+
### Keep features matching a condition
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
mapshaper countries.geojson -filter 'CONTINENT == "Asia" && POP > 1e7' \
|
|
40
|
+
-o output.geojson
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`-filter` keeps features for which the expression returns `true`.
|
|
44
|
+
|
|
45
|
+
### Keep features inside a bounding box
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
mapshaper world.shp -clip bbox=-10,35,30,60 -o europe.shp
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The four bbox numbers are `xmin,ymin,xmax,ymax` in the layer's own coordinates.
|
|
52
|
+
|
|
53
|
+
### Keep the top N features by some attribute
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
mapshaper cities.geojson \
|
|
57
|
+
-sort POP descending \
|
|
58
|
+
-filter 'this.id < 50' \
|
|
59
|
+
-o top50.geojson
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`-sort POP descending` orders by population from largest to smallest. Features have numerical ids starting with `0`, so `this.id < 50` keeps the first 50.
|
|
63
|
+
|
|
64
|
+
### Drop features with empty geometry
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
mapshaper messy.geojson -filter remove-empty -o clean.geojson
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The `remove-empty` flag drops features with missing or empty geometry.
|
|
71
|
+
|
|
72
|
+
## Editing attributes
|
|
73
|
+
|
|
74
|
+
### Add derived fields
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
mapshaper counties.shp \
|
|
78
|
+
-each 'STATE_FIPS = COUNTY_FIPS.substr(0, 2),
|
|
79
|
+
AREA_KM2 = round(this.area / 1e6, 1)' \
|
|
80
|
+
-o out.shp
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`-each` runs a JS expression on each feature; assigning to a bare name creates or updates a field. `round(x, 1)` is Mapshaper's rounding helper (one decimal here). On unprojected lat/long data, `this.area` returns square meters, dividing by 1e6 converts to square kilometers.
|
|
84
|
+
|
|
85
|
+
### Rename and filter fields
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
mapshaper data.csv \
|
|
89
|
+
-rename-fields POPULATION=POP,MEDIAN_INCOME=MEDIAN_INC \
|
|
90
|
+
-filter-fields STATE,COUNTY,POPULATION,MEDIAN_INCOME \
|
|
91
|
+
-o cleaned.csv
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`-rename-fields` takes `NEW=OLD` pairs. `-filter-fields` keeps only the listed fields, in the listed order — convenient for shaping CSV output.
|
|
95
|
+
|
|
96
|
+
### Preserve leading zeros from a CSV
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
mapshaper -i counties.csv string-fields=FIPS,STATEFIPS \
|
|
100
|
+
-o counties.shp
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
By default Mapshaper parses any numeric-looking CSV column as a number, which silently drops leading zeros from FIPS, ZIP and similar identifier columns. `string-fields=` forces the named columns to stay as strings.
|
|
104
|
+
|
|
105
|
+
## Joining data
|
|
106
|
+
|
|
107
|
+
### Join a CSV to a Shapefile by key
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
mapshaper states.shp \
|
|
111
|
+
-join demographics.csv keys=STATE_FIPS,FIPS string-fields=FIPS \
|
|
112
|
+
-o states_with_data.shp
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
`keys=A,B` means "match the target's `A` field to the source's `B` field". `string-fields=FIPS` (passed through to the CSV import) keeps the FIPS code as a string so `"06"` matches `"06"` rather than being parsed to `6`. To pull just a few columns from the source, add `fields=FIELD_A,FIELD_B`.
|
|
116
|
+
|
|
117
|
+
### Spatial join: tag points with the polygon they fall in
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
mapshaper crimes.geojson \
|
|
121
|
+
-join precinct_polygons.shp \
|
|
122
|
+
-o crimes_with_precinct.geojson
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
When `keys=` is omitted, `-join` falls back to a spatial join based on the geometry types involved. Here, every point inherits the attributes of the polygon containing it. Use `fields=PRECINCT_ID,DIVISION` to keep just specific columns.
|
|
126
|
+
|
|
127
|
+
### Many-to-one join with an aggregation
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
mapshaper precincts.shp \
|
|
131
|
+
-join crimes.geojson calc='N = count(), AVG_SEVERITY = mean(SEVERITY)' \
|
|
132
|
+
-o precincts_with_stats.shp
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
A polygon-to-many-points join can use `calc=` to summarize the matched source records into one or more new fields per target feature. The functions in `calc=` are the same set documented under [`-calc`](/docs/reference.html.md#-calc).
|
|
136
|
+
|
|
137
|
+
## Simplifying
|
|
138
|
+
|
|
139
|
+
### Simplify a polygon layer for the web
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
mapshaper provinces.shp \
|
|
143
|
+
-simplify 5% keep-shapes \
|
|
144
|
+
-clean \
|
|
145
|
+
-o format=topojson provinces.topojson
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`-simplify 5%` keeps 5% of the original vertices using the default weighted Visvalingam algorithm. `keep-shapes` prevents simplification from wiping out very small polygons. `-clean` mops up any topology errors introduced by aggressive simplification. TopoJSON output is usually 2–5x smaller than the equivalent GeoJSON.
|
|
149
|
+
|
|
150
|
+
### Simplify multiple files with shared topology
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
mapshaper -i states.shp counties.shp combine-files \
|
|
154
|
+
-simplify 10% \
|
|
155
|
+
-o out/
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
`combine-files` merges the inputs into one dataset before Mapshaper builds its arc topology, so vertices shared between layers stay shared after simplification — no gaps or overlaps along state/county boundaries. Each input still gets written back out as a separate file in `out/`. In the web app, add `combine-files` in the **Advanced options** field at import time to get the same behavior.
|
|
159
|
+
|
|
160
|
+
### Repair topology errors
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
mapshaper messy.shp -clean -o cleaned.shp
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
`-clean` snaps near-duplicate vertices, removes tiny gaps and overlaps between polygons, and fixes self-intersecting lines. It's a safe first step before any spatial operation. You can tune `gap-fill-area=`, `sliver-control=` or `snap-interval=` if necessary.
|
|
167
|
+
|
|
168
|
+
## Aggregating
|
|
169
|
+
|
|
170
|
+
### Dissolve to a parent geography
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
mapshaper counties.shp -dissolve STATE -o states.shp
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
`-dissolve` merges adjacent polygons that share a value in the named field.
|
|
177
|
+
|
|
178
|
+
### Dissolve while computing per-group stats
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
mapshaper counties.shp \
|
|
182
|
+
-dissolve STATE calc='N = count(),
|
|
183
|
+
POP = sum(POP),
|
|
184
|
+
MEDIAN_INC = median(MEDIAN_INC)' \
|
|
185
|
+
-o states_with_stats.shp
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
`calc=` works inside `-dissolve` as well as `-join`. The named functions (`count`, `sum`, `mean`, `median`, `mode`, `min`, `max`, `quartile1/2/3`, `iqr`, `quantile`, `collect`, `every`, `some`, `first`, `last`) all see the same per-feature context as `-each`.
|
|
189
|
+
|
|
190
|
+
### Convert points to population-weighted centroids
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
mapshaper cities.shp \
|
|
194
|
+
-dissolve STATE_FIPS weight=POPULATION \
|
|
195
|
+
-o state_centers.shp
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Dissolve groups of points that share a `STATE_FIPS` value into a single weighted centroid per group. The `weight=` option accepts a field name or a JS expression. Omitting a grouping field dissolves all points into one centroid.
|
|
199
|
+
|
|
200
|
+
## Spatial operations
|
|
201
|
+
|
|
202
|
+
### Erase one layer from another
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
mapshaper land.shp -erase lakes.shp -o land_no_lakes.shp
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
`-erase` removes the parts of the target layer that fall inside the source layer's polygons. Useful for masking out water, parks, or any "do-not-count" region. The inverse is `-clip`, which keeps the inside instead.
|
|
209
|
+
|
|
210
|
+
### Compute interior boundaries
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
mapshaper counties.shp -innerlines -o county_borders.shp
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
`-innerlines` returns the shared boundaries between polygons as a polyline layer, which is usually used for adding a stroke to interior boundaries on a styled map. Use [`-lines`](/docs/reference.html.md#-lines) instead if you want to retain both outer and inner boundaries.
|
|
217
|
+
|
|
218
|
+
### Generate a hex grid covering a layer
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
mapshaper region.shp \
|
|
222
|
+
-grid type=hex interval=10km name=hex \
|
|
223
|
+
-o hex.shp
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
`-grid` builds a regular grid (`square`, `hex`, `hex2`) covering the target's bounding box. Pair it with a spatial join to style the grid cells using interpolated count data (`-join interpolate=POPULATION`).
|
|
227
|
+
|
|
228
|
+
## Reprojection
|
|
229
|
+
|
|
230
|
+
### Project to a named CRS
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
mapshaper world.geojson -proj robinson -o world_robinson.geojson
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
`-proj` accepts EPSG codes (`EPSG:3857`), PROJ strings (`+proj=tmerc +lon_0=...`), or short aliases (`wgs84`, `webmercator`, `robinson`, `albersusa`). See the [Projections guide](/docs/guides/projections.html.md) for details.
|
|
237
|
+
|
|
238
|
+
### Match the projection of another file
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
mapshaper points.shp -proj match=basemap.shp -o points_aligned.shp
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
`match=` reads the CRS of another file and projects the target to match it — handy when assembling multiple datasets that need to share a coordinate system.
|
|
245
|
+
|
|
246
|
+
## Classification and styling
|
|
247
|
+
|
|
248
|
+
### Quantile-classify into a color ramp
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
mapshaper covid_cases.geojson \
|
|
252
|
+
-classify save-as=fill quantile classes=6 color-scheme=Oranges \
|
|
253
|
+
-o themed.geojson
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
`-classify` writes a class index or a derived value (here, a fill color) into the named field. The default is sequential quantile classification, but you can switch to `equal-interval`, `nice`, `categorical` or `non-adjacent`. Run `mapshaper -colors` to list the built-in color schemes.
|
|
257
|
+
|
|
258
|
+
### Add SVG styling for export
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
mapshaper boundaries.shp \
|
|
262
|
+
-style stroke="#444" stroke-width=0.5 fill=none \
|
|
263
|
+
-style where='RANK == 0' stroke="#000" stroke-width=1.5 \
|
|
264
|
+
-o map.svg
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
`-style` writes SVG presentation attributes onto each feature; the `where=` form lets you set them conditionally. The result is a valid SVG you can drop into a print or web layout.
|
|
268
|
+
|
|
269
|
+
## Output and conversion
|
|
270
|
+
|
|
271
|
+
### Convert Shapefile ↔ GeoJSON
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
mapshaper input.shp -o input.geojson
|
|
275
|
+
mapshaper input.geojson -o input.shp
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
The output format is inferred from the file extension. Use `format=` to force it (e.g. `-o format=topojson out.json`). When writing a Shapefile, Mapshaper produces `.shp`, `.shx`, `.dbf`, and `.prj`. If no output filename is given, the output file takes the name of the targeted layer.
|
|
279
|
+
|
|
280
|
+
### Quantized TopoJSON
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
mapshaper boundaries.shp -o boundaries.topojson
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
TopoJSON output is quantized by default — Mapshaper picks a quantization level based on the data's coordinate range. Quantization rounds coordinates to a grid, which dramatically shrinks file size. The default can be overridden with `quantization=` (e.g. `quantization=1e5`). Combined with `-simplify` and TopoJSON's shared-arc encoding, quantized output is routinely 2–5× smaller than equivalent GeoJSON.
|
|
287
|
+
|
|
288
|
+
### Output as ndjson
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
mapshaper big.geojson -o ndjson big.ndjson
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Newline-delimited JSON is friendlier to line-oriented tools like jq, BigQuery, and DuckDB. One Feature per line, no enclosing FeatureCollection.
|
|
295
|
+
|
|
296
|
+
### Split a layer into multiple files
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
mapshaper counties.shp \
|
|
300
|
+
-split STATE \
|
|
301
|
+
-o out/ extension=geojson
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
`-split FIELD` partitions features into separate layers by the value of `FIELD`; `-o` to a directory then writes one file per layer, named after the field value.
|
|
305
|
+
|
|
306
|
+
## Workflow patterns
|
|
307
|
+
|
|
308
|
+
### Run a chain of commands from a file
|
|
309
|
+
|
|
310
|
+
```
|
|
311
|
+
# build.txt
|
|
312
|
+
mapshaper
|
|
313
|
+
-i counties.shp
|
|
314
|
+
-rename-fields POP=POPULATION
|
|
315
|
+
-dissolve STATE calc='POP = sum(POP)'
|
|
316
|
+
-simplify 5%
|
|
317
|
+
-o out/states.topojson
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
```bash
|
|
321
|
+
mapshaper -run build.txt
|
|
322
|
+
# or simply:
|
|
323
|
+
mapshaper build.txt
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Long pipelines can be kept in a [command file](/docs/reference.html.md#command-files).
|
|
327
|
+
|
|
328
|
+
### Parameterize a command file
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
mapshaper -vars YEAR=2024 PCT=10 -run build.txt
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
```
|
|
335
|
+
# build.txt
|
|
336
|
+
mapshaper
|
|
337
|
+
-defaults YEAR=2020 PCT=5
|
|
338
|
+
-i sources/counties_{{YEAR}}.shp
|
|
339
|
+
-simplify {{PCT}}%
|
|
340
|
+
-o out/counties_{{YEAR}}.shp
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
`{{VAR}}` placeholders are substituted at parse time. `-defaults` sets values that the caller can override with `-vars` (or with `{{env.NAME}}` for environment variables).
|
|
344
|
+
|
|
345
|
+
### Stop a pipeline early on bad input
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
mapshaper input.csv \
|
|
349
|
+
-calc 'N = count()' \
|
|
350
|
+
-if 'global.N == 0' \
|
|
351
|
+
-print 'No records, exiting' \
|
|
352
|
+
-stop \
|
|
353
|
+
-endif \
|
|
354
|
+
-o out.csv
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
`-calc` expressions can publish values to the `global` object via simple assignment. `-if`/`-stop` then guard the rest of the pipeline. Useful in scripts where bad upstream data should fail loudly rather than silently produce empty output.
|
|
358
|
+
|
|
359
|
+
### Increase the heap for very large files
|
|
360
|
+
|
|
361
|
+
```bash
|
|
362
|
+
mapshaper-xl 16gb counties_5m.shp -simplify 10% -o counties_5m.topojson
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
`mapshaper-xl` is a wrapper that launches Node with extra heap space (default 8 GB; pass a size to override). Use it whenever you see "JavaScript heap out of memory" errors.
|
|
366
|
+
|
|
367
|
+
## See also
|
|
368
|
+
|
|
369
|
+
- [Command reference](/docs/reference.html.md) — every command and option
|
|
370
|
+
- [JavaScript expressions](/docs/guides/expressions.html.md) — the syntax and context used by `-each`, `-filter`, `calc=`, etc.
|
|
371
|
+
- [Guides](/docs/guides/index.html.md) — longer-form walk-throughs of simplification, topology cleaning, and more
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Per-example asset builds for the docs site.
|
|
2
|
+
#
|
|
3
|
+
# Each example is one short target. Mapshaper's CLI stacks multiple `-o`
|
|
4
|
+
# commands, so the recipe's own `-o <slug>.svg` and the trailing
|
|
5
|
+
# `-o <slug>.msx` here both fire from a single mapshaper invocation -- no
|
|
6
|
+
# need to run mapshaper twice. The .zip bundles the raw input files so
|
|
7
|
+
# readers can reproduce the example end-to-end.
|
|
8
|
+
#
|
|
9
|
+
# Add a new example by:
|
|
10
|
+
# 1. dropping <slug>.txt + source data into this directory
|
|
11
|
+
# 2. appending a target below following the globe pattern
|
|
12
|
+
# 3. adding the slug to `EXAMPLES`
|
|
13
|
+
|
|
14
|
+
EXAMPLES := globe us-states
|
|
15
|
+
|
|
16
|
+
all: $(EXAMPLES)
|
|
17
|
+
|
|
18
|
+
clean:
|
|
19
|
+
rm -f $(addsuffix .svg,$(EXAMPLES)) \
|
|
20
|
+
$(addsuffix .msx,$(EXAMPLES)) \
|
|
21
|
+
$(addsuffix .zip,$(EXAMPLES))
|
|
22
|
+
|
|
23
|
+
globe:
|
|
24
|
+
mapshaper globe.txt -o globe.msx
|
|
25
|
+
rm -f globe.zip && zip globe.zip ne_50m_admin_0_countries.geojson
|
|
26
|
+
|
|
27
|
+
us-states:
|
|
28
|
+
mapshaper us-states.txt -o us-states.msx
|
|
29
|
+
rm -f us-states.zip && zip us-states.zip ne_50m_admin_1_states_provinces_lakes.geojson
|
|
30
|
+
|
|
31
|
+
.PHONY: all clean $(EXAMPLES)
|
|
Binary file
|