ianengelbrecht / geo-coordinates-parser

A Javascript function for reading a variety of coordinate formats and converting to decimal numbers. Builds on other efforts by returning the verbatim coordinates and the decimal coordinates all in one object.
MIT License
38 stars 9 forks source link

Problem with more decimal precision #18

Closed Haschikeks closed 6 months ago

Haschikeks commented 6 months ago

Hi,

I've noticed that in the following format 45°5'46.8"N, 18°30'36.7"E, adding more decimal numbers for the seconds leads to an error on converting. Here is an example code snippet. The gpsString2 is the first one, just with less precision on the seconds.

Example Codesandbox: Sandbox

const { convert } = require('geo-coordinates-parser'); //CommonJS
const gpsString1 = `45°5'46.8132"N, 18°30'36.7128"E`;
const gpsString2 = `45°5'46.8"N, 18°30'36.7"E`;
try {
    const c = convert(gpsString1);
    console.log("GPSString1:",c);
} catch (e) {
    console.error("Problem gpsString 1", e)
}
try {
    const c = convert(gpsString2);
    console.log("GPSString2:",c);
} catch (e) {
    console.error("Problem gpsString 2", e)
}

Is this intended behavior and my source for the gps information is doing something weird?

ianengelbrecht commented 6 months ago

Thanks for the message Max. The maximum number of decimal places is hardcoded to 3. I'm happy to increase it but can you tell me about the source of these coordinates first? Four decimal places on the seconds is basically measuring in millimeters, which is vastly more precise than geographic coordinates typically ever are or can be measured using handheld GPSs. Apparently professional land surveyor GPSs can be accurate to 10mm though. I am seeing some GPS devices that provide higher precision than 3 decimal places in their readings but they're basically meaningless decimal points if the GPS is only accurate to a few feet. Let me know your thoughts.

Haschikeks commented 6 months ago

Hi, then I got lucky and unlucky at the same time. "my Source" is just an excel sheet. I've seem to picked one of the few that had 4 decimals. I'm not sure who/how the coordinates a measured. The coordinates are used for the "exact" location of trees, in like every tree has it's own set of coordinates.

Could the change of increasing the max decimal places break any other format?

ianengelbrecht commented 6 months ago

Yes it turns out it breaks the parsing of other formats :-/ It seems yours is something of an edge case. Could I suggest editing the data in OpenRefine rather? If you add a text filter on your coords column with ./d{4,} and regular expressions turned on you should get them all and can do a replace to set to three decimal places.

On Wed, Apr 10, 2024 at 1:38 PM Max @.***> wrote:

Hi, then I got lucky and unlucky at the same time. "my Source" is just an excel sheet. I've seem to picked one of the few that had 4 decimals. I'm not sure who/how the coordinates a measured. The coordinates are used for the "exact" location of trees, in like every tree has it's own set of coordinates.

Could the change of increasing the max decimal places break any other format?

— Reply to this email directly, view it on GitHub https://github.com/ianengelbrecht/geo-coordinates-parser/issues/18#issuecomment-2047299657, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACH3QI7GCSUSISH6RYTS6D3Y4UQEHAVCNFSM6AAAAABGAHEDTCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBXGI4TSNRVG4 . You are receiving this because you commented.Message ID: @.***>

-- Ian Engelbrecht Digitization Coordinator Natural Science Collections Facility South Africa https://nscf.org.za/ https://nscf.org.za/ +27 82 763 4596 i @.>@. / @.***

Haschikeks commented 6 months ago

Okay, good to know.

I'll try some try workarounds and propagate the problem up the info chain. Would it make sense to add some sort of "Edge cases" or something similar to the docs?

ianengelbrecht commented 6 months ago

Okay I've made a note under formats, which will go out with the next publish. Thanks for the suggestion.

Haschikeks commented 6 months ago

Okay thank you. Could you point me to the part in the regex's where it would need to be increased, in case I would need to do a local patch?

ianengelbrecht commented 6 months ago

Sure, if you search for {1, 3} (without the tickmarks of course), and increase 3 to 4 or higher, you should be good. (Update all instances just in case). I hope it works!

On Thu, Apr 11, 2024 at 4:28 PM Max @.***> wrote:

Okay thank you. Could you point me to the part in the regex's where it would need to be increased, in case I would need to do a local patch?

— Reply to this email directly, view it on GitHub https://github.com/ianengelbrecht/geo-coordinates-parser/issues/18#issuecomment-2049825335, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACH3QI3QO4TZDTHFGY255XLY42M2FAVCNFSM6AAAAABGAHEDTCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBZHAZDKMZTGU . You are receiving this because you commented.Message ID: @.***>

-- Ian Engelbrecht Digitization Coordinator Natural Science Collections Facility South Africa https://nscf.org.za/ https://nscf.org.za/ +27 82 763 4596 i @.>@. / @.***