8000 Failed to create Point instance from string: unknown format. · Issue #432 · geopy/geopy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Failed to create Point instance from string: unknown format. #432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nseidl opened this issue Jul 16, 2020 · 1 comment · Fixed by #448
Closed

Failed to create Point instance from string: unknown format. #432

nseidl opened this issue Jul 16, 2020 · 1 comment · Fixed by #448

Comments

@nseidl
Copy link
nseidl commented Jul 16, 2020

This example works:

geopy.point.Point('+037.33270,-122.00530')

This example does not work:

geopy.point.Point('+041.69438,+001.51461')

ValueError: Failed to create Point instance from string: unknown format.

The string in example that is not working is indeed valid GPS, so I believe that this is a bug.

@KostyaEsmukov
Copy link
Member

The following patch seems to fix the issue:

diff --git a/geopy/point.py b/geopy/point.py
index d6a5ee8..7c061e0 100644
--- a/geopy/point.py
+++ b/geopy/point.py
@@ -15,20 +15,20 @@ POINT_PATTERN = re.compile(r"""
     .*?
     (?P<latitude>
       (?P<latitude_direction_front>[NS])?[ ]*
-        (?P<latitude_degrees>-?%(FLOAT)s)(?:[%(DEGREE)sD\*\u00B0\s][ ]*
+        (?P<latitude_degrees>[+-]?%(FLOAT)s)(?:[%(DEGREE)sD\*\u00B0\s][ ]*
         (?:(?P<latitude_arcminutes>%(FLOAT)s)[%(PRIME)s'm][ ]*)?
         (?:(?P<latitude_arcseconds>%(FLOAT)s)[%(DOUBLE_PRIME)s"s][ ]*)?
         )?(?P<latitude_direction_back>[NS])?)
     %(SEP)s
     (?P<longitude>
       (?P<longitude_direction_front>[EW])?[ ]*
-      (?P<longitude_degrees>-?%(FLOAT)s)(?:[%(DEGREE)sD\*\u00B0\s][ ]*
+      (?P<longitude_degrees>[+-]?%(FLOAT)s)(?:[%(DEGREE)sD\*\u00B0\s][ ]*
       (?:(?P<longitude_arcminutes>%(FLOAT)s)[%(PRIME)s'm][ ]*)?
       (?:(?P<longitude_arcseconds>%(FLOAT)s)[%(DOUBLE_PRIME)s"s][ ]*)?
       )?(?P<longitude_direction_back>[EW])?)(?:
     %(SEP)s
       (?P<altitude>
-        (?P<altitude_distance>-?%(FLOAT)s)[ ]*
+        (?P<altitude_distance>[+-]?%(FLOAT)s)[ ]*
         (?P<altitude_units>km|m|mi|ft|nm|nmi)))?
     \s*$
 """ % {

The reason why the first example works is because the leading + is not getting matched by the regexp. But the second example fails, because the second plus doesn't allow for the regex to match.

That format (with pluses) is not currently supported, so this is a new feature request rather than a bug.

A PR with that fix along with new tests and examples in docs would be welcome.

For the time being you can workaround this problem by simply stripping off all pluses from the input:

In [2]: geopy.point.Point('+037.33270,-122.00530'.replace('+', ''))
Out[2]: Point(37.3327, -122.0053, 0.0)

In [3]: geopy.point.Point('+041.69438,+001.51461'.replace('+', ''))
Out[3]: Point(41.69438, 1.51461, 0.0)

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

Successfully merging a pull request may close this issue.

2 participants
0