Added ability to use remote geo_path#602
Added ability to use remote geo_path#602ocefpaf merged 9 commits intopython-visualization:masterfrom
Conversation
| # Create GeoJson object | ||
| if geo_path: | ||
| geo_data = open(geo_path) | ||
| if geo_path.lower().startswith(('http','ftp','https')): |
There was a problem hiding this comment.
E231 missing whitespace after ','
W291 trailing whitespace
| geo_data = open(geo_path) | ||
| if geo_path.lower().startswith(('http','ftp','https')): | ||
| geo_data = requests.get(geo_path).json() | ||
| else: |
| # Create GeoJson object | ||
| if geo_path: | ||
| geo_data = open(geo_path) | ||
| if geo_path.lower().startswith(('http', 'ftp', 'https')): |
There was a problem hiding this comment.
Probably should include the colon, too; someone could have a file that starts with any of these sequences.
There was a problem hiding this comment.
Maybe it is an overkill but how about something like:
def scheme_validator(url):
parsed = urlparse(url)
if parsed.scheme in ['http', 'ftp', 'https']:
return True
return Falseto validade the scheme?
I am fine with the extra dependency. We could use a
The PR is fine. You can add a simple test that just tries to use this. See https://github.com/python-visualization/folium/blob/master/tests/test_folium.py#L282 for an example (but yours will probably be much simpler than that.) Please add:
and this should be good to go. |
|
Cool, I will try to get the test written in the next few days. I will modify the Will modify docs and reqs accordingly. |
…swith on URL checking.
| # Create GeoJson object | ||
| if geo_path: | ||
| geo_data = open(geo_path) | ||
| if geo_path.lower().startswith(('http:', 'ftp':, 'https:')): |
There was a problem hiding this comment.
E231 missing whitespace after ':'
E999 SyntaxError: invalid syntax
| from six import PY3 | ||
| import branca.element | ||
|
|
||
| import requests |
There was a problem hiding this comment.
F401 'requests' imported but unused
| self.map = folium.Map(zoom_start=4) | ||
|
|
||
| # Adding remote GeoJSON as additional layer. | ||
| path = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data/us-states.json' |
There was a problem hiding this comment.
E501 line too long (114 > 100 characters)
|
|
||
| # For testing remote requests | ||
| remote_url = '/'.join([ | ||
| 'https://raw.githubusercontent.com', |
There was a problem hiding this comment.
E101 indentation contains mixed spaces and tabs
W191 indentation contains tabs
| # For testing remote requests | ||
| remote_url = '/'.join([ | ||
| 'https://raw.githubusercontent.com', | ||
| 'python-visualization/folium/master', |
| remote_url = '/'.join([ | ||
| 'https://raw.githubusercontent.com', | ||
| 'python-visualization/folium/master', | ||
| 'examples/data/us-states.json']) |
|
Right, think I've managed to tidy everything up -- that stickler really is a stickler (but I can appreciate that). Have added a simple test that tries to remotely access one of the example JSON files packaged with Folium from GitHub and checks that the map extent matches its expectations. |
|
Please do check that edits to CHANGES.txt and such are appropriate and reasonable. |
| - Added `smooth_factor `option to `GeoJSON`, `TopoJSON` and `Choropleth` (JamesGardiner #428) | ||
| - `Map` object now accepts Leaflet global switches (sgvandijk #424) | ||
| - Added weight option to CircleMarker (palewire #581) | ||
| - Added requests support to enable http(s) and ftp for geo_path parameter |
There was a problem hiding this comment.
If you want feel free to add you github handle and the PR number here too.
| remote_url = '/'.join([ | ||
| 'https://raw.githubusercontent.com', | ||
| 'python-visualization/folium/master', | ||
| 'examples/data/us-states.json']) |
Thanks! Looks good to go.
And it saves the devs time while reviewing PRs 😉
That is perfect. Let's wait on Travis-CI and merge this. |
|
Cool — I’ve added my info to the CHANGES.txt file so I think we’re good to go.
Thank you all for the support/tips on getting this through to merged. It’s not something I’ve done before with Travis and all these other tools so it could have been… hairy.
jon
… On 9 Mar 2017, at 14:46, Filipe ***@***.***> wrote:
Right, think I've managed to tidy everything up
Thanks! Looks good to go.
that stickler really is a stickler (but I can appreciate that).
And it saves the devs time while reviewing PRs 😉
Have added a simple test that tries to remotely access one of the example JSON files packaged with Folium from GitHub and checks that the map extent matches its expectations.
That is perfect. Let's wait on Travis-CI and merge this.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#602 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ADEzZe7o9GCCR3m0CQKPI2NVSu4gYy6tks5rkBDCgaJpZM4MUsut>.
--
Jon Reades
m: 07976.987.392
e: jon@reades.com <mailto:jon@reades.com>
im: jereades
|
|
Thanks for the awesome contribution @jreades! |
Added ability to use remote geo_path
Adds a dependency (requests) but enables ability to use http/https/ftp for loading geo_paths.
I'm really rusty on unit tests (last did them in Java 1.2 or thereabouts) so I've not attempted to implement these. This is the first time I've done this, so please review carefully before accepting the PR.