From 006c86ff14221c4f97baf1960883105381f4337b Mon Sep 17 00:00:00 2001 From: DanielJDufour Date: Fri, 30 Jun 2023 12:53:44 +0200 Subject: [PATCH] parse code from Proj.4 string in any sort order --- src/getCodeFromProjString.js | 3 +-- test.js | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/getCodeFromProjString.js b/src/getCodeFromProjString.js index b56e546..305b805 100644 --- a/src/getCodeFromProjString.js +++ b/src/getCodeFromProjString.js @@ -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"); diff --git a/test.js b/test.js index 0915976..7932a62 100644 --- a/test.js +++ b/test.js @@ -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 }) => {