@allmaps/project

中文文档
1.0.0-beta.10发布于 2026/09/22MITES Module近 30 天下载 8627

Projection functions

原始使用文档
文档目录51 节
  1. How it works
  2. Installation
  3. Usage
  4. Quickstart
  5. Using a transformer with the default WebMercator EPSG:3857 …
  6. Using a transformer with a specific internal projection
  7. Using a transformer with a specific internal projection and…
  8. Transforming to a different projection
  9. Creating and using a projected transformer
  10. Projected GCP Transformer options
  11. Projected GCP Transform options
  12. Typing
  13. Benchmark
  14. License
  15. API
  16. InternalProjectionInputs
  17. ProjectedGcpTransformOptions
  18. new ProjectedGcpTransformer(gcps, type, partialProjectedGcp…
  19. ProjectedGcpTransformer#gcps
  20. ProjectedGcpTransformer#getToGeoTransformationResolution(re…
  21. ProjectedGcpTransformer#getToProjectedGeoTransformationReso…
  22. ProjectedGcpTransformer#getToResourceTransformationResoluti…
  23. ProjectedGcpTransformer#interalProjectedGcps
  24. ProjectedGcpTransformer#internalProjection
  25. ProjectedGcpTransformer#internalProjectionToProjection
  26. ProjectedGcpTransformer#isNonWarping()
  27. ProjectedGcpTransformer#lonLatToProjection
  28. ProjectedGcpTransformer#lonlatGcps
  29. ProjectedGcpTransformer#projectedGcps
  30. ProjectedGcpTransformer#projection
  31. ProjectedGcpTransformer#projectionToInternalProjection
  32. ProjectedGcpTransformer#projectionToLonLat
  33. ProjectedGcpTransformer#transformToGeo(resourcePoint, parti…
  34. ProjectedGcpTransformer#transformToProjectedGeo(resourcePoi…
  35. ProjectedGcpTransformer#transformToResource(projectedGeoPoi…
  36. ProjectedGcpTransformer.fromGeoreferencedMap(georeferencedM…
  37. ProjectedGcpTransformer.fromProjection(projectedTransformer…
  38. ProjectedGcpTransformerInputs
  39. ProjectedGcpTransformerOptions
  40. Projection
  41. ProjectionDefinition
  42. ProjectionInputs
  43. defaultProjectedGcpTransformOptions
  44. defaultProjectedGcpTransformerOptions
  45. getLonLatDefinition(partialProjectionDefinitionOptions)
  46. getWebMercatorDefinition(partialProjectionDefinitionOptions)
  47. isEqualProjection(projection0, projection1)
  48. lonLatProjection
  49. projectionDefinitionToAntialiasedDefinition(stringProjectio…
  50. projectionToAntialiasedProjection(projection, partialProjec…
  51. webMercatorProjection

@allmaps/project

This module extends the GCP Transformer class from @allmaps/transform with projection functions: the Projected GCP Transformer class and its methods can transform and project Points, LineStrings, Polygons and other spatial features from image 'resource' space to a 'projected geo' space.

Projections are handled by the Proj4js library. This package this supports any projection (or more generally, coordinate reference system or CRS) supported by Proj4js.

Within the Allmaps project, this module is used a.o. in @allmaps/render and @allmaps/tileserver, two places where we transform a IIIF image from the 'resource' space of the image to the 'projected geospatial' space of a map projection (in most cases WebMercator), using the Ground Control Points and transformation type defined in the map's Georeference Annotation.

How it works

This package exports the ProjectedGcpTransformer class, which extends the GcpTransformer class from @allmaps/transform.

Like instances of the GcpTransformer class, instances of the ProjectedGcpTransformer class are constructed from a set of Control Points, who's coordinates are known in both spaces (and who's geo coordinates are given in lon-lat EPSG:4326 projection), and a specific type of transformation algorithm. Additionally, an internal projection and projection can be defined, in order to transform not from 'resource' to 'geo' space, but from 'resource' to 'projected geo' space of the viewport, optionally passing through an 'internal projected geo' space of the map. This is achieved using the toProjectedGeo() and toResource() methods (or toGeo() to obtain points in EPSG:4326 projection).

The projection defines the 'projected geo' space of the viewport. Since we will render our geometries in the projected space of our viewport, it is logical to make the transformer aware of this space by supplying its projection, so it can bring the results to this space. It defaults to WebMercator EPSG:3857, the projection used by default in most webmaps.

The internal projection defines the 'internal projected geo' space. This is the space of the known or supposed projection in which the map was made. When we know this projection, it is important, e.g. when transforming toGeo, to build a toGeoTransfromation between the 'resource' space of the image and the 'internal projected geo' space of this known or supposed projection. This way we make the transformation account only for the warping of the image onto its intended projection space, and not for any other warping due to the choice of viewport projection (which could be different than the map projection). To bring the results from the 'internal projected geo' space of the map to the 'projected geo' space of the viewport, a projection function from 'internal projected geo' to 'projected geo' space is set as the postToGeo option (that is part of the GCP Transform options), and executed at the end of the transformer's toProjectedGeo() method. Similarly when calling the toResource() method a preToResource() is executed to go from 'projected geo' space to 'internal projected geo' space, before evaluating the toResourceTransformation and arriving in 'resource' space. The 'internal projected geo' space also defaults to WebMercator EPSG:3857 (due to its 'conformal' properties that make it a good general guess for a map's projection at large scales). When the internal projection and projection are identical (as is the default) the postToGeo() function is an identity projection with no effect.

The GCPs must be provided in lon-lat EPSG:4326 projection (since this is the default projection used by GeoJSON and Georeference Annotations) and are projected to the 'projected geo' space before building the GCP Transformer (who will project them to the 'internal projected geo' space).

Installation

This is an ESM-only module that works in browsers and in Node.js.

Install with pnpm:

pnpm install @allmaps/project

Usage

Quickstart

Similar to GCP Transformers, when starting from an Annotation or Georeferenced Map, the fastest way to build a Projected GCP Transformer is:

import { parseAnnotation } from '@allmaps/annotation'
import { ProjectedGcpTransformer } from '@allmaps/project'

// Fetch an annotation
const annotation = await fetch(annoationUrl).then((response) => response.json())

// Create a georeferencedMap from the annotation
const georeferencedMaps = parseAnnotation(annotation)
const georeferencedMap = georeferencedMaps[0]

// Build Projected GCP Transformer
const projectedTransformer =
  ProjectedGcpTransformer.fromGeoreferencedMap(georeferencedMap)

// Use it to transform geometries, as below. E.g.:
const projectedGeoPoint = projectedTransformer.transformToProjectedGeo(resourcePoint)

This is equivalent to constructing a projected transformer from the Annotation's or Georeferenced Map's GCPs, transformation type and projection, as in the examples below.

This projected transformer can then be used to transform geometries between 'resource' space and 'projected geo' space.

When rendering maps, another way to quickly obtain a projected transformer is to access it directly from a Warped Map in the renderer's Warped Map List:

// Create a renderer from your canvas
const renderer = new WebGL2Renderer(gl)
// Fetch and parse annotations, add them to the renderer ...

// There are multiple ways to access the renderer's Warped Map List's Warped Maps, e.g.:
const warpedMap = renderer.warpedMapList.getWarpedMap(mapId)

// Access the Projected GCP Transformer, in the Warped Map's current transformation type
const projectedTransformer = warpedMap.projectedTransformer
// Or select or create the Projected GCP Transformer of a different transformation type
const projectedHelmertTransformer = warpedMap.getProjectedTransformer('helmert')

Using a transformer with the default WebMercator EPSG:3857 projections

In this example we create a projected transformer with a Thin Plate Spline transformation and the default internal projection and projection: WebMercator EPSG:3857.

This projected transformer thus gives WebMercator EPSG:3857 coordinates when transforming forward.

import { ProjectedGcpTransformer } from '@allmaps/project'

const gcps6 = [
  {
    resource: [1344, 4098],
    geo: [4.4091165, 51.9017125]
  },
  {
    resource: [4440, 3441],
    geo: [4.5029222, 51.9164451]
  },
  {
    resource: [3549, 4403],
    geo: [4.4764224, 51.897309]
  },
  {
    resource: [1794, 2130],
    geo: [4.4199066, 51.9391509]
  },
  {
    resource: [3656, 2558],
    geo: [4.4775683, 51.9324358]
  },
  {
    resource: [2656, 3558],
    geo: [4.4572643, 51.9143043]
  }
]

const options = {
  minOffsetRatio: 0.001,
  maxDepth: 1
}

const projectedTransformer = new ProjectedGcpTransformer(
  gcps6,
  'thinPlateSpline',
  options
)

const resourceLineString = [
  [3655, 2212],
  [2325, 3134],
  [3972, 325],
  [3451, 2876],
  [2067, 920],
  [622, 941]
]

const projectedGeoLineString =
  projectedTransformer.transformToProjectedGeo(resourceLineString)
// projectedGeoLineString = [
//   [498246.8195647142, 6789061.316027705],
//   [496595.9732655353, 6787546.801212325],
//   [494783.7898554361, 6785995.114473057],
//   [496391.8586632488, 6790623.562354985],
//   [498497.64212101337, 6795403.988950945],
//   [498135.8154413349, 6791100.393518668],
//   [498076.9264938777, 6786883.571136022],
//   [495239.5461210053, 6790036.9871731205],
//   [492300.2095900435, 6793167.011607833],
//   [489770.9992948517, 6793018.672759057],
//   [487201.94796965295, 6792860.379165613]
// ]

Notice how this returns a lineString in WebMercator coordinates.

Using a transformer with a specific internal projection

In this example we create a projected transformer with a Thin Plate Spline transformation, the internal projection set to 'BD72 / Belgian Lambert 72' EPSG:31370 and the projection set to the WebMercator EPSG:3857.

import { ProjectedGcpTransformer } from '@allmaps/project'

const gcps6 = ... // See above

const epsg31370 =
  '+proj=lcc +lat_0=90 +lon_0=4.36748666666667 +lat_1=51.1666672333333 +lat_2=49.8333339 +x_0=150000.013 +y_0=5400088.438 +ellps=intl +towgs84=-106.8686,52.2978,-103.7239,0.3366,-0.457,1.8422,-1.2747 +units=m +no_defs +type=crs'

const options = {
  minOffsetRatio: 0.001,
  maxDepth: 1,
  internalProjection: epsg31370
}

const projectedTransformer = new ProjectedGcpTransformer(gcps6, 'thinPlateSpline', options)

const resourceLineString = [
  [3655, 2212],
  [2325, 3134],
  [3972, 325],
  [3451, 2876],
  [2067, 920],
  [622, 941]
]

const projectedGeoLineString = projectedTransformer.transformToProjectedGeo(resourceLineString)
// const projectedGeoLineString = [
//   [498247.196090505, 6789061.7676701555],
//   [496596.0857961293, 6787546.818863111],
//   [494783.8626652385, 6785995.157771795],
//   [496392.4627162781, 6790624.950878147],
//   [498501.57678734255, 6795410.032138047],
//   [498137.15972611686, 6791102.130838948],
//   [498076.85849569837, 6786883.389086489],
//   [495239.9136289843, 6790037.973029668],
//   [492298.9972965987, 6793169.702451241],
//   [489767.88734149706, 6793019.906716891],
//   [487196.5540720398, 6792859.377809678]
// ]

Notice how this return a lineString in WebMercator coordinates with different points than previously, since its transformation used another internal projection before projecting the result to WebMercator.

Using a transformer with a specific internal projection and projection

Likewise, it's possible to specify both the internal projection and projection.

In this example we create a projected transformer with a Thin Plate Spline transformation from the 'resource' space to the 'internal projected' space in the EPSG:31370 projection, and bring the results to the (default) 'projected geo' space in the 'Amersfoort / RD' New EPSG:28992 projection.

import { ProjectedGcpTransformer } from '@allmaps/project'

const gcps6 = ... // See above

const epsg31370 = ... // See above
const epsg28992 = "+proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +towgs84=565.4171,50.3319,465.5524,1.9342,-1.6677,9.1019,4.0725 +units=m +no_defs +type=crs"

const options = {
  minOffsetRatio: 0.001,
  maxDepth: 1,
  internalProjection: epsg31370,
  projection: epsg28992
}

const projectedTransformer = new ProjectedGcpTransformer(gcps6, 'thinPlateSpline', options)

const resourceLineString = [
  [3655, 2212],
  [2325, 3134],
  [3972, 325],
  [3451, 2876],
  [2067, 920],
  [622, 941]
]

const projectedGeoLineString = projectedTransformer.transformToProjectedGeo(resourceLineString)
// const projectedGeoLineString = [
//   [92171.96319801327, 439250.7392195241],
//   [91140.1318550074, 438330.2059945731],
//   [90008.06902330121, 437388.3781427277],
//   [91038.64166624477, 440228.31014306704],
//   [92378.19922071013, 443158.54244443506],
//   [92119.83597131, 440508.5490631829],
//   [92049.81893950628, 437909.7404415105],
//   [90322.16486404435, 439875.89373726887],
//   [88531.49536626287, 441828.6782593381],
//   [86967.57638718556, 441757.502798549],
//   [85378.67808803722, 441680.55210508476]
// ]

Notice how this returns a lineString in WebMercator coordinates with the same points as previously but projected to EPSG:28992

Transforming to a different projection

Since projection is a transform option, it can be set on every transform method call. This allows us to change the requested projection from the one specified during a projected transformer creation to any projection. Thus, we don't need to create a projected transformer for every projection of interest: we can reuse a transformer and its toGeo and/or toResource transformations (who's computation can be expensive when there are many GCPs).

We can request the result of a 'toGeo' transform using the projected transformer above as follows:

// Same projectedTransformer as above:
// internalProjection: epsg31370,
// projection: epsg28992

const projectedGeoLineString = projectedTransformer.transformToProjectedGeo(
  resourceLineString,
  { projection: { definition: 'EPSG:3857' } }
)
// const projectedGeoLineString = [
//   [ 498247.1996476347, 6789061.760253225 ],
//   [ 496596.08934986574, 6787546.81144527 ],
//   [ 494783.8662153203, 6785995.150353045 ],
//   [ 496392.4662716557, 6790624.943463034 ],
//   [ 498501.58034885704, 6795410.0247265855 ],
//   [ 498137.16328437213, 6791102.123423815 ],
//   [ 498076.8620512022, 6786883.381667706 ],
//   [ 495239.91718228994, 6790037.965614326 ],
//   [ 492299.00084753655, 6793169.695039346 ],
//   [ 489767.8908886019, 6793019.899305481 ],
//   [ 487196.5576152448, 6792859.370398756 ]
// ]

Notice how this returns a result very close to the earlier result for projectedTransformer with internalProjection EPSG:31370 and default projection WebMercator EPSG:3857.

To change a projected transformer's projection in the transformer options (such that it will always be used by default), use the setProjection() method.

Passing a projection in a transform call, as above, has been implemented as passing a postToGeo function that projects from the transformer's internal projection to the requested projection.

Note: there is no equivalent option for the internal projection.

Creating and using a projected transformer

Since the Projected GCP Transformer class extends the GCP Transformer class, a lot of its usage is similar. (See the @allmaps/transform package for more information on the items below).

When creating an instance from the Projected GCP Transformer class:

  • The GCPs are specified using the Gcp type and with geo component in lon-lat 'EPSG:4326'.
  • The same transformation types are supported: polynomial, thinPlateSpline, ...
  • Two extra options can be set: projection specifies the projected geo space (defaults to WebMercator EPSG:3857), and intenalProjection specifies the projected using when computing the transformation (also defaults to WebMercator EPSG:3857). As with a GCP Transformer, the differentHandedness is true by default.

When using its main methods:

  • The method transformToProjectedGeo() transforms input geometries from 'resource' space to 'projected geo' space, as the method transformToResource() transforms input geometries from 'projected geo' space to 'resource' space.
  • An additional method transformToGeo() transforms input geometries from 'resource' space to 'geo' in lon-lat 'EPSG:4326'.
  • Inputs are following the Allmaps Geometries types. To handle GeoJSON Geometries or SVG Geometries, convert to and from these geometry types using the functions available in @allmaps/stdlib.
  • GCP Transform options can be specified and manage a.o. how geometries are refined and which distortions are computed. The projection functions are now considered when refining geometries and recursively adding midpoints.
  • A 'return type function' can be used to extract distortion information or modify the results.

For faster transformation between SVG Geometries and GeoJSON Geometries, the same shortcut static methods are available for GcpTransformers: transformSvgToGeojson(), transformSvgStringToGeojsonFeatureCollection(), transformGeojsonToSvg(), transformGeojsonFeatureCollectionToSvgString().

Note: Distortions only describe the warping of the transformation, from 'resource' space to 'internal projected geo' space. (Describing the warping up until 'projected geo' space would require applying the chain rule and having access to the partial derivatives of the projection functions.)

Projected GCP Transformer options

An extra 'transformer option' is available for Projected GCP Transformers:

OptionDescriptionTypeDefault
internalProjectionThe geographic projection used internally in the transformation.ProjectionWebMercator EPSG:3857

Since the internal projection defines the internal projected space to and from which the transformations have been computed, transform calls can't specify a different internal projection.

Projected GCP Transform options

An extra 'transform option' is available for Projected GCP Transformers:

OptionDescriptionTypeDefault
projectionThe geographic projection rendered in the viewport.ProjectionWebMercator EPSG:3857

As with a GCP Transformer, passing this transform option during the transformer's construction here it the default when using the transform methods.

Like other GCP Transform options, this option can be set when constructing a transformer and when transform geometries. This can be useful, since it allows us to reusing the toGeo and/or toResource transformations of a transformer (which can be expensive to compute for when there are many GCPs) to transform to a new projection. (See example above.)

Typing

Projections are defined as follows:

export type Projection = {
  name?: string
  definition: string | proj4.PROJJSONDefinition
}

Projection definitions can be anything compatible with Proj4js, e.g. one of the two default named projections 'EPSG:3857' 'EPSG:4326', a proj4-string '+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs', a WKT-string or (since Proj4js version 2.19) a PROJJSON definition.

Benchmark

Here are some benchmarks on building and using a transformer, as computed on a 2023 MacBook Air M2 with 16 GB RAM.

This benchmark can be run with pnpm run bench. For more information, see ./bench/index.js.

To create a projected transformer (with 10 points) and compute its 'toGeo' transformation:

TypeOps/s
helmert31178
polynomial139583
polynomial231907
polynomial320137
thinPlateSpline17325
projective20322

To use a projected transformer (with 10 points, and its 'toGeo' transformation already computed) and transform a point 'toGeo':

TypeOps/s
helmert3906562
polynomial13595760
polynomial23568346
polynomial32087742
thinPlateSpline1759935
projective3621210

License

MIT

API

InternalProjectionInputs

Fields
  • internalProjection? ({id?: string; name?: string; definition: ProjectionDefinition})

ProjectedGcpTransformOptions

Type
ProjectionInputs & {
  maxDepth: number
  minSourceDistance: number
  minDestinationDistance: number
  minOffsetRatio: number
  minOffsetDistance: number
  distortionMeasures: DistortionMeasure[]
  referenceScale: number
  postToGeo: ProjectionFunction
  preToResource: ProjectionFunction
} & MultiGeometryOptions

new ProjectedGcpTransformer(gcps, type, partialProjectedGcpTransformerOptions)

Create a ProjectedGcpTransformer

Parameters
  • gcps (Array<Gcp>)
    • An array of Ground Control Points (GCPs) in lon-lat 'EPSG:4326'
  • type (TransformationType | undefined)
    • The transformation type
  • partialProjectedGcpTransformerOptions? (Partial<ProjectedGcpTransformerOptions> | undefined)
    • Projected GCP Transformer options
Returns

ProjectedGcpTransformer.

Extends
  • GcpTransformer

ProjectedGcpTransformer#gcps

Get GCPs as they were inputed to the GCP Transformer (Array<Gcp>).

For a Projected GCP Transformer, these are the GCPs in projected coordinates.

ProjectedGcpTransformer#getToGeoTransformationResolution(resourceBbox, partialProjectedGcpTransformOptions)

Get the resolution of the toGeo transformation in resource space, within a given bbox.

This informs you in how fine the warping is, in resource space. It can be useful e.g. to create a triangulation in resource space that is fine enough for this warping or set the minSourceDistance options.

It is obtained by transforming toGeo two linestring, namely the horizontal and vertical midlines of the given bbox. The toGeo transformation will refine these lines: it will break them in small enough pieces to obtain a near continuous result.

Resolution returned in the length of the shortest piece, measured in resource coordinates, or undefined if no refinements were needed.

Parameters
  • resourceBbox? (Bbox | undefined)
    • BBox in resource space where the resolution is requested, or undefined to get this from the GCPs
  • partialProjectedGcpTransformOptions? (Partial<ProjectedGcpTransformOptions> | undefined)
Returns

Resolution of the toGeo transformation in resource space (number | undefined).

ProjectedGcpTransformer#getToProjectedGeoTransformationResolution(resourceBbox, partialProjectedGcpTransformOptions)

Get the resolution of the toProjectedGeo transformation in resource space, within a given bbox.

This informs you in how fine the warping is, in resource space. It can be useful e.g. to create a triangulation in resource space that is fine enough for this warping or set the minSourceDistance options.

It is obtained by transforming toProjectedGeo two linestring, namely the horizontal and vertical midlines of the given bbox. The toProjectedGeo transformation will refine these lines: it will break them in small enough pieces to obtain a near continuous result.

Resolution returned in the length of the shortest piece, measured in resource coordinates, or undefined if no refinements were needed.

Parameters
  • resourceBbox? (Bbox | undefined)
    • BBox in resource space where the resolution is requested, or undefined to get this from the GCPs
  • partialProjectedGcpTransformOptions? (Partial<ProjectedGcpTransformOptions> | undefined)
Returns

Resolution of the toProjectedGeo transformation in resource space (number | undefined).

ProjectedGcpTransformer#getToResourceTransformationResolution(projectedGeoBbox, partialProjectedGcpTransformOptions)

Get the resolution of the toResource transformation in projected geo space, within a given bbox.

This informs you in how fine the warping is, in projected geo space. It can be useful e.g. to create a triangulation in projected geo space that is fine enough for this warping or set the minDestionationDistance options.

It is obtained by transforming toResource two linestring, namely the horizontal and vertical midlines of the given bbox. The toResource transformation will refine these lines: it will break them in small enough pieces to obtain a near continuous result.

Resolution returned in the length of the shortest piece, measured in internal projected geo coordinates, or undefined if no refinements were needed.

Parameters
  • projectedGeoBbox? (Bbox | undefined)
    • BBox in projected geo space where the resolution is requested, or undefined to get this from the GCPs
  • partialProjectedGcpTransformOptions? (Partial<ProjectedGcpTransformOptions> | undefined)
Returns

Resolution of the toResource transformation in internal projected geo space (number | undefined).

ProjectedGcpTransformer#interalProjectedGcps

Get GCPs in interal projected coordinates (Array<Gcp>).

ProjectedGcpTransformer#internalProjection

Type
{id?: string; name?: string; definition: ProjectionDefinition}

ProjectedGcpTransformer#internalProjectionToProjection

Type
(point: Point) => Point

ProjectedGcpTransformer#isNonWarping()

Parameters

There are no parameters.

Returns

boolean.

ProjectedGcpTransformer#lonLatToProjection

Type
(point: Point) => Point

ProjectedGcpTransformer#lonlatGcps

Get GCPs in interal projected coordinates (Array<Gcp>).

ProjectedGcpTransformer#projectedGcps

Get GCPs in projected coordinates (Array<Gcp>).

ProjectedGcpTransformer#projection

Type
{id?: string; name?: string; definition: ProjectionDefinition}

ProjectedGcpTransformer#projectionToInternalProjection

Type
(point: Point) => Point

ProjectedGcpTransformer#projectionToLonLat

Type
(point: Point) => Point

ProjectedGcpTransformer#transformToGeo(resourcePoint, partialGcpTransformOptions, gcpToP)

Parameters
  • resourcePoint ([number, number])
  • partialGcpTransformOptions? (Partial<ProjectedGcpTransformOptions> | undefined)
  • gcpToP? (((gcp: GcpAndDistortions) => P) | undefined)
Returns

P.

ProjectedGcpTransformer#transformToProjectedGeo(resourcePoint, partialGcpTransformOptions, gcpToP)

Parameters
  • resourcePoint ([number, number])
  • partialGcpTransformOptions? (Partial<ProjectedGcpTransformOptions> | undefined)
  • gcpToP? (((gcp: GcpAndDistortions) => P) | undefined)
Returns

P.

ProjectedGcpTransformer#transformToResource(projectedGeoPoint, partialGcpTransformOptions, gcpToP)

Parameters
  • projectedGeoPoint ([number, number])
  • partialGcpTransformOptions? (Partial<ProjectedGcpTransformOptions> | undefined)
  • gcpToP? (((gcp: GcpAndDistortions) => P) | undefined)
Returns

P.

ProjectedGcpTransformer.fromGeoreferencedMap(georeferencedMap, options)

Create a Projected GCP Transformer from a Georeferenced Map

Parameters
  • georeferencedMap ({ '@context'?: "https://schemas.allmaps.org/map/2/context.json" | undefined; type: "GeoreferencedMap"; id?: string | undefined; created?: string | undefined; modified?: string | undefined; ... 5 more ...; _allmaps?: unknown; })
    • A Georeferenced Map
  • options? (Partial<{ internalProjection: Projection; projection: Projection; } & { differentHandedness: boolean; } & { maxDepth: number; minSourceDistance: number; minDestinationDistance: number; ... 5 more ...; preToResource: ProjectionFunction; } & MultiGeometryOptions & TransformationTypeInputs> | undefined)
    • Options, including Projected GCP Transformer Options, and a transformation type to overrule the type defined in the Georeferenced Map
Returns

A Projected GCP Transformer (ProjectedGcpTransformer).

ProjectedGcpTransformer.fromProjection(projectedTransformer, projection)

Set the projection.

To transform 'toGeo' or 'toResource' to or from a different projection than set on a transformer's construction (but using the same internal projection) it's possible to specify the requested projection in the transform options.

This way we circumvent a possibly expensive recomputation of the toGeo and/or toResource transformations.

To do this more systematically, it's possible to set a projected gcp transformer's projection using this method.

Parameters
  • projectedTransformer (ProjectedGcpTransformer)
  • projection ({id?: string; name?: string; definition: ProjectionDefinition})
Returns

this (ProjectedGcpTransformer).

ProjectedGcpTransformerInputs

Type
GcpsInputs &
  TransformationTypeInputs &
  InternalProjectionInputs &
  ProjectionInputs

ProjectedGcpTransformerOptions

Type
{ internalProjection: Projection; projection: Projection; } & { differentHandedness: boolean; } & { maxDepth: number; minSourceDistance: number; minDestinationDistance: number; ... 5 more ...; preToResource: ProjectionFunction; } & MultiGeometryOptions

Projection

Fields
  • definition (Definition)
  • id? (string)
  • name? (string)

ProjectionDefinition

Type
string | PROJJSONDefinition

ProjectionInputs

Fields
  • projection? ({id?: string; name?: string; definition: ProjectionDefinition})

defaultProjectedGcpTransformOptions

Fields
  • projection ({id?: string; name?: string; definition: string})

defaultProjectedGcpTransformerOptions

Fields
  • internalProjection ({id?: string; name?: string; definition: string})
  • projection ({id?: string; name?: string; definition: string})

getLonLatDefinition(partialProjectionDefinitionOptions)

Parameters
  • partialProjectionDefinitionOptions? (Partial<ProjectionDefinitionOptions> | undefined)
Returns

string.

getWebMercatorDefinition(partialProjectionDefinitionOptions)

Parameters
  • partialProjectionDefinitionOptions? (Partial<ProjectionDefinitionOptions> | undefined)
Returns

string.

isEqualProjection(projection0, projection1)

Parameters
  • projection0 ({id?: string; name?: string; definition: ProjectionDefinition})
  • projection1 ({id?: string; name?: string; definition: ProjectionDefinition})
Returns

boolean.

lonLatProjection

lonLatProjection

EPSG:4326 projection with definition: "+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees +over"

Note that +over was added to support wrapping around the antimeridian

Fields
  • definition (string)
  • id (string)
  • name (string)

projectionDefinitionToAntialiasedDefinition(stringProjectionDefinition, partialProjectionDefinitionOptions)

Parameters
  • stringProjectionDefinition (string)
  • partialProjectionDefinitionOptions? (Partial<ProjectionDefinitionOptions> | undefined)
Returns

string.

projectionToAntialiasedProjection(projection, partialProjectionDefinitionOptions)

Parameters
  • projection ({id?: string; name?: string; definition: ProjectionDefinition})
  • partialProjectionDefinitionOptions? (Partial<ProjectionDefinitionOptions> | undefined)
Returns

{id?: string; name?: string; definition: ProjectionDefinition}.

webMercatorProjection

webMercatorProjection

EPSG:3857 projection with definition: "+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs +over"

Note that +over was added to support wrapping around the antimeridian

Fields
  • definition (string)
  • id (string)
  • name (string)

版本与发布记录

@allmaps/project 共发布 10 个版本,首次发布于 2025/05/22;过去 12 个月发布了 5 个版本。

版本发布日期距今
1.0.0-beta.10latest2026/09/221 个月前
1.0.0-beta.92026/05/295 个月前
1.0.0-beta.82026/02/108 个月前
1.0.0-beta.72025/11/2711 个月前
1.0.0-beta.62025/11/1111 个月前
1.0.0-beta.52025/07/201.3 年前

其他发布通道:beta → 1.0.0-beta.2。

关于 @allmaps/project 的常见问题

@allmaps/project 是什么?

Projection functions

如何安装 @allmaps/project?

在项目目录运行 npm install @allmaps/project,或使用 pnpm add / yarn add / bun add。

@allmaps/project 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/allmaps__project 是否存在。

@allmaps/project 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@allmaps/project 可以商用吗?

@allmaps/project 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@allmaps/project 的下载量有多少?

根据 npm 官方下载统计,@allmaps/project 在 2026/10/06 – 2026/11/04 这 30 天内被下载 8,627 次,日均约 288 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@allmaps/project 还在维护吗?

最新版本 1.0.0-beta.10 发布于 2026/09/22(1 个月前);至今共发布 10 个版本,其中过去 12 个月发布了 5 个;首次发布于 2025/05/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。