mapshaper 0.7.1 → 0.7.3

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.
Files changed (82) hide show
  1. package/LICENSE +1 -1
  2. package/mapshaper.js +1 -1
  3. package/package.json +5 -2
  4. package/www/.nojekyll +0 -0
  5. package/www/index.html +22 -6
  6. package/www/mapshaper-gui.js +292 -4
  7. package/www/mapshaper.js +1 -1
  8. package/www/page.css +188 -10
  9. package/www/docs/_assets/cmd-search.js +0 -213
  10. package/www/docs/_assets/docs.css +0 -712
  11. package/www/docs/_assets/docs.js +0 -75
  12. package/www/docs/_assets/highlight.css +0 -10
  13. package/www/docs/essentials/command-line.html +0 -127
  14. package/www/docs/essentials/command-line.html.md +0 -112
  15. package/www/docs/essentials/web-app.html +0 -138
  16. package/www/docs/essentials/web-app.html.md +0 -106
  17. package/www/docs/examples/basics.html +0 -276
  18. package/www/docs/examples/basics.html.md +0 -371
  19. package/www/docs/examples/data/Makefile +0 -31
  20. package/www/docs/examples/data/globe.msx +0 -0
  21. package/www/docs/examples/data/globe.svg +0 -616
  22. package/www/docs/examples/data/globe.txt +0 -21
  23. package/www/docs/examples/data/globe.zip +0 -0
  24. package/www/docs/examples/data/ne_50m_admin_0_countries.geojson +0 -1
  25. package/www/docs/examples/data/ne_50m_admin_1_states_provinces_lakes.geojson +0 -1
  26. package/www/docs/examples/data/us-states.msx +0 -0
  27. package/www/docs/examples/data/us-states.svg +0 -56
  28. package/www/docs/examples/data/us-states.txt +0 -6
  29. package/www/docs/examples/data/us-states.zip +0 -0
  30. package/www/docs/examples/globe.html +0 -108
  31. package/www/docs/examples/globe.html.md +0 -64
  32. package/www/docs/examples/us-states.html +0 -88
  33. package/www/docs/examples/us-states.html.md +0 -44
  34. package/www/docs/formats/csv.html +0 -127
  35. package/www/docs/formats/csv.html.md +0 -97
  36. package/www/docs/formats/dbf.html +0 -87
  37. package/www/docs/formats/dbf.html.md +0 -39
  38. package/www/docs/formats/flatgeobuf.html +0 -86
  39. package/www/docs/formats/flatgeobuf.html.md +0 -42
  40. package/www/docs/formats/geojson.html +0 -107
  41. package/www/docs/formats/geojson.html.md +0 -65
  42. package/www/docs/formats/geopackage.html +0 -87
  43. package/www/docs/formats/geopackage.html.md +0 -42
  44. package/www/docs/formats/json.html +0 -83
  45. package/www/docs/formats/json.html.md +0 -35
  46. package/www/docs/formats/kml.html +0 -82
  47. package/www/docs/formats/kml.html.md +0 -39
  48. package/www/docs/formats/overview.html +0 -192
  49. package/www/docs/formats/overview.html.md +0 -35
  50. package/www/docs/formats/shapefile.html +0 -123
  51. package/www/docs/formats/shapefile.html.md +0 -84
  52. package/www/docs/formats/snapshot.html +0 -87
  53. package/www/docs/formats/snapshot.html.md +0 -39
  54. package/www/docs/formats/svg.html +0 -99
  55. package/www/docs/formats/svg.html.md +0 -51
  56. package/www/docs/formats/topojson.html +0 -102
  57. package/www/docs/formats/topojson.html.md +0 -54
  58. package/www/docs/gallery/index.html +0 -80
  59. package/www/docs/gallery/index.html.md +0 -29
  60. package/www/docs/guides/combining-layers.html +0 -105
  61. package/www/docs/guides/combining-layers.html.md +0 -81
  62. package/www/docs/guides/expressions.html +0 -600
  63. package/www/docs/guides/expressions.html.md +0 -376
  64. package/www/docs/guides/programmatic.html +0 -117
  65. package/www/docs/guides/programmatic.html.md +0 -91
  66. package/www/docs/guides/projections.html +0 -158
  67. package/www/docs/guides/projections.html.md +0 -118
  68. package/www/docs/guides/simplification.html +0 -110
  69. package/www/docs/guides/simplification.html.md +0 -94
  70. package/www/docs/guides/topology.html +0 -90
  71. package/www/docs/guides/topology.html.md +0 -63
  72. package/www/docs/images/simplification-detail.png +0 -0
  73. package/www/docs/images/simplification-dp.png +0 -0
  74. package/www/docs/images/simplification-mod2.png +0 -0
  75. package/www/docs/index.html +0 -101
  76. package/www/docs/index.html.md +0 -59
  77. package/www/docs/reference.html +0 -1302
  78. package/www/docs/reference.html.md +0 -1817
  79. package/www/docs/whats-new.html +0 -76
  80. package/www/docs/whats-new.html.md +0 -53
  81. package/www/llms-full.txt +0 -4040
  82. package/www/llms.txt +0 -55
