A TypeScript wrapper for loading remote CRS WKT definitions and extends the original uriproj by adding support for URNs and shorthand prefixes, making it easier to work with different CRS formats.
- Supports specifying OGC URNs, URIs and :
shorthands - Uses OGC WKT2 definitions eliminating need for NADGRID TIFF files
- Caches definitions
npm install @murithigeo/uriproj
import { uriproj, load, fromAuthCode, toURI } from "@murithigeo/uriproj";
// Project coordinates from EPSG:4326 to OGC:CRS84
const converter = await uriproj({
from: "EPSG:4326",
to: "OGC:CRS84",
});
const projected = converter.forward({ x: -90, y: -180 });
console.log(projected); // { x: -180, y: -90 }
URIProj supports three CRS identifier formats:
- Authority:Code (shorthand):
EPSG:4326, OGC:CRS84
- URI:
http://www.opengis.net/def/crs/EPSG/0/4326
- URN:
urn:ogc:def:crs:EPSG:0:4326
The fromURI, fromURN and fromAuthCode functions allow conversions to other formats
The toURI allows conversions from an unknown string to an absolute URI
Loads a CRS definition from spatialreference.org and caches it locally. Automatically registers the definition with proj4. Accepts any supported CRS format.
import { load } from "@murithigeo/uriproj";
let wkt = await load("EPSG:4326");
wkt = await load("urn:ogc:def:crs:OGC:1.3:CRS84");
wkt = await load("http://www.opengis.net/def/crs/EPSG/0/4326");
console.log(wkt);
Retrieve a cached CRS definition.
import { get } from "@murithigeo/uriproj";
const cached = get("http://www.opengis.net/def/crs/EPSG/0/4326");
if (cached) {
console.log("CRS definition is cached:", cached);
}
const converter = await uriproj({
from: "OGC:CRS84", // If undefined, defaults to EPSG:4326
to: "EPSG:32737",
});
Both proj4 and the Converter type are re-exported for convenience:
import { proj4, type Converter } from "@murithigeo/uriproj";
// Use proj4 directly if needed
proj4.defs("EPSG:4326");