Skip to content

Add new function proj4ToProj4 to turf/projection#3046

Open
BenPortner wants to merge 2 commits intoTurfjs:masterfrom
BenPortner:proj4
Open

Add new function proj4ToProj4 to turf/projection#3046
BenPortner wants to merge 2 commits intoTurfjs:masterfrom
BenPortner:proj4

Conversation

@BenPortner
Copy link
Copy Markdown

This PR adds a new function proj4ToProj4 to the turf-projection package. The function allows conversions from an arbitrary input projection to an arbitrary output projection, as long as it is implemented in Proj4js. Before, only conversions from WGS84 to Mercator and vice-versa were possible.

Example use:

  import { proj4ToProj4 } from "@turf/projection";

  const coord = [10, 40];
  const millerProj4 = "+proj=mill +R_A +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs";
  const millerCoord = proj4ToProj4(coord, "WGS84", millerProj4);

This is not a breaking change. Both of the original toMercator and toWgs84 functions are left untouched (however, it might be worthwhile removing them, as they are easily replaced by proj4ToProj4). Proj4js has been added as a project dependency (it had already been a dev dependency before).

I've read the steps for preparing a pull request. I've added appropriate tests for the new function (currently testing only WGS84->Mercator and Mercator->WGS84, based on the already existing test files). All tests are ok. The docs have not yet been updated to include the new function because I first want to see if this sparks your interest at all.

@smallsaucepan
Copy link
Copy Markdown
Member

Thanks for putting this together @BenPortner. Overall would be supportive of this. Though the spec says geojson is WSG84 by default, seems reasonable if we offer projection services to one alternative (mercator) we should offer it to others.

Couple of questions ...

  1. Does proj4 offer type safety for the projection names? Or can we only be as specific as "string"?
  2. Can you please evaluate how adding proj4 as a runtime dependency changes bundle sizes? The size of packages/turf/turf.min.js would be a good first check
  3. I'm not 100% sure proj4 will be compatible with ESM projects? https://arethetypeswrong.github.io/?p=proj4%402.20.8 Do you have any practical insights there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants