question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Broken Projections when using proj4js definitions

See original GitHub issue

OpenLayers produces broken projections when using ol 6.4.3 and proj4js 2.6.2 for (at least) geographic CRS. Adding a new definition in proj via defs with the official strings (from epsg.io or spatialreference.org) works nicely in proj4js. But using the register function of ol.proj.proj4 then creates an invalid projection. Invalid means that required parameters like units are undefined and axisOrientation is set to wrong default values.

Example:

proj4.defs('EPSG:4258', '+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs');
ol.proj.proj4.register(proj4);

image image

The map display / projection is broken when using this ol.Projection.

Expected behavior When having a proj4js definition which does not have a unit set, the default should be “degrees” instead of undefined. In fact, all EPSG definitions for proj4js are missing the unit for geographic projections and there are only “m”, “ft” and “us-ft”.

Besides, the axisOrientation needs to be configured correctly in order to render a map correctly. The broken definition from above needs to have a ‘neu’ order, but the definition has no axis given and openlayers defaults to ‘enu’. There are only 28 definitions for proj4js out of 3910 which have an axis given (“+axis=wsu”)

Am i doing something totally wrong or is this somehow unusable for geographic projections in the current state?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
weskammcommented, Oct 15, 2020

Very nice! I did not know that proj4js also handles “other” definition strings, this becomes very handy here. And yes i think you are right about assuming degrees for longlat definitions should be ok, i had a look at this collection:

https://github.com/yuletide/node-proj4js-defs/blob/master/epsg.js

and it appears that they all miss the units parameter.

So thanks for the solution and the PR!

0reactions
ahocevarcommented, Jun 16, 2021

@weskamm:

Well the problem is, that commonly used sources like epsg.io and spatialreference.org do not serve that information (no axis and no unit, e.g. http://epsg.io/4258 or http://epsg.io/4326).

Correct. You can use the official EPSG database API instead, e.g. https://apps.epsg.org/api/v1/CoordRefSystem/4258/export/?format=wkt&formatVersion=1. I just published new versions of wkt-parser and proj4js that support their WKT format.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error in proj4js-Projection while upgrading from OpenLayers 5 ...
I started with the OSM Example Map with EPSG:3587 and added my own WMS Server with EPSG:25832. Therefore I initially neeeded a reprojection....
Read more >
Using proj4js with d3 / Fil - Observable
First, d3 instantiates its projections with specific scale, center, rotate and translate, which don't take into account what's defined in the the proj4 ......
Read more >
Can't use specific projection with OpenLayers - Stack Overflow
The problem has been resolved. I was given with bad projection string (some parameters were missed). Instead of using.
Read more >
PROJ4JS | Proj4js
JavaScript library to transform coordinates from one coordinate system to another, including datum transformations.
Read more >
Understand EPSG, WKT and Other CRS Definition Styles
Using the PROJ.4 syntax, you specify the complete set of parameters including the ellipse, datum, projection units and projection definition ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found