Skip to content

Commit

Permalink
parse code from Proj.4 string in any sort order
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Jun 30, 2023
1 parent a3dd476 commit 006c86f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/getCodeFromProjString.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
function getCodeFromProjString(proj) {
if (proj.startsWith("+proj=utm") && proj.includes("+zone=")) {
// replace any accidental double spaces
if (proj.includes("+proj=utm") && proj.includes("+zone=")) {
const parts = proj.split(" ");
const zone = parts.find(part => part.startsWith("+zone=")).split("=")[1];
const south = proj.includes("+south");
Expand Down
3 changes: 3 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ test("getCodeFromProjString", ({ eq }) => {
eq(getCodeFromProjString("+proj=utm +zone=17 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"), 32617);
eq(getCodeFromProjString("+proj=utm +zone=18 +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs"), 32718);
eq(getCodeFromProjString("+proj=utm +zone=18 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"), 32618);
eq(getCodeFromProjString("+proj=utm +zone=17 +datum=WGS84 +units=m +no_defs"), 32617);
eq(getCodeFromProjString("+proj=utm +zone=17 +datum=WGS84 +units=m"), 32617);
eq(getCodeFromProjString("+datum=WGS84 +proj=utm +units=m +zone=17"), 32617);
});

test("isUTM", ({ eq }) => {
Expand Down

0 comments on commit 006c86f

Please sign in to comment.