Skip to content

Commit c027c20

Browse files
committed
Update website
1 parent 246fa62 commit c027c20

26 files changed

Lines changed: 1215 additions & 663 deletions

docs/essentials/command-line.html

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,64 @@ <h2 id="working-with-layers">Working with layers</h2>
116116
<pre><code class="hljs language-bash">mapshaper usa.topojson \
117117
-filter <span class="hljs-string">&#x27;STATE == &quot;HI&quot;&#x27;</span> target=states \
118118
-o out/hawaii.geojson
119+
</code></pre>
120+
<h2 id="command-files">Command files</h2>
121+
<p>As an alternative to typing commands on the command line, you can put them in a plain-text command file and run them with the mapshaper CLI.</p>
122+
<p>Command files offer a few conveniences over a shell script or Makefile:</p>
123+
<ul>
124+
<li>Hash-delimited (<code>#</code>) comments, both on their own line and at the end of a line.</li>
125+
<li>No need to escape <code>*</code> or other shell metacharacters; commands aren&#39;t passed through the shell.</li>
126+
<li>Trailing-backslash line continuations are accepted but not required &mdash; lines that don&#39;t begin with <code>-</code> are joined onto the previous command.</li>
127+
<li>Variable interpolation using <code>{{VAR}}</code> placeholders. See <a href="#variables">variables</a> below.</li>
128+
</ul>
129+
<p>(Support for running command files in the mapshaper web UI is planned for a future release.)</p>
130+
<h3 id="file-format">File format</h3>
131+
<p>A mapshaper command file is a <code>.txt</code> file whose first non-blank, non-comment line starts with <code>mapshaper</code>.</p>
132+
<pre><code>mapshaper
133+
-i provinces.shp
134+
# Use Douglas Peucker simplification
135+
-simplify dp 20%
136+
-o precision=0.00001 output.geojson
137+
</code></pre>
138+
<p>If you write the command file using shell-compatible syntax &mdash; trailing <code>\</code> for line continuations and no <code>#</code> comments &mdash; it can also be pasted directly onto a bash command line, where the leading <code>mapshaper</code> word invokes the CLI. To make the above example shell compatible, you could write:</p>
139+
<pre><code>mapshaper \
140+
-i provinces.shp \
141+
-simplify dp 20% \
142+
-o precision=0.00001 output.geojson
143+
</code></pre>
144+
<h3 id="running-a-command-file">Running a command file</h3>
145+
<p>The command for running a command file is <a href="#-run"><code>-run</code></a>:</p>
146+
<pre><code class="hljs language-bash">mapshaper -run build.txt
147+
</code></pre>
148+
<p><code>mapshaper commands.txt</code> is a shortcut for <code>mapshaper -run commands.txt</code>.</p>
149+
<h2 id="variable-interpolation">Variable interpolation</h2>
150+
<p>Command files and command lines may contain <code>{{VAR}}</code> placeholders, which are substituted just before each command runs. Two forms are recognized:</p>
151+
<ul>
152+
<li><code>{{VAR}}</code> &mdash; substituted with the value of <code>VAR</code>.</li>
153+
<li><code>{{env.NAME}}</code> &mdash; substituted with the value of the <code>NAME</code> environment variable.</li>
154+
</ul>
155+
<p>This syntax allows you to interpolate all or part of a command option. For example, <code>-simplify {{SIMPLIFY_METHOD}} resolution={{SIMPLIFY_RESOLUTION}}</code>.</p>
156+
<p>Variables can be set in several ways:</p>
157+
<ul>
158+
<li>The <a href="#-vars"><code>-vars</code></a> command sets one or more variables, always overwriting any previous value.</li>
159+
<li>The <a href="#-defaults"><code>-defaults</code></a> command set only those values that do not already exist.</li>
160+
<li>Assignments in <code>-calc</code> and <code>-define</code> expressions create new variables.</li>
161+
<li>Assigning a property to the <code>global</code> object in an <code>-each</code> expression creates a new variable.</li>
162+
</ul>
163+
<p><code>-vars</code> and <code>-defaults</code> write to a templating-scope store; the other commands write to an expression-scope store (<code>global</code>). <code>{{X}}</code> substitution checks the templating scope first and falls back to the expression scope, so values from any of the four mechanisms above are reachable. Bare names in JS expressions only see the expression scope &mdash; a name set by <code>-vars</code> is <em>not</em> readable by bare name from inside <code>-each</code>, <code>-filter</code>, etc. See <a href="/docs/guides/expressions.html#sharing-state-across-commands">JavaScript expressions</a> for the full story.</p>
164+
<h4 id="example">Example</h4>
165+
<p><code>build.txt</code>:</p>
166+
<pre><code>mapshaper
167+
-defaults YEAR=2024 PCT=10 # overridable defaults
168+
-i sources/counties_{{YEAR}}.shp
169+
-simplify {{PCT}}%
170+
-o out/counties_{{YEAR}}_simplified.shp
171+
</code></pre>
172+
<p>Run with the command file&#39;s defaults:</p>
173+
<pre><code class="hljs language-bash">mapshaper build.txt
174+
</code></pre>
175+
<p>Or override default values from the command line:</p>
176+
<pre><code class="hljs language-bash">mapshaper -vars YEAR=2030 PCT=5 -run build.txt
119177
</code></pre>
120178

121179
<div class="edit-link">
@@ -125,7 +183,7 @@ <h2 id="working-with-layers">Working with layers</h2>
125183
</main>
126184

127185
<aside class="docs-toc">
128-
<div class="docs-toc-title">On this page</div><ul><li class="lvl-2"><a href="#install">Install</a></li><li class="lvl-2"><a href="#anatomy-of-a-mapshaper-command">Anatomy of a Mapshaper command</a></li><li class="lvl-2"><a href="#some-examples">Some examples</a></li><li class="lvl-3"><a href="#get-help">Get help</a></li><li class="lvl-3"><a href="#chain-commands">Chain commands</a></li><li class="lvl-2"><a href="#working-with-layers">Working with layers</a></li></ul>
186+
<div class="docs-toc-title">On this page</div><ul><li class="lvl-2"><a href="#install">Install</a></li><li class="lvl-2"><a href="#anatomy-of-a-mapshaper-command">Anatomy of a Mapshaper command</a></li><li class="lvl-2"><a href="#some-examples">Some examples</a></li><li class="lvl-3"><a href="#get-help">Get help</a></li><li class="lvl-3"><a href="#chain-commands">Chain commands</a></li><li class="lvl-2"><a href="#working-with-layers">Working with layers</a></li><li class="lvl-2"><a href="#command-files">Command files</a></li><li class="lvl-3"><a href="#file-format">File format</a></li><li class="lvl-3"><a href="#running-a-command-file">Running a command file</a></li><li class="lvl-2"><a href="#variable-interpolation">Variable interpolation</a></li></ul>
129187
</aside>
130188

131189
</div>

docs/essentials/command-line.html.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,85 @@ mapshaper usa.topojson \
110110
-filter 'STATE == "HI"' target=states \
111111
-o out/hawaii.geojson
112112
```
113+
114+
## Command files
115+
116+
As an alternative to typing commands on the command line, you can put them in a plain-text command file and run them with the mapshaper CLI.
117+
118+
Command files offer a few conveniences over a shell script or Makefile:
119+
120+
- Hash-delimited (`#`) comments, both on their own line and at the end of a line.
121+
- No need to escape `*` or other shell metacharacters; commands aren't passed through the shell.
122+
- Trailing-backslash line continuations are accepted but not required &mdash; lines that don't begin with `-` are joined onto the previous command.
123+
- Variable interpolation using `{{VAR}}` placeholders. See [variables](#variables) below.
124+
125+
(Support for running command files in the mapshaper web UI is planned for a future release.)
126+
127+
### File format
128+
129+
A mapshaper command file is a `.txt` file whose first non-blank, non-comment line starts with `mapshaper`.
130+
131+
```
132+
mapshaper
133+
-i provinces.shp
134+
# Use Douglas Peucker simplification
135+
-simplify dp 20%
136+
-o precision=0.00001 output.geojson
137+
```
138+
139+
If you write the command file using shell-compatible syntax &mdash; trailing `\` for line continuations and no `#` comments &mdash; it can also be pasted directly onto a bash command line, where the leading `mapshaper` word invokes the CLI. To make the above example shell compatible, you could write:
140+
141+
```
142+
mapshaper \
143+
-i provinces.shp \
144+
-simplify dp 20% \
145+
-o precision=0.00001 output.geojson
146+
```
147+
148+
### Running a command file
149+
150+
The command for running a command file is [`-run`](#-run):
151+
152+
```bash
153+
mapshaper -run build.txt
154+
```
155+
156+
`mapshaper commands.txt` is a shortcut for `mapshaper -run commands.txt`.
157+
158+
## Variable interpolation
159+
160+
Command files and command lines may contain `{{VAR}}` placeholders, which are substituted just before each command runs. Two forms are recognized:
161+
162+
- `{{VAR}}` &mdash; substituted with the value of `VAR`.
163+
- `{{env.NAME}}` &mdash; substituted with the value of the `NAME` environment variable.
164+
165+
This syntax allows you to interpolate all or part of a command option. For example, `-simplify {{SIMPLIFY_METHOD}} resolution={{SIMPLIFY_RESOLUTION}}`.
166+
167+
Variables can be set in several ways:
168+
- The [`-vars`](#-vars) command sets one or more variables, always overwriting any previous value.
169+
- The [`-defaults`](#-defaults) command set only those values that do not already exist.
170+
- Assignments in `-calc` and `-define` expressions create new variables.
171+
- Assigning a property to the `global` object in an `-each` expression creates a new variable.
172+
173+
`-vars` and `-defaults` write to a templating-scope store; the other commands write to an expression-scope store (`global`). `{{X}}` substitution checks the templating scope first and falls back to the expression scope, so values from any of the four mechanisms above are reachable. Bare names in JS expressions only see the expression scope &mdash; a name set by `-vars` is *not* readable by bare name from inside `-each`, `-filter`, etc. See [JavaScript expressions](/docs/guides/expressions.html.md#sharing-state-across-commands) for the full story.
174+
175+
#### Example
176+
177+
`build.txt`:
178+
```
179+
mapshaper
180+
-defaults YEAR=2024 PCT=10 # overridable defaults
181+
-i sources/counties_{{YEAR}}.shp
182+
-simplify {{PCT}}%
183+
-o out/counties_{{YEAR}}_simplified.shp
184+
```
185+
186+
Run with the command file's defaults:
187+
```bash
188+
mapshaper build.txt
189+
```
190+
191+
Or override default values from the command line:
192+
```bash
193+
mapshaper -vars YEAR=2030 PCT=5 -run build.txt
194+
```

docs/essentials/web-app.html

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,6 @@ <h2 id="running-the-web-ui-locally">Running the web UI locally</h2>
146146
<p>You can pre-load files by listing them on the command line, which skips the import dialog:</p>
147147
<pre><code class="hljs language-bash">mapshaper-gui states.shp rivers.shp
148148
</code></pre>
149-
<h2 id="optional-ai-assistant">Optional AI assistant</h2>
150-
<p>Some Mapshaper installations may enable an optional AI assistant by serving an <code>ai-config.js</code> file alongside the web app. If the file is missing or disabled, no assistant UI is shown.</p>
151-
<p>When enabled, the assistant can receive the same runtime context shown by the console&#39;s <code>context</code> command: layer names, field names/types, feature counts, CRS, recent commands and recent messages. It does not include geometry or full attribute records.</p>
152-
<p>Development builds can use a mock assistant or direct provider calls from <code>localhost</code>. Production deployments should use a proxy endpoint so provider secrets, rate limits and logging policy are not exposed in the browser.</p>
153-
<p>An <code>ai-config.js</code> file can also point the assistant at static documentation, such as <code>llms-full.txt</code>, for providers or proxies that support prompt caching:</p>
154-
<pre><code class="hljs language-js"><span class="hljs-variable language_">window</span>.<span class="hljs-property">mapshaperAI</span> = {
155-
<span class="hljs-attr">enabled</span>: <span class="hljs-literal">true</span>,
156-
<span class="hljs-attr">mode</span>: <span class="hljs-string">&quot;proxy&quot;</span>,
157-
<span class="hljs-attr">endpoint</span>: <span class="hljs-string">&quot;/api/mapshaper-assist&quot;</span>,
158-
<span class="hljs-attr">staticContextUrl</span>: <span class="hljs-string">&quot;/llms-full.txt&quot;</span>,
159-
<span class="hljs-attr">cacheControl</span>: {<span class="hljs-attr">type</span>: <span class="hljs-string">&quot;ephemeral&quot;</span>},
160-
<span class="hljs-attr">cacheTtl</span>: <span class="hljs-string">&quot;1h&quot;</span>
161-
};
162-
</code></pre>
163-
<p>For local testing without a proxy, <code>mode: &quot;direct&quot;</code> supports OpenAI-compatible Responses requests and Anthropic Messages requests. Anthropic direct mode sends static context as cacheable system content when <code>provider: &quot;anthropic&quot;</code> is configured. Direct mode should only be used with disposable development keys on <code>localhost</code>.</p>
164149
<h2 id="browser-support">Browser support</h2>
165150
<p>When importing very large files (hundreds of megabytes), the web app may run out of memory and crash. Firefox used to be better than Chrome at handling large files, but Chrome seems to have improved recently. If the web app crashes, try the <a href="/docs/essentials/command-line.html"><code>mapshaper-xl</code> command-line tool</a>, which can allocate a large amount of memory.</p>
166151
<h2 id="privacy">Privacy</h2>
@@ -173,7 +158,7 @@ <h2 id="privacy">Privacy</h2>
173158
</main>
174159

175160
<aside class="docs-toc">
176-
<div class="docs-toc-title">On this page</div><ul><li class="lvl-2"><a href="#loading-data">Loading data</a></li><li class="lvl-3"><a href="#tips-for-importing-shapefiles">Tips for importing Shapefiles</a></li><li class="lvl-2"><a href="#the-console">The console</a></li><li class="lvl-3"><a href="#keyboard">Keyboard</a></li><li class="lvl-3"><a href="#syntax">Syntax</a></li><li class="lvl-3"><a href="#using-cli-examples-in-the-web-console">Using CLI examples in the web console</a></li><li class="lvl-3"><a href="#magic-words-at-the-prompt">Magic words at the prompt</a></li><li class="lvl-3"><a href="#discovering-commands">Discovering commands</a></li><li class="lvl-2"><a href="#the-map">The map</a></li><li class="lvl-3"><a href="#right-click-menu">Right-click menu</a></li><li class="lvl-3"><a href="#layer-navigation">Layer navigation</a></li><li class="lvl-2"><a href="#display-options">Display options</a></li><li class="lvl-2"><a href="#snapshots-and-session-history">Snapshots and session history</a></li><li class="lvl-2"><a href="#running-the-web-ui-locally">Running the web UI locally</a></li><li class="lvl-2"><a href="#optional-ai-assistant">Optional AI assistant</a></li><li class="lvl-2"><a href="#browser-support">Browser support</a></li><li class="lvl-2"><a href="#privacy">Privacy</a></li></ul>
161+
<div class="docs-toc-title">On this page</div><ul><li class="lvl-2"><a href="#loading-data">Loading data</a></li><li class="lvl-3"><a href="#tips-for-importing-shapefiles">Tips for importing Shapefiles</a></li><li class="lvl-2"><a href="#the-console">The console</a></li><li class="lvl-3"><a href="#keyboard">Keyboard</a></li><li class="lvl-3"><a href="#syntax">Syntax</a></li><li class="lvl-3"><a href="#using-cli-examples-in-the-web-console">Using CLI examples in the web console</a></li><li class="lvl-3"><a href="#magic-words-at-the-prompt">Magic words at the prompt</a></li><li class="lvl-3"><a href="#discovering-commands">Discovering commands</a></li><li class="lvl-2"><a href="#the-map">The map</a></li><li class="lvl-3"><a href="#right-click-menu">Right-click menu</a></li><li class="lvl-3"><a href="#layer-navigation">Layer navigation</a></li><li class="lvl-2"><a href="#display-options">Display options</a></li><li class="lvl-2"><a href="#snapshots-and-session-history">Snapshots and session history</a></li><li class="lvl-2"><a href="#running-the-web-ui-locally">Running the web UI locally</a></li><li class="lvl-2"><a href="#browser-support">Browser support</a></li><li class="lvl-2"><a href="#privacy">Privacy</a></li></ul>
177162
</aside>
178163

179164
</div>

docs/essentials/web-app.html.md

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -128,29 +128,6 @@ You can pre-load files by listing them on the command line, which skips the impo
128128
mapshaper-gui states.shp rivers.shp
129129
```
130130

131-
## Optional AI assistant
132-
133-
Some Mapshaper installations may enable an optional AI assistant by serving an `ai-config.js` file alongside the web app. If the file is missing or disabled, no assistant UI is shown.
134-
135-
When enabled, the assistant can receive the same runtime context shown by the console's `context` command: layer names, field names/types, feature counts, CRS, recent commands and recent messages. It does not include geometry or full attribute records.
136-
137-
Development builds can use a mock assistant or direct provider calls from `localhost`. Production deployments should use a proxy endpoint so provider secrets, rate limits and logging policy are not exposed in the browser.
138-
139-
An `ai-config.js` file can also point the assistant at static documentation, such as `llms-full.txt`, for providers or proxies that support prompt caching:
140-
141-
```js
142-
window.mapshaperAI = {
143-
enabled: true,
144-
mode: "proxy",
145-
endpoint: "/api/mapshaper-assist",
146-
staticContextUrl: "/llms-full.txt",
147-
cacheControl: {type: "ephemeral"},
148-
cacheTtl: "1h"
149-
};
150-
```
151-
152-
For local testing without a proxy, `mode: "direct"` supports OpenAI-compatible Responses requests and Anthropic Messages requests. Anthropic direct mode sends static context as cacheable system content when `provider: "anthropic"` is configured. Direct mode should only be used with disposable development keys on `localhost`.
153-
154131
## Browser support
155132

156133
When importing very large files (hundreds of megabytes), the web app may run out of memory and crash. Firefox used to be better than Chrome at handling large files, but Chrome seems to have improved recently. If the web app crashes, try the [`mapshaper-xl` command-line tool](/docs/essentials/command-line.html.md), which can allocate a large amount of memory.

docs/examples/basics.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ <h3 id="run-a-chain-of-commands-from-a-file">Run a chain of commands from a file
220220
<span class="hljs-comment"># or simply:</span>
221221
mapshaper build.txt
222222
</code></pre>
223-
<p>Long pipelines can be kept in a <a href="/docs/reference.html#command-files">command file</a>. This is a CLI workflow; support for running command files in the web app is planned for a future release.</p>
223+
<p>Long pipelines can be kept in a <a href="/docs/essentials/command-line.html#command-files">command file</a>. This is a CLI workflow; support for running command files in the web app is planned for a future release.</p>
224224
<h3 id="parameterize-a-command-file">Parameterize a command file</h3>
225225
<pre><code class="hljs language-bash">mapshaper -vars YEAR=2024 PCT=10 -run build.txt
226226
</code></pre>

docs/examples/basics.html.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ mapshaper -run build.txt
324324
mapshaper build.txt
325325
```
326326

327-
Long pipelines can be kept in a [command file](/docs/reference.html.md#command-files). This is a CLI workflow; support for running command files in the web app is planned for a future release.
327+
Long pipelines can be kept in a [command file](/docs/essentials/command-line.html.md#command-files). This is a CLI workflow; support for running command files in the web app is planned for a future release.
328328

329329
### Parameterize a command file
330330

docs/examples/data/globe.msx

0 Bytes
Binary file not shown.

docs/examples/data/ny-state.msx

0 Bytes
Binary file not shown.

docs/examples/data/us-states.msx

0 Bytes
Binary file not shown.

docs/guides/expressions.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ <h2 id="layer-level-expressions--if--define">Layer-level expressions (<code>-if<
525525
</code></pre>
526526
<p>Each entry in <code>targets</code> exposes useful summary stats from <code>-info</code>: <code>layer_name</code>, <code>feature_count</code>, <code>null_shape_count</code>, <code>null_data_count</code>, <code>bbox</code>, <code>proj4</code>. Reading <code>targets[0].geojson</code> returns the layer as a GeoJSON FeatureCollection; assigning to it replaces the layer with the FeatureCollection you provide.</p>
527527
<h2 id="template-expressions--run">Template expressions (<code>-run</code>)</h2>
528-
<p><code>-run</code> accepts either a path to a <a href="/docs/reference.html#command-files">command file</a> or a string containing one or more curly-brace template expressions. Each <code>{...}</code> is evaluated as a JS expression and substituted into the resulting command string before Mapshaper parses it.</p>
528+
<p><code>-run</code> accepts either a path to a <a href="/docs/essentials/command-line.html#command-files">command file</a> or a string containing one or more curly-brace template expressions. Each <code>{...}</code> is evaluated as a JS expression and substituted into the resulting command string before Mapshaper parses it.</p>
529529
<pre><code class="hljs language-bash"><span class="hljs-comment"># Project to a transverse Mercator centred on the layer</span>
530530
mapshaper -i country.shp -require projection.js \
531531
-run <span class="hljs-string">&#x27;-proj {tmerc(target.bbox)}&#x27;</span> -o

0 commit comments

Comments
 (0)