Skip to content

Added 2 helper functions lonlat and latlon, added documentation for each - #282

Merged
KostyaEsmukov merged 8 commits into
geopy:masterfrom
paulefoe:master
May 8, 2018
Merged

KostyaEsmukov merged 8 commits into
geopy:masterfrom
paulefoe:master

Conversation

@paulefoe

Copy link
Copy Markdown
Contributor

this commit fixes #202

@KostyaEsmukov KostyaEsmukov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, thank you very much for this! Some changes are definitely required, and, TBH, I'm not quite sure how should this look in the end. I left a suggestion on removing latlon function, because it fully replicates Point constructor.

Also I've noticed that these functions are not referenced in the docs. Could you do that please? I think that these should go right after module doc, before geodesic (docs/index.rst file). See CONTRIBUTING.md for how-to on building and viewing docs locally.

PS I know how hard this is to write good docs, especially on a foreign language. I'm still learning here too! Just want to let you know that I appreciate your efforts.

Comment thread geopy/distance.py
>>> _, pa = g.geocode('Palo Alto, CA')
>>> print((d(ne, cl) + d(cl, wa) + d(wa, pa)).miles)
3277.30439191

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please revert this change?

Comment thread geopy/distance.py Outdated
>>> newport_ri = (41.49008, -71.312796)
>>> cleveland_oh = (41.499498, -81.695391)
>>> print(distance(latlon(*newport_ri), latlon(*cleveland_oh)).miles)
538.3904453677203

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameters (below) must be separated from description (above) with one empty line:

"""
... description ...
  <-- empty newline
:param ...
"""

Comment thread geopy/distance.py Outdated
def latlon(y, x, z=0):
"""
Helper function that can be used for more explicit and obvious calling of the distance methods
>>> from geopy.distance import latlon, distance

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that code examples must be indented to be rendered correctly, though I'm not sure. Anyway, all the examples in this file are indented, so could you please do that there too?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still relevant

Comment thread geopy/distance.py Outdated
Helper function that can be used for more explicit and obvious calling of the distance methods
>>> from geopy.distance import latlon, distance
>>> newport_ri = (41.49008, -71.312796)
>>> cleveland_oh = (41.499498, -81.695391)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it might be not easy to comprehend that this is an y-x order, but this is crucial for understanding the intent of this function. Maybe a more explanatory variable name would help?

newport_ri_yx = (41.49008, -71.312796)

Comment thread geopy/distance.py Outdated

def lonlat(x, y, z=0):
"""
Helper function that can be used for more explicit and obvious calling of the distance methods

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that obvious is a proper term for documentation :-)

This description should introduce the reader to the problem: distance accepts coordinates in (y, x)/(lat, lon) order, while some other libraries/systems might use (x, y)/(lon, lat) instead.

And then suggest a solution: using this function, which accepts coordinates in (x, y, [z]) order and returns a Point instance for the distance.

Comment thread geopy/distance.py Outdated

def latlon(y, x, z=0):
"""
Helper function that can be used for more explicit and obvious calling of the distance methods

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is very different from the previous one, so should be the description. I believe it will be confusing to the reader to see a function which transforms (y, x, [z]) to the same (y, x, [z]).

Actually I'm starting to think that instead of introducing this function, it would probably be better to simply encourage the use of the Point constructor instead. What do you think?

@paulefoe

paulefoe commented May 2, 2018

Copy link
Copy Markdown
Contributor Author

Hey, it's been a while, I'm verry sorry. I got sick and then a lot of work appeared suddenly.
Anyway, so should I delete latlon function?
And did build failed? I don't get it, I didn't change anything other than docs.

@KostyaEsmukov

Copy link
Copy Markdown
Member

Hey, it's been a while, I'm verry sorry. I got sick and then a lot of work appeared suddenly.

No problem, this can wait.

Anyway, so should I delete latlon function?

Yup, I think that would be better.

And did build failed? I don't get it, I didn't change anything other than docs.

Click on the red cross near a commit to see the build status #374139588. There's a single failing job #374139594, which is, apparently, caused by a random failure due to the tests relying on the network, which might fail (in this case there was a timeout). The failed tests in this job are surely unrelated to your changes, so all that was needed was to trigger the build one more time. That last merge of yours did it. You could've also amended the commit and force-pushed it.

Comment thread geopy/distance.py Outdated
def lonlat(x, y, z=0):
"""
Helper function that can be used for more explicit and obvious calling of the distance methods
distance accepts coordinates in (y, x)/(lat, lon) order, while some other libraries/systems might use

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. A sentence should start with a capital letter :). But in this case distance is a term (a class reference, more specifically), not a plain word. See the docs around for examples on how distance is formatted there.
  2. Please try to keep the line lengths close to 80-ish.
  3. Coordinate pairs should also be formatted as terms (with backticks, I guess), otherwise they might be split by word-wrapping.

Comment thread geopy/distance.py Outdated
distance accepts coordinates in (y, x)/(lat, lon) order, while some other libraries/systems might use
(x, y)/(lon, lat).
This helper function introduced here for solving this problem. It accepts coordinates in a form of (x, y)/(lon, lat)
and returns Point that is safe to use with distance

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. A sentence should end with a dot (or some other relevant punctuation mark).

  2. It seems to me that these two sentences are intended to be in their own paragraph. Paragraphs should be separated with one empty line, which is missing there.

  3. These two sentences don't sound natural to me. Let me propose the following phrasing:

     This function provides a convenient way to convert coordinates of 
     the ``(x, y)/(lon, lat)`` format to a :class:`geopy.point.Point` instance.
    
     Example::
    

@KostyaEsmukov KostyaEsmukov added this to the 1.14 milestone May 6, 2018
@paulefoe

paulefoe commented May 7, 2018

Copy link
Copy Markdown
Contributor Author

Hey again, thanks for positive feedback, I am doing my best, but it's actually pretty hard to write meaningful docs, so thank you very much for your guidance and patience!

@KostyaEsmukov KostyaEsmukov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few notes, otherwise it looks good. Thank you for your efforts!

Comment thread geopy/distance.py Outdated
>>> print((d(ne, cl) + d(cl, wa) + d(wa, pa)).miles)
3277.30439191

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be reverted

Comment thread geopy/distance.py Outdated

:param x: longitude
:param y: latitude
:param z: altitude

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:param z: (optional) altitude

Comment thread geopy/distance.py Outdated

Example::

>>> from geopy.distance import lonlat, distance

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread geopy/distance.py Outdated
Example::

>>> from geopy.distance import lonlat, distance
>>> newport_ri = (-71.312796, 41.49008)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newport_ri_xy and cleveland_oh_xy

@KostyaEsmukov KostyaEsmukov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Merging.

@KostyaEsmukov
KostyaEsmukov merged commit 2064f7f into geopy:master May 8, 2018
KostyaEsmukov pushed a commit that referenced this pull request May 8, 2018
@KostyaEsmukov

Copy link
Copy Markdown
Member

We seem to have forgotten about the tests! Added in fdfaac7.

Also the import in the docs was incorrect: it was

.. autofunction:: geopy.lonlat

... which yielded an error when building the docs, because lonlat is not exported from geopy. It should've been this:

.. autofunction:: geopy.distance.lonlat

I guess it was just a typo.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Distance calculation takes (y, x) instead of (x, y)

2 participants