Function: fetchProjection()
function fetchProjection(epsg, options?): Promise<string>;Defined in: epsg.ts:122
Fetches a coordinate system definition from epsg.io.
Uses the native fetch, so it works unchanged in the browser, in Node 18+, and in workers.
Parameters
| Parameter | Type | Description |
|---|---|---|
epsg | number | The EPSG code, e.g. 26915. Must be a positive integer. |
options | FetchProjectionOptions | Format, timeout, and overrides. |
Returns
Promise<string>
The definition as text, trimmed.
Throws
If the code does not exist (epsg.io answers with a 404), the service is unreachable, the request times out or is aborted, or the response is not WKT. Every message names which of those it was.
Examples
Fetch a projection and use it directly
const wkt = await fetchProjection(2027);
await writeShapefileZip(data, { fileName: 'parcels', wkt });Fetch once, then register it so later calls are offline
import { fetchProjection, registerProjections } from '@crmackey/shapefile-wasm';
registerProjections({ 2027: await fetchProjection(2027) });
await writeShapefileZip(data, { epsg: 2027 });Ask for a different flavour
const wkt2 = await fetchProjection(4326, { format: 'wkt2' });Remarks
Only 'esri-wkt' belongs in a .prj. WKT 2 is the better standard, but a .prj containing it will confuse a lot of GIS software — so do not register a WKT 2 string for use as a projection file.
In a browser this is a cross-origin request. epsg.io does send permissive CORS headers, but if your page's Content Security Policy restricts connect-src, add https://epsg.io to it.