Skip to content

Commit baf299f

Browse files
authored
Merge pull request #73 from nuest/master
Dev update
2 parents 19f778c + 2db0d2d commit baf299f

22 files changed

+268
-170
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ addons:
1919
before_install:
2020
- gdal-config --version
2121
# installation of gdal Python package, see https://stackoverflow.com/a/17311033
22-
- export CPLUS_INCLUDE_PATH=/usr/include/gdal
23-
- export C_INCLUDE_PATH=/usr/include/gdal
24-
- pip install gdal==`gdal-config --version`
22+
#- export CPLUS_INCLUDE_PATH=/usr/include/gdal
23+
#- export C_INCLUDE_PATH=/usr/include/gdal
24+
- pip install pygdal=="`gdal-config --version`.*"
2525
install:
2626
- pip install -r requirements.txt
2727
- pip install -e .

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The following steps assume you are familiar with Python packages.
1313

1414
We follow a _fork and pull_ development model. [Fork](https://help.github.com/en/articles/fork-a-repo), then clone the repo:
1515

16-
```
16+
```bash
1717
git clone https://github.com/o2r-project/geoextent.git
1818
```
1919

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
[![Build Status](https://travis-ci.org/o2r-project/geoextent.svg?branch=master)](https://travis-ci.org/github/o2r-project/geoextent) [![PyPI version](https://badge.fury.io/py/geoextent.svg)](https://pypi.org/project/geoextent/0.1.0/)
2-
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/o2r-project/geoextent/master)
3-
41
# geoextent
52

3+
[![Build Status](https://travis-ci.org/o2r-project/geoextent.svg?branch=master)](https://travis-ci.org/github/o2r-project/geoextent) [![PyPI version](https://badge.fury.io/py/geoextent.svg)](https://pypi.org/project/geoextent/0.1.0/)
4+
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/o2r-project/geoextent/master)
5+
66
Python library for extracting geospatial extent of files and directories with multiple data formats
77

8-
This project is developed as part of the [DFG-funded](https://o2r.info/about/#funding) research project Opening Reproducible Research (o2r, https://o2r.info).
8+
This project is developed as part of the [DFG-funded](https://o2r.info/about/#funding) research project Opening Reproducible Research (o2r, [https://o2r.info](https://o2r.info)).
99

1010
## Installation
1111

12-
**System requirements**
12+
### System requirements
1313

1414
Python: `3.x`
1515

@@ -18,13 +18,17 @@ On Debian systems, the [UbuntuGIS](https://wiki.ubuntu.com/UbuntuGIS) project of
1818

1919
See the `packages` list in `travis.yml` for a full list of dependencies on Linux.
2020

21-
**Install from PyPI**
21+
### Install from PyPI
22+
23+
You must install a suitable version of `pygdal` manually first, see [instructions](https://pypi.org/project/pygdal/) and [this related SO thread with different helpful answers](https://gis.stackexchange.com/questions/28966/python-gdal-package-missing-header-file-when-installing-via-pip/124420#124420).
24+
We use `pygdal` for better compatibility with virtual environments.
2225

2326
```bash
27+
# pip install pygdal=="`gdal-config --version`.*"
2428
pip install geoextent
2529
```
2630

27-
**Source installation**
31+
### Source installation
2832

2933
```bash
3034
git clone https://github.com/o2r-project/geoextent
@@ -34,10 +38,6 @@ pip install -r requirements.txt
3438
pip install -e .
3539
```
3640

37-
**System requirements**
38-
39-
- see `travis.yml`
40-
4141
## Use
4242

4343
Run

docs/source/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
Changelog
33
=========
44

5+
0.3.0
6+
^^^^^
7+
8+
- Add debug option ``--debug`` and environment variable ``GEOEXTENT_DEBUG`` (:pr:`73`)
9+
- Remove need for ``-input=`` for passing input paths in CLI (:pr:`73`)
10+
- Switch to ``pygdal`` and update docs (:pr:`73`)
11+
512
0.2.0
613
^^^^^
714

docs/source/development.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ Notes for developers of ``geoextent``.
66
Environment
77
-----------
88

9-
All commands in this file assume you work in a virtual environment created with [``virtualenvwrapper``](https://virtualenvwrapper.readthedocs.io/en/latest/install.html) as follows (please keep up to date!):
9+
All commands in this file assume you work in a virtual environment created with virtualenvwrapper_ as follows (please keep up to date!):
10+
11+
.. _virtualenvwrapper: https://virtualenvwrapper.readthedocs.io/en/latest/install.html
1012

1113
::
1214

@@ -69,6 +71,8 @@ You can also run individual files:
6971

7072
::
7173

74+
pytest
75+
7276
pytest tests/test_api.py
7377

7478
Documentation
@@ -180,8 +184,8 @@ Install geoextent from TestPyPI and ensure the package is functional:
180184
geoextent --help
181185
geoextent --version
182186

183-
geoextent -b -t -input= /testdata/geojson/muenster_ring_zeit.geojson
184-
geoextent -b -t -input= /testdata/shapefile/gis_osm_buildings_a_free_1.shp
187+
geoextent -b -t /testdata/geojson/muenster_ring_zeit.geojson
188+
geoextent -b -t /testdata/shapefile/gis_osm_buildings_a_free_1.shp
185189

186190
Alternatively, use Debian Testing container to try out a more recent version of GDAL which matches the current release of the GDAL package on PyPI:
187191

@@ -198,6 +202,10 @@ Alternatively, use Debian Testing container to try out a more recent version of
198202

199203
wget https://github.com/o2r-project/geoextent/blob/master/tests/testdata/tif/wf_100m_klas.tif
200204

205+
geoextent -b muenster_ring_zeit.geojson
206+
geoextent --version
207+
geoextent --help
208+
201209

202210
Upload to PyPI
203211
^^^^^^^^^^^^^^

docs/source/howto/cli.rst

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Basics
1010
.. autoprogram:: geoextent.__main__:argparser
1111
:prog: \
1212

13-
1413
Examples
1514
--------
1615

@@ -31,7 +30,7 @@ Show help message
3130
:stderr:
3231

3332
import geoextent.__main__ as geoextent
34-
geoextent.print_help_fun()
33+
geoextent.print_help()
3534

3635
Extract bounding box from a single file
3736
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -41,7 +40,7 @@ Extract bounding box from a single file
4140

4241
::
4342

44-
geoextent -b -input= 'muenster_ring_zeit.geojson'
43+
geoextent -b muenster_ring_zeit.geojson
4544

4645
Output:
4746

@@ -55,9 +54,12 @@ Output:
5554
Extract time interval from a single file
5655
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5756

57+
.. note::
58+
You can find the file used in the examples of this section from `muenster_ring_zeit <https://raw.githubusercontent.com/o2r-project/geoextent/master/tests/testdata/geojson/muenster_ring_zeit.geojson>`_. Furthermore, for displaying the rendering of the file contents, see `rendered blob <https://github.com/o2r-project/geoextent/blob/master/tests/testdata/geojson/muenster_ring_zeit.geojson>`_.
59+
5860
::
5961

60-
geoextent -t -input='file.geojson'
62+
geoextent -t muenster_ring_zeit.geojson
6163

6264
Output:
6365

@@ -71,13 +73,27 @@ Output:
7173
Extract both bounding box and time interval from a single file
7274
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7375

76+
.. note::
77+
You can find the file used in the examples of this section from `muenster_ring_zeit <https://raw.githubusercontent.com/o2r-project/geoextent/master/tests/testdata/geojson/muenster_ring_zeit.geojson>`_. Furthermore, for displaying the rendering of the file contents, see `rendered blob <https://github.com/o2r-project/geoextent/blob/master/tests/testdata/geojson/muenster_ring_zeit.geojson>`_.
78+
7479
::
7580

76-
geoextent -b -t -input= 'file.geojson'
81+
geoextent -b -t muenster_ring_zeit.geojson
7782

7883
.. jupyter-execute::
7984
:hide-code:
8085
:stderr:
8186

8287
import geoextent.lib.extent as geoextent
8388
geoextent.fromFile('../tests/testdata/geojson/muenster_ring_zeit.geojson', True, True)
89+
90+
Debugging
91+
^^^^^^^^^
92+
93+
You can enable detailed logs by passing the ``--debug`` option, or by setting the environment variable ``GEOEXTENT_DEBUG=1``.
94+
95+
::
96+
97+
geoextent --debug -b -t muenster_ring_zeit.geojson
98+
99+
GEOEXTENT_DEBUG=1 geoextent -b -t muenster_ring_zeit.geojson

docs/source/supportedformats/index_supportedformats.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The file used in the example can be in the code repository: `muenster_ring_zeit.
3636

3737
::
3838

39-
geoextent -b -t -input= 'muenster_ring_zeit.geojson'
39+
geoextent -b -t muenster_ring_zeit.geojson
4040

4141
.. jupyter-execute::
4242
:hide-code:
@@ -70,7 +70,7 @@ The file used in the example can be obtained from `Zenodo Sandbox record 256820
7070

7171
::
7272

73-
geoextent -b -t -input= 'cities_NL.csv'
73+
geoextent -b -t cities_NL.csv
7474

7575
.. jupyter-execute::
7676
:hide-code:
@@ -90,7 +90,7 @@ The file used in the example is available online: `wf_100m_klas.tif <https://git
9090

9191
::
9292

93-
geoextent -b -input= 'wf_100m_klas.tif'
93+
geoextent -b wf_100m_klas.tif
9494

9595
.. jupyter-execute::
9696
:hide-code:
@@ -110,7 +110,7 @@ The file used in the example can be found at Geofabrik: `shapefiles_toulouse.zip
110110

111111
::
112112

113-
geoextent 'gis_osm_buildings_a_07_1.shp'
113+
geoextent -b gis_osm_buildings_a_07_1.shp
114114

115115
.. jupyter-execute::
116116
:hide-code:

geoextent/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
name = "geoextent"
22

3-
__version__ = '0.2.0'
3+
__version__ = '0.3.0'

geoextent/__main__.py

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from . import __version__ as current_version
55
import logging
66

7-
logging.basicConfig(level=logging.INFO)
8-
logger = logging.getLogger(__name__)
7+
logging.basicConfig(level=logging.WARNING)
8+
logger = logging.getLogger("geoextent")
99

1010
help_description = '''
1111
geoextent is a Python library for extracting geospatial and temporal extents of a file or a directory of multiple geospatial data formats.
@@ -49,7 +49,7 @@ def get_argparser():
4949
add_help=False,
5050
prog='geoextent',
5151
formatter_class=argparse.RawDescriptionHelpFormatter,
52-
usage= "geoextent [-h] [--formats] [--version] [-b] [-t] [-input= '[filepath|input file]']"
52+
usage= "geoextent [-h] [--formats] [--version] [--debug] [-b] [-t] [input file]']"
5353
)
5454

5555
parser.add_argument(
@@ -70,36 +70,41 @@ def get_argparser():
7070
help='show installed version'
7171
)
7272

73+
parser.add_argument(
74+
'--debug',
75+
help='turn on debug logging, alternatively set environment variable GEOEXTENT_DEBUG=1',
76+
action='store_true'
77+
)
78+
7379
parser.add_argument(
7480
'-b', '--bounding-box',
7581
action='store_true',
82+
default=False,
7683
help='extract spatial extent (bounding box)'
7784
)
7885

7986
parser.add_argument(
8087
'-t', '--time-box',
8188
action='store_true',
89+
default=False,
8290
help='extract temporal extent'
8391
)
8492

8593
parser.add_argument(
86-
'-input=',
94+
'files',
8795
action=readable_file_or_dir,
8896
default=os.getcwd(),
89-
nargs='+',
97+
nargs=argparse.REMAINDER,
9098
help="input file or path"
9199
)
92100

93101
return parser
94102

95-
def print_help_fun():
103+
def print_help():
96104
print(help_description)
97105
argparser.print_help()
98-
print_examples()
99-
print_supported_formats()
100-
101-
def print_examples():
102106
print(help_epilog)
107+
print_supported_formats()
103108

104109
def print_supported_formats():
105110
print(supported_formats)
@@ -113,34 +118,50 @@ def print_version():
113118
def main():
114119
# Check if there is no arguments, then print help
115120
if len(sys.argv[1:])==0:
116-
print_help_fun()
121+
print_help()
117122
argparser.exit()
118123

119-
args = vars(argparser.parse_args())
120-
logger.debug('Extracting from inputs %s', args['input='])
121-
122-
if(args['help']):
123-
print_help_fun()
124-
elif(args['version']):
124+
# version, help, and formats must be checked before parse, as otherwise files are required
125+
# but argpase gives an error if allowed to be parsed first
126+
if "--help" in sys.argv:
127+
print_help()
128+
argparser.exit()
129+
if "--version" in sys.argv:
125130
print_version()
126-
elif(args['formats']):
131+
argparser.exit()
132+
if "--formats" in sys.argv:
127133
print_supported_formats()
128-
else:
129-
# Check if file is exists happens in parser validation, see readable_file_or_dir
130-
if os.path.isfile(os.path.join(os.getcwd(), args['input='])):
131-
output = extent.fromFile(args['input='], bbox = args['bounding_box'], tbox = args['time_box'])
132-
if os.path.isdir(os.path.join(os.getcwd(), args['input='])):
133-
output = extent.fromDirectory(args['input='], bbox = args['bounding_box'], tbox = args['time_box'])
134-
135-
if output is None:
136-
raise Exception("This file format is not supported")
137-
138-
# print output
139-
if type(output) == list or type(output) == dict:
140-
print(str(output))
141-
else:
142-
print(output)
134+
argparser.exit()
143135

136+
args = vars(argparser.parse_args())
137+
files = args['files']
138+
logger.debug('Extracting from inputs %s', files)
139+
140+
# Set logging level
141+
if(args['debug']):
142+
logging.getLogger('geoextent').setLevel(logging.DEBUG)
143+
if(os.environ.get('GEOEXTENT_DEBUG', None) == "1"):
144+
logging.getLogger('geoextent').setLevel(logging.DEBUG)
145+
146+
# Check if file is exists happens in parser validation, see readable_file_or_dir
147+
try:
148+
if os.path.isfile(os.path.join(os.getcwd(), files)):
149+
output = extent.fromFile(files, bbox = args['bounding_box'], tbox = args['time_box'])
150+
if os.path.isdir(os.path.join(os.getcwd(), files)):
151+
output = extent.fromDirectory(files, bbox = args['bounding_box'], tbox = args['time_box'])
152+
except Exception as e:
153+
if(logger.getEffectiveLevel() >= logging.DEBUG):
154+
logger.exception(e)
155+
sys.exit(1)
156+
157+
if output is None:
158+
raise Exception("Did not find supported files at {}".format(files))
159+
160+
# print output
161+
if type(output) == list or type(output) == dict:
162+
print(str(output))
163+
else:
164+
print(output)
144165

145166
if __name__ == '__main__':
146167
main()

0 commit comments

Comments
 (0)