@@ -1,276 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>Basics &middot; mapshaper docs</title>
7
- <meta name="description" content="A scannable collection of short Mapshaper recipes for common GIS tasks — format conversion, joins, simplification, dissolves, projection, classification, web export and more.">
8
- <link rel="icon" type="image/png" href="/images/icon.png">
9
- <link rel="stylesheet" href="/docs/_assets/highlight.css">
10
- <link rel="stylesheet" href="/docs/_assets/docs.css">
11
- </head>
12
- <body class="">
13
-
14
- <header class="page-header">
15
- <a href="/" class="mapshaper-logo">map<span class="logo-highlight">shaper</span></a>
16
- <span class="header-section-label">Docs</span>
17
- <nav class="header-nav">
18
- <a href="/">Web app</a>
19
- <a href="https://github.com/mbloch/mapshaper">GitHub</a>
20
- <a href="/sponsor.html" class="sponsor-link"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"/></svg> Become a sponsor</a>
21
- </nav>
22
- </header>
23
-
24
- <div class="docs-layout">
25
-
26
- <aside class="docs-sidebar">
27
- <div class="sidebar-inner">
28
- <nav class="docs-nav"><ul class="top-links"><li><a href="/docs/">Home</a></li><li><a href="/docs/whats-new.html">What&#39;s new</a></li><li><a href="/docs/reference.html">Command reference</a></li><li><a href="/docs/gallery/">Gallery</a></li></ul><h2>Getting started</h2><ul><li><a href="/docs/essentials/command-line.html">The command-line tool</a></li><li><a href="/docs/essentials/web-app.html">The web app</a></li></ul><h2>Guides</h2><ul><li><a href="/docs/guides/simplification.html">Simplification</a></li><li><a href="/docs/guides/expressions.html">JavaScript expressions</a></li><li><a href="/docs/guides/projections.html">Projections</a></li><li><a href="/docs/guides/topology.html">Topology and cleaning</a></li><li><a href="/docs/guides/combining-layers.html">Combining two layers</a></li><li><a href="/docs/guides/programmatic.html">Using Mapshaper from Node.js</a></li></ul><h2>Formats</h2><ul><li><a href="/docs/formats/overview.html">Overview</a></li><li><a href="/docs/formats/shapefile.html">Shapefile</a></li><li><a href="/docs/formats/geojson.html">GeoJSON</a></li><li><a href="/docs/formats/topojson.html">TopoJSON</a></li><li><a href="/docs/formats/geopackage.html">GeoPackage</a></li><li><a href="/docs/formats/flatgeobuf.html">FlatGeobuf</a></li><li><a href="/docs/formats/kml.html">KML / KMZ</a></li><li><a href="/docs/formats/csv.html">CSV / TSV</a></li><li><a href="/docs/formats/dbf.html">DBF</a></li><li><a href="/docs/formats/json.html">JSON records</a></li><li><a href="/docs/formats/svg.html">SVG</a></li><li><a href="/docs/formats/snapshot.html">Mapshaper snapshot</a></li></ul><h2>Examples</h2><ul><li><a href="/docs/examples/basics.html" class="is-active">Basics</a></li><li><a href="/docs/examples/globe.html">Globe</a></li><li><a href="/docs/examples/us-states.html">U.S. state map</a></li></ul></nav>
29
- </div>
30
- </aside>
31
-
32
- <main class="docs-main">
33
- <article class="docs-article">
34
- <div class="docs-breadcrumbs"><a href="/docs/">Docs</a> &rsaquo; Examples &rsaquo; Basics</div>
35
- <h1 id="basics">Basics</h1>
36
- <p>Short Mapshaper recipes for common GIS tasks. The filenames and field names are illustrative &mdash; substitute your own. Most recipes also work in the <a href="/docs/essentials/web-app.html">web app&#39;s</a> console: drop the leading <code>mapshaper</code> and the input filename, since the GUI already has the layer loaded.</p>
37
- <blockquote>
38
- <p>Looking for the syntax of a particular command or option? See the <a href="/docs/reference.html">command reference</a>. For the JS expression context used by <code>-each</code>, <code>-filter</code>, <code>calc=</code> and other commands, see <a href="/docs/guides/expressions.html">JavaScript expressions</a>.</p>
39
- </blockquote>
40
- <h2 id="inspecting-and-exploring">Inspecting and exploring</h2>
41
- <h3 id="print-a-summary-of-a-dataset">Print a summary of a dataset</h3>
42
- <pre><code class="hljs language-bash">mapshaper input.shp -info
43
- </code></pre>
44
- <p><code>-info</code> prints the geometry type, feature count, CRS (if known), bounding box, and the name and type of every attribute field. It&#39;s the fastest way to remind yourself what a file actually contains. Add <code>save-to=info.json</code> to capture it as JSON.</p>
45
- <h3 id="count-features-grouped-by-a-field">Count features grouped by a field</h3>
46
- <pre><code class="hljs language-bash">mapshaper counties.shp \
47
- -drop geometry \
48
- -dissolve STATE calc=<span class="hljs-string">&#x27;N = count(), POP = sum(POP)&#x27;</span> \
49
- -o state_data.csv
50
- </code></pre>
51
- <p>A dissolve with a <code>calc=</code> clause is an idiomatic way to aggregate data values.</p>
52
- <h2 id="filtering-and-selecting">Filtering and selecting</h2>
53
- <h3 id="keep-features-matching-a-condition">Keep features matching a condition</h3>
54
- <pre><code class="hljs language-bash">mapshaper countries.geojson -filter <span class="hljs-string">&#x27;CONTINENT == &quot;Asia&quot; &amp;&amp; POP &gt; 1e7&#x27;</span> \
55
- -o output.geojson
56
- </code></pre>
57
- <p><code>-filter</code> keeps features for which the expression returns <code>true</code>.</p>
58
- <h3 id="keep-features-inside-a-bounding-box">Keep features inside a bounding box</h3>
59
- <pre><code class="hljs language-bash">mapshaper world.shp -clip bbox=-10,35,30,60 -o europe.shp
60
- </code></pre>
61
- <p>The four bbox numbers are <code>xmin,ymin,xmax,ymax</code> in the layer&#39;s own coordinates.</p>
62
- <h3 id="keep-the-top-n-features-by-some-attribute">Keep the top N features by some attribute</h3>
63
- <pre><code class="hljs language-bash">mapshaper cities.geojson \
64
- -<span class="hljs-built_in">sort</span> POP descending \
65
- -filter <span class="hljs-string">&#x27;this.id &lt; 50&#x27;</span> \
66
- -o top50.geojson
67
- </code></pre>
68
- <p><code>-sort POP descending</code> orders by population from largest to smallest. Features have numerical ids starting with <code>0</code>, so <code>this.id &lt; 50</code> keeps the first 50.</p>
69
- <h3 id="drop-features-with-empty-geometry">Drop features with empty geometry</h3>
70
- <pre><code class="hljs language-bash">mapshaper messy.geojson -filter remove-empty -o clean.geojson
71
- </code></pre>
72
- <p>The <code>remove-empty</code> flag drops features with missing or empty geometry.</p>
73
- <h2 id="editing-attributes">Editing attributes</h2>
74
- <h3 id="add-derived-fields">Add derived fields</h3>
75
- <pre><code class="hljs language-bash">mapshaper counties.shp \
76
- -each <span class="hljs-string">&#x27;STATE_FIPS = COUNTY_FIPS.substr(0, 2),
77
- AREA_KM2 = round(this.area / 1e6, 1)&#x27;</span> \
78
- -o out.shp
79
- </code></pre>
80
- <p><code>-each</code> runs a JS expression on each feature; assigning to a bare name creates or updates a field. <code>round(x, 1)</code> is Mapshaper&#39;s rounding helper (one decimal here). On unprojected lat/long data, <code>this.area</code> returns square meters, dividing by 1e6 converts to square kilometers.</p>
81
- <h3 id="rename-and-filter-fields">Rename and filter fields</h3>
82
- <pre><code class="hljs language-bash">mapshaper data.csv \
83
- -rename-fields POPULATION=POP,MEDIAN_INCOME=MEDIAN_INC \
84
- -filter-fields STATE,COUNTY,POPULATION,MEDIAN_INCOME \
85
- -o cleaned.csv
86
- </code></pre>
87
- <p><code>-rename-fields</code> takes <code>NEW=OLD</code> pairs. <code>-filter-fields</code> keeps only the listed fields, in the listed order &mdash; convenient for shaping CSV output.</p>
88
- <h3 id="preserve-leading-zeros-from-a-csv">Preserve leading zeros from a CSV</h3>
89
- <pre><code class="hljs language-bash">mapshaper -i counties.csv string-fields=FIPS,STATEFIPS \
90
- -o counties.shp
91
- </code></pre>
92
- <p>By default Mapshaper parses any numeric-looking CSV column as a number, which silently drops leading zeros from FIPS, ZIP and similar identifier columns. <code>string-fields=</code> forces the named columns to stay as strings.</p>
93
- <h2 id="joining-data">Joining data</h2>
94
- <h3 id="join-a-csv-to-a-shapefile-by-key">Join a CSV to a Shapefile by key</h3>
95
- <pre><code class="hljs language-bash">mapshaper states.shp \
96
- -<span class="hljs-built_in">join</span> demographics.csv keys=STATE_FIPS,FIPS string-fields=FIPS \
97
- -o states_with_data.shp
98
- </code></pre>
99
- <p><code>keys=A,B</code> means &quot;match the target&#39;s <code>A</code> field to the source&#39;s <code>B</code> field&quot;. <code>string-fields=FIPS</code> (passed through to the CSV import) keeps the FIPS code as a string so <code>&quot;06&quot;</code> matches <code>&quot;06&quot;</code> rather than being parsed to <code>6</code>. To pull just a few columns from the source, add <code>fields=FIELD_A,FIELD_B</code>.</p>
100
- <h3 id="spatial-join-tag-points-with-the-polygon-they-fall-in">Spatial join: tag points with the polygon they fall in</h3>
101
- <pre><code class="hljs language-bash">mapshaper crimes.geojson \
102
- -<span class="hljs-built_in">join</span> precinct_polygons.shp \
103
- -o crimes_with_precinct.geojson
104
- </code></pre>
105
- <p>When <code>keys=</code> is omitted, <code>-join</code> falls back to a spatial join based on the geometry types involved. Here, every point inherits the attributes of the polygon containing it. Use <code>fields=PRECINCT_ID,DIVISION</code> to keep just specific columns.</p>
106
- <h3 id="many-to-one-join-with-an-aggregation">Many-to-one join with an aggregation</h3>
107
- <pre><code class="hljs language-bash">mapshaper precincts.shp \
108
- -<span class="hljs-built_in">join</span> crimes.geojson calc=<span class="hljs-string">&#x27;N = count(), AVG_SEVERITY = mean(SEVERITY)&#x27;</span> \
109
- -o precincts_with_stats.shp
110
- </code></pre>
111
- <p>A polygon-to-many-points join can use <code>calc=</code> to summarize the matched source records into one or more new fields per target feature. The functions in <code>calc=</code> are the same set documented under <a href="/docs/reference.html#-calc"><code>-calc</code></a>.</p>
112
- <h2 id="simplifying">Simplifying</h2>
113
- <h3 id="simplify-a-polygon-layer-for-the-web">Simplify a polygon layer for the web</h3>
114
- <pre><code class="hljs language-bash">mapshaper provinces.shp \
115
- -simplify 5% keep-shapes \
116
- -clean \
117
- -o format=topojson provinces.topojson
118
- </code></pre>
119
- <p><code>-simplify 5%</code> keeps 5% of the original vertices using the default weighted Visvalingam algorithm. <code>keep-shapes</code> prevents simplification from wiping out very small polygons. <code>-clean</code> mops up any topology errors introduced by aggressive simplification. TopoJSON output is usually 2&ndash;5x smaller than the equivalent GeoJSON.</p>
120
- <h3 id="simplify-multiple-files-with-shared-topology">Simplify multiple files with shared topology</h3>
121
- <pre><code class="hljs language-bash">mapshaper -i states.shp counties.shp combine-files \
122
- -simplify 10% \
123
- -o out/
124
- </code></pre>
125
- <p><code>combine-files</code> merges the inputs into one dataset before Mapshaper builds its arc topology, so vertices shared between layers stay shared after simplification &mdash; no gaps or overlaps along state/county boundaries. Each input still gets written back out as a separate file in <code>out/</code>. In the web app, add <code>combine-files</code> in the <strong>Advanced options</strong> field at import time to get the same behavior.</p>
126
- <h3 id="repair-topology-errors">Repair topology errors</h3>
127
- <pre><code class="hljs language-bash">mapshaper messy.shp -clean -o cleaned.shp
128
- </code></pre>
129
- <p><code>-clean</code> snaps near-duplicate vertices, removes tiny gaps and overlaps between polygons, and fixes self-intersecting lines. It&#39;s a safe first step before any spatial operation. You can tune <code>gap-fill-area=</code>, <code>sliver-control=</code> or <code>snap-interval=</code> if necessary.</p>
130
- <h2 id="aggregating">Aggregating</h2>
131
- <h3 id="dissolve-to-a-parent-geography">Dissolve to a parent geography</h3>
132
- <pre><code class="hljs language-bash">mapshaper counties.shp -dissolve STATE -o states.shp
133
- </code></pre>
134
- <p><code>-dissolve</code> merges adjacent polygons that share a value in the named field.</p>
135
- <h3 id="dissolve-while-computing-per-group-stats">Dissolve while computing per-group stats</h3>
136
- <pre><code class="hljs language-bash">mapshaper counties.shp \
137
- -dissolve STATE calc=<span class="hljs-string">&#x27;N = count(),
138
- POP = sum(POP),
139
- MEDIAN_INC = median(MEDIAN_INC)&#x27;</span> \
140
- -o states_with_stats.shp
141
- </code></pre>
142
- <p><code>calc=</code> works inside <code>-dissolve</code> as well as <code>-join</code>. The named functions (<code>count</code>, <code>sum</code>, <code>mean</code>, <code>median</code>, <code>mode</code>, <code>min</code>, <code>max</code>, <code>quartile1/2/3</code>, <code>iqr</code>, <code>quantile</code>, <code>collect</code>, <code>every</code>, <code>some</code>, <code>first</code>, <code>last</code>) all see the same per-feature context as <code>-each</code>.</p>
143
- <h3 id="convert-points-to-population-weighted-centroids">Convert points to population-weighted centroids</h3>
144
- <pre><code class="hljs language-bash">mapshaper cities.shp \
145
- -dissolve STATE_FIPS weight=POPULATION \
146
- -o state_centers.shp
147
- </code></pre>
148
- <p>Dissolve groups of points that share a <code>STATE_FIPS</code> value into a single weighted centroid per group. The <code>weight=</code> option accepts a field name or a JS expression. Omitting a grouping field dissolves all points into one centroid.</p>
149
- <h2 id="spatial-operations">Spatial operations</h2>
150
- <h3 id="erase-one-layer-from-another">Erase one layer from another</h3>
151
- <pre><code class="hljs language-bash">mapshaper land.shp -erase lakes.shp -o land_no_lakes.shp
152
- </code></pre>
153
- <p><code>-erase</code> removes the parts of the target layer that fall inside the source layer&#39;s polygons. Useful for masking out water, parks, or any &quot;do-not-count&quot; region. The inverse is <code>-clip</code>, which keeps the inside instead.</p>
154
- <h3 id="compute-interior-boundaries">Compute interior boundaries</h3>
155
- <pre><code class="hljs language-bash">mapshaper counties.shp -innerlines -o county_borders.shp
156
- </code></pre>
157
- <p><code>-innerlines</code> 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 <a href="/docs/reference.html#-lines"><code>-lines</code></a> instead if you want to retain both outer and inner boundaries.</p>
158
- <h3 id="generate-a-hex-grid-covering-a-layer">Generate a hex grid covering a layer</h3>
159
- <pre><code class="hljs language-bash">mapshaper region.shp \
160
- -grid <span class="hljs-built_in">type</span>=hex interval=10km name=hex \
161
- -o hex.shp
162
- </code></pre>
163
- <p><code>-grid</code> builds a regular grid (<code>square</code>, <code>hex</code>, <code>hex2</code>) covering the target&#39;s bounding box. Pair it with a spatial join to style the grid cells using interpolated count data (<code>-join interpolate=POPULATION</code>).</p>
164
- <h2 id="reprojection">Reprojection</h2>
165
- <h3 id="project-to-a-named-crs">Project to a named CRS</h3>
166
- <pre><code class="hljs language-bash">mapshaper world.geojson -proj robinson -o world_robinson.geojson
167
- </code></pre>
168
- <p><code>-proj</code> accepts EPSG codes (<code>EPSG:3857</code>), PROJ strings (<code>+proj=tmerc +lon_0=...</code>), or short aliases (<code>wgs84</code>, <code>webmercator</code>, <code>robinson</code>, <code>albersusa</code>). See the <a href="/docs/guides/projections.html">Projections guide</a> for details.</p>
169
- <h3 id="match-the-projection-of-another-file">Match the projection of another file</h3>
170
- <pre><code class="hljs language-bash">mapshaper points.shp -proj match=basemap.shp -o points_aligned.shp
171
- </code></pre>
172
- <p><code>match=</code> reads the CRS of another file and projects the target to match it &mdash; handy when assembling multiple datasets that need to share a coordinate system.</p>
173
- <h2 id="classification-and-styling">Classification and styling</h2>
174
- <h3 id="quantile-classify-into-a-color-ramp">Quantile-classify into a color ramp</h3>
175
- <pre><code class="hljs language-bash">mapshaper covid_cases.geojson \
176
- -classify save-as=fill quantile classes=6 color-scheme=Oranges \
177
- -o themed.geojson
178
- </code></pre>
179
- <p><code>-classify</code> 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 <code>equal-interval</code>, <code>nice</code>, <code>categorical</code> or <code>non-adjacent</code>. Run <code>mapshaper -colors</code> to list the built-in color schemes.</p>
180
- <h3 id="add-svg-styling-for-export">Add SVG styling for export</h3>
181
- <pre><code class="hljs language-bash">mapshaper boundaries.shp \
182
- -style stroke=<span class="hljs-string">&quot;#444&quot;</span> stroke-width=0.5 fill=none \
183
- -style <span class="hljs-built_in">where</span>=<span class="hljs-string">&#x27;RANK == 0&#x27;</span> stroke=<span class="hljs-string">&quot;#000&quot;</span> stroke-width=1.5 \
184
- -o map.svg
185
- </code></pre>
186
- <p><code>-style</code> writes SVG presentation attributes onto each feature; the <code>where=</code> form lets you set them conditionally. The result is a valid SVG you can drop into a print or web layout.</p>
187
- <h2 id="output-and-conversion">Output and conversion</h2>
188
- <h3 id="convert-shapefile-harr-geojson">Convert Shapefile &harr; GeoJSON</h3>
189
- <pre><code class="hljs language-bash">mapshaper input.shp -o input.geojson
190
- mapshaper input.geojson -o input.shp
191
- </code></pre>
192
- <p>The output format is inferred from the file extension. Use <code>format=</code> to force it (e.g. <code>-o format=topojson out.json</code>). When writing a Shapefile, Mapshaper produces <code>.shp</code>, <code>.shx</code>, <code>.dbf</code>, and <code>.prj</code>. If no output filename is given, the output file takes the name of the targeted layer.</p>
193
- <h3 id="quantized-topojson">Quantized TopoJSON</h3>
194
- <pre><code class="hljs language-bash">mapshaper boundaries.shp -o boundaries.topojson
195
- </code></pre>
196
- <p>TopoJSON output is quantized by default — Mapshaper picks a quantization level based on the data&#39;s coordinate range. Quantization rounds coordinates to a grid, which dramatically shrinks file size. The default can be overridden with <code>quantization=</code> (e.g. <code>quantization=1e5</code>). Combined with <code>-simplify</code> and TopoJSON&#39;s shared-arc encoding, quantized output is routinely 2&ndash;5&times; smaller than equivalent GeoJSON.</p>
197
- <h3 id="output-as-ndjson">Output as ndjson</h3>
198
- <pre><code class="hljs language-bash">mapshaper big.geojson -o ndjson big.ndjson
199
- </code></pre>
200
- <p>Newline-delimited JSON is friendlier to line-oriented tools like jq, BigQuery, and DuckDB. One Feature per line, no enclosing FeatureCollection.</p>
201
- <h3 id="split-a-layer-into-multiple-files">Split a layer into multiple files</h3>
202
- <pre><code class="hljs language-bash">mapshaper counties.shp \
203
- -<span class="hljs-built_in">split</span> STATE \
204
- -o out/ extension=geojson
205
- </code></pre>
206
- <p><code>-split FIELD</code> partitions features into separate layers by the value of <code>FIELD</code>; <code>-o</code> to a directory then writes one file per layer, named after the field value.</p>
207
- <h2 id="workflow-patterns">Workflow patterns</h2>
208
- <h3 id="run-a-chain-of-commands-from-a-file">Run a chain of commands from a file</h3>
209
- <pre><code># build.txt
210
- mapshaper
211
- -i counties.shp
212
- -rename-fields POP=POPULATION
213
- -dissolve STATE calc=&#39;POP = sum(POP)&#39;
214
- -simplify 5%
215
- -o out/states.topojson
216
- </code></pre>
217
- <pre><code class="hljs language-bash">mapshaper -run build.txt
218
- <span class="hljs-comment"># or simply:</span>
219
- mapshaper build.txt
220
- </code></pre>
221
- <p>Long pipelines can be kept in a <a href="/docs/reference.html#command-files">command file</a>.</p>
222
- <h3 id="parameterize-a-command-file">Parameterize a command file</h3>
223
- <pre><code class="hljs language-bash">mapshaper -vars YEAR=2024 PCT=10 -run build.txt
224
- </code></pre>
225
- <pre><code># build.txt
226
- mapshaper
227
- -defaults YEAR=2020 PCT=5
228
- -i sources/counties_{{YEAR}}.shp
229
- -simplify {{PCT}}%
230
- -o out/counties_{{YEAR}}.shp
231
- </code></pre>
232
- <p><code>{{VAR}}</code> placeholders are substituted at parse time. <code>-defaults</code> sets values that the caller can override with <code>-vars</code> (or with <code>{{env.NAME}}</code> for environment variables).</p>
233
- <h3 id="stop-a-pipeline-early-on-bad-input">Stop a pipeline early on bad input</h3>
234
- <pre><code class="hljs language-bash">mapshaper input.csv \
235
- -calc <span class="hljs-string">&#x27;N = count()&#x27;</span> \
236
- -<span class="hljs-keyword">if</span> <span class="hljs-string">&#x27;global.N == 0&#x27;</span> \
237
- -<span class="hljs-built_in">print</span> <span class="hljs-string">&#x27;No records, exiting&#x27;</span> \
238
- -stop \
239
- -endif \
240
- -o out.csv
241
- </code></pre>
242
- <p><code>-calc</code> expressions can publish values to the <code>global</code> object via simple assignment. <code>-if</code>/<code>-stop</code> then guard the rest of the pipeline. Useful in scripts where bad upstream data should fail loudly rather than silently produce empty output.</p>
243
- <h3 id="increase-the-heap-for-very-large-files">Increase the heap for very large files</h3>
244
- <pre><code class="hljs language-bash">mapshaper-xl 16gb counties_5m.shp -simplify 10% -o counties_5m.topojson
245
- </code></pre>
246
- <p><code>mapshaper-xl</code> is a wrapper that launches Node with extra heap space (default 8 GB; pass a size to override). Use it whenever you see &quot;JavaScript heap out of memory&quot; errors.</p>
247
- <h2 id="see-also">See also</h2>
248
- <ul>
249
- <li><a href="/docs/reference.html">Command reference</a> &mdash; every command and option</li>
250
- <li><a href="/docs/guides/expressions.html">JavaScript expressions</a> &mdash; the syntax and context used by <code>-each</code>, <code>-filter</code>, <code>calc=</code>, etc.</li>
251
- <li><a href="/docs/guides/">Guides</a> &mdash; longer-form walk-throughs of simplification, topology cleaning, and more</li>
252
- </ul>
253
-
254
- <div class="edit-link">
255
- <a href="https://github.com/mbloch/mapshaper/edit/master/docs/examples/basics.md">Edit this page on GitHub</a>
256
- </div>
257
- </article>
258
- </main>
259
-
260
- <aside class="docs-toc">
261
- <div class="docs-toc-title">On this page</div><ul><li class="lvl-2"><a href="#inspecting-and-exploring">Inspecting and exploring</a></li><li class="lvl-3"><a href="#print-a-summary-of-a-dataset">Print a summary of a dataset</a></li><li class="lvl-3"><a href="#count-features-grouped-by-a-field">Count features grouped by a field</a></li><li class="lvl-2"><a href="#filtering-and-selecting">Filtering and selecting</a></li><li class="lvl-3"><a href="#keep-features-matching-a-condition">Keep features matching a condition</a></li><li class="lvl-3"><a href="#keep-features-inside-a-bounding-box">Keep features inside a bounding box</a></li><li class="lvl-3"><a href="#keep-the-top-n-features-by-some-attribute">Keep the top N features by some attribute</a></li><li class="lvl-3"><a href="#drop-features-with-empty-geometry">Drop features with empty geometry</a></li><li class="lvl-2"><a href="#editing-attributes">Editing attributes</a></li><li class="lvl-3"><a href="#add-derived-fields">Add derived fields</a></li><li class="lvl-3"><a href="#rename-and-filter-fields">Rename and filter fields</a></li><li class="lvl-3"><a href="#preserve-leading-zeros-from-a-csv">Preserve leading zeros from a CSV</a></li><li class="lvl-2"><a href="#joining-data">Joining data</a></li><li class="lvl-3"><a href="#join-a-csv-to-a-shapefile-by-key">Join a CSV to a Shapefile by key</a></li><li class="lvl-3"><a href="#spatial-join-tag-points-with-the-polygon-they-fall-in">Spatial join: tag points with the polygon they fall in</a></li><li class="lvl-3"><a href="#many-to-one-join-with-an-aggregation">Many-to-one join with an aggregation</a></li><li class="lvl-2"><a href="#simplifying">Simplifying</a></li><li class="lvl-3"><a href="#simplify-a-polygon-layer-for-the-web">Simplify a polygon layer for the web</a></li><li class="lvl-3"><a href="#simplify-multiple-files-with-shared-topology">Simplify multiple files with shared topology</a></li><li class="lvl-3"><a href="#repair-topology-errors">Repair topology errors</a></li><li class="lvl-2"><a href="#aggregating">Aggregating</a></li><li class="lvl-3"><a href="#dissolve-to-a-parent-geography">Dissolve to a parent geography</a></li><li class="lvl-3"><a href="#dissolve-while-computing-per-group-stats">Dissolve while computing per-group stats</a></li><li class="lvl-3"><a href="#convert-points-to-population-weighted-centroids">Convert points to population-weighted centroids</a></li><li class="lvl-2"><a href="#spatial-operations">Spatial operations</a></li><li class="lvl-3"><a href="#erase-one-layer-from-another">Erase one layer from another</a></li><li class="lvl-3"><a href="#compute-interior-boundaries">Compute interior boundaries</a></li><li class="lvl-3"><a href="#generate-a-hex-grid-covering-a-layer">Generate a hex grid covering a layer</a></li><li class="lvl-2"><a href="#reprojection">Reprojection</a></li><li class="lvl-3"><a href="#project-to-a-named-crs">Project to a named CRS</a></li><li class="lvl-3"><a href="#match-the-projection-of-another-file">Match the projection of another file</a></li><li class="lvl-2"><a href="#classification-and-styling">Classification and styling</a></li><li class="lvl-3"><a href="#quantile-classify-into-a-color-ramp">Quantile-classify into a color ramp</a></li><li class="lvl-3"><a href="#add-svg-styling-for-export">Add SVG styling for export</a></li><li class="lvl-2"><a href="#output-and-conversion">Output and conversion</a></li><li class="lvl-3"><a href="#convert-shapefile-harr-geojson">Convert Shapefile &amp;harr; GeoJSON</a></li><li class="lvl-3"><a href="#quantized-topojson">Quantized TopoJSON</a></li><li class="lvl-3"><a href="#output-as-ndjson">Output as ndjson</a></li><li class="lvl-3"><a href="#split-a-layer-into-multiple-files">Split a layer into multiple files</a></li><li class="lvl-2"><a href="#workflow-patterns">Workflow patterns</a></li><li class="lvl-3"><a href="#run-a-chain-of-commands-from-a-file">Run a chain of commands from a file</a></li><li class="lvl-3"><a href="#parameterize-a-command-file">Parameterize a command file</a></li><li class="lvl-3"><a href="#stop-a-pipeline-early-on-bad-input">Stop a pipeline early on bad input</a></li><li class="lvl-3"><a href="#increase-the-heap-for-very-large-files">Increase the heap for very large files</a></li><li class="lvl-2"><a href="#see-also">See also</a></li></ul>
262
- </aside>
263
-
264
- </div>
265
-
266
- <script src="/docs/_assets/docs.js" defer></script>
267
-
268
- <footer class="docs-footer">
269
- <div class="docs-footer-inner">
270
- <span>mapshaper is free software, licensed under <a href="https://www.mozilla.org/MPL/2.0/">MPL 2.0</a>.</span>
271
- <span><a href="/privacy.html">Privacy</a> &middot; <a href="/terms.html">Terms</a> &middot; <a href="/sponsor.html">Support mapshaper</a></span>
272
- </div>
273
- </footer>
274
-
275
- </body>
276
- </html>