-
Notifications
You must be signed in to change notification settings - Fork 819
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
Add scripts/get-shapefiles.py #2137
Add scripts/get-shapefiles.py #2137
Conversation
|
||
print "\nChecking shapeindex version:" | ||
try: | ||
err = subprocess.call("bin/shapeindex -V", shell=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We aren't creating a bin directory, so this should just be shapeindex
I wouldn't mind replacing |
It would be nice to have a script which is 2.7 and 3 compatible. |
@pnorman: In fact I am trying to manage implications of contributing to openstreetmap-carto through a Windows installation of Tilemill. One aspect that needed rewriting was get-shapefiles.sh |
One of the important features of get-shapefiles.sh is you can re-run it to update |
Added command line arguments. Run it with To allow re-run it to update, use
|
How hard is it to make the script do the following:
Also, I can see there is inconsistencies in both variable naming (all lower (nodownload), snakecase (update_mode), other (Owps)) and indentation. I'm not a python programmer but best to go with whatever the python conventions are. Finally, if this is a replacement for get-shapefiles.sh, then the PR should include removing the old version. |
@gravitystorm: OK, I'll try in the next days |
help="do not populate target directories with downloaded data") | ||
parser.add_argument('-s', "--noshape", dest='noshape', action='store_true', | ||
help="do not run shapeindex") | ||
parser.add_argument('-1', dest='Owb', action='store_true', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variables like --world-boundaries
, --simplified-water
, --ne-admin
, etc would be easier to remember than numerics
121d4af
to
4f73b92
Compare
if args.option_wps: | ||
subprocess.call("shapeindex --shape_files data/antarctica-icesheet-polygons-3857/icesheet_polygons.shp") | ||
print() | ||
if args.option_aip: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
option_aip controls the call to icesheet-outlines.
option_aio (the next one) controls the ne110m admin boundaries.
I guess this is not intended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tilmanb: Thanks, I will correct this and will also change the water acronyms to land
I found the following issues running it
I get the error
Code and data are intermixed and there's a lot of repeated similar code. The shell script has this too, but it's only 86 lines. I suggest moving the definitions of the files and their locations to the top in an array, dict, or other structure and having code which loops over that. |
@pnorman: thanks for the feedbacks, I will setup a UNIX VM and test it there. OK for the updates you asked. I did not use curl to simplify the Windows setup.
Would you refer to the Scripted download section in INSTALL.md or also something else? |
Anywhere that get-shapefiles.sh is mentioned. |
@Ircama Is this ready for review? |
@math1985 yes, thanks. |
@pnorman Do you have time to review this? |
Yes, later this week. |
0f156aa
to
5cdc3b9
Compare
Memo for me: there is some change to be done to comply to PEP8 style guide. Will do ASAP with a new commit. Also a documentation typo needs fixing. |
I still need to do a code review on this. |
5cdc3b9
to
c0ae573
Compare
[Unwanted push, just rebased by now] |
c0ae573
to
ca7277f
Compare
@pnorman: code now ready for review, thanks |
Additional comments to get-shapefiles.py, moved from gravitystorm#2137 The aim of this PR is to propose a documentation for the scripts that are available in the *scripts* directory. It updates the already existing README.md with some currently available information. Notice that get-shapefiles.py is already mentioned here.
Rebased |
Fixes gravitystorm#2333 (comment) reported by @kocio-pl (thanks!) Rebased with the previous commit: Add a description for all the scripts included in OpenStreetMap Carto Additional comments to get-shapefiles.py, moved from gravitystorm#2137 The aim of this PR is to propose a documentation for the scripts that are available in the *scripts* directory. It updates the already existing README.md with some currently available information. Notice that get-shapefiles.py is already mentioned here.
Resolves #43 |
b8a49c8
to
ba2a700
Compare
Rebased so that it can be easily reviewed/merged |
ba2a700
to
45e92aa
Compare
If you place the "resolves" text in the first message of this PR the issues will be closed automatically. |
I think you should also delete get-shapefiles.sh script in this PR. |
@HolgerJeromin, @kocio-pl: thanks, I thought that any place within the PR for a comment was enough for the auto closure.
Yes, thanks a lot. I have just fixed it with a new commit. |
372345e
to
b9cdc68
Compare
@pnorman Any problems left with this PR? |
the -1 to -6 short options. Aside from that, it seems to work. I don't like the gain in code complexity, but it's probably worth it for windows support in the download script. |
@pnorman - OK no problem; would you like to have the short options removed (keeping the long ones), or both the short and long options removed (with reference to -1 to -6)? Just one note, as I see many sites mentioning the bash script, I’d like to double check that its removal is wanted. |
The long options are good to have.
We don't want to maintain two download scripts. |
I'm currently having problems with shapeindex on my Ubuntu 16.04. It tries to load the shared libraries of Ubuntu 14.04. So I can't test this right now. I also think the short options -1 .. -6 are not the best choice. |
@Ircama Double check is here, so do you plan to remove the short options? I would like to merge this PR soon, if possible. |
- Removed short options -1 .. -6 - Rebased Add scripts/get-shapefiles.py Previous changes: - Removed unneeded information from the documentation - Compliance to PEP8 style guide, typo correction and some revision - Coding revised to fully comply to PEP8 style guide - A documentation typo has been fixed - Additional documentation provided - Some minor code improvements - code compacted and exploiting a dictionary - added execution flag - tested with Windows, Ubuntu and Cygwin - file dates are checked before downloading new files - curl is used if available - return codes are checked - documentation updated - now update is the default and does not require confirmation - code improvements $ ./get-shapefiles.py -h usage: get-shapefiles.py [-h] [-c] [-d <directory name>] [-e] [-f] [-l] [-n] [-p] [-r] [-s] [-u] [--world-boundaries] [--simplified-land] [--ne-admin] [--land-polygons] [--icesheet-polygons] [--icesheet-outlines] optional arguments: -h, --help show this help message and exit -c, --check check whether the 'data' directory already exists -d <directory name>, --directory <directory name> set the name of the data directory (default: 'data') -e, --no-extract do not populate target directories with the expansion of downloaded data -f, --force force continuing even if project.yaml does not exist -l, --no-curl do not use 'curl' even if available -n, --no-download do not download archive if already existing locally -p, --pause pause before starting -r, --remove remove each downloaded archive after its expansion -s, --no-shape do not run shapeindex -u, --update force downloading files even if not newer than the locally existing ones --world-boundaries only process world_boundaries --simplified-land only process simplified-land-polygons-complete-3857 --ne-admin only process ne_110m_admin_0_boundary_lines_land --land-polygons only process land-polygons-split-3857 --icesheet-polygons only process antarctica-icesheet-polygons-3857 --icesheet-outlines only process antarctica-icesheet-outlines-3857 This script generates and populates the 'data' directory with all needed shapefiles, including indexing them through shapeindex.
b9cdc68
to
3fd7ddf
Compare
Code updated as requested. I meanwhile noticed that, when using |
I just made some basic testing with Python 2/3 and shapeindex/--no-shape under Linux and it works. I think that 6 months for one script is long enough and fine tuning can be done later. In the meantime we lack portability and the code waiting too long in the queue may need to be keep in sync, which is additional problem. Thanks for your code and patience, @Ircama! |
[Edited summary for this PR, left out on my first push.
Edited the command line options to reflect the merged commit]
The aim of this PR is to replace get-shapefiles.sh with a Python version named get-shapefiles.py and positioned in the scripts directory of openstreetmap-carto.
It generates and populates the data directory with all needed shapefiles, including indexing them through shapeindex. Related features are the same as the original shell script, with the addition of some command line options.
The code exploits an internal dictionary for easy adaptation to future changes, supports Windows, UNIX, Python 2.7, Python 3 and curl when installed (even if curl is not required, for more comfortable Windows support). Installation of shapeindex is a prerequisite to index files, but is not strictly required if
-s
option is used (old indexes are not automatically removed; it is better to manually remove indexes from the subfolders when updating the data directory without updating indexes).The script can be run from the scripts directory of openstreetmap-carto, or from its base folder, or through absolute path from any directory. It should allow a default Web proxy and also the configuration of the HTTP_PROXY environment variable. With Windows, PAC and NTLM authentication are not supported.
Documentation has been updated accordingly.
Resolves #43
Resolves #66
Resolves #1233
Basic invocation:
scripts/get-shapefiles.py