Skip to content

Commit

Permalink
Merge pull request #73 from nuest/master
Browse files Browse the repository at this point in the history
Dev update
  • Loading branch information
nuest authored Jul 1, 2020
2 parents 19f778c + 2db0d2d commit baf299f
Show file tree
Hide file tree
Showing 22 changed files with 268 additions and 170 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ addons:
before_install:
- gdal-config --version
# installation of gdal Python package, see https://stackoverflow.com/a/17311033
- export CPLUS_INCLUDE_PATH=/usr/include/gdal
- export C_INCLUDE_PATH=/usr/include/gdal
- pip install gdal==`gdal-config --version`
#- export CPLUS_INCLUDE_PATH=/usr/include/gdal
#- export C_INCLUDE_PATH=/usr/include/gdal
- pip install pygdal=="`gdal-config --version`.*"
install:
- pip install -r requirements.txt
- pip install -e .
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The following steps assume you are familiar with Python packages.

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

```
```bash
git clone https://github.com/o2r-project/geoextent.git
```

Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[![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/)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/o2r-project/geoextent/master)

# geoextent

[![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/)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/o2r-project/geoextent/master)

Python library for extracting geospatial extent of files and directories with multiple data formats

This project is developed as part of the [DFG-funded](https://o2r.info/about/#funding) research project Opening Reproducible Research (o2r, https://o2r.info).
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)).

## Installation

**System requirements**
### System requirements

Python: `3.x`

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

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

**Install from PyPI**
### Install from PyPI

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).
We use `pygdal` for better compatibility with virtual environments.

```bash
# pip install pygdal=="`gdal-config --version`.*"
pip install geoextent
```

**Source installation**
### Source installation

```bash
git clone https://github.com/o2r-project/geoextent
Expand All @@ -34,10 +38,6 @@ pip install -r requirements.txt
pip install -e .
```

**System requirements**

- see `travis.yml`

## Use

Run
Expand Down
7 changes: 7 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Changelog
=========

0.3.0
^^^^^

- Add debug option ``--debug`` and environment variable ``GEOEXTENT_DEBUG`` (:pr:`73`)
- Remove need for ``-input=`` for passing input paths in CLI (:pr:`73`)
- Switch to ``pygdal`` and update docs (:pr:`73`)

0.2.0
^^^^^

Expand Down
14 changes: 11 additions & 3 deletions docs/source/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Notes for developers of ``geoextent``.
Environment
-----------

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!):
All commands in this file assume you work in a virtual environment created with virtualenvwrapper_ as follows (please keep up to date!):

.. _virtualenvwrapper: https://virtualenvwrapper.readthedocs.io/en/latest/install.html

::

Expand Down Expand Up @@ -69,6 +71,8 @@ You can also run individual files:

::

pytest

pytest tests/test_api.py

Documentation
Expand Down Expand Up @@ -180,8 +184,8 @@ Install geoextent from TestPyPI and ensure the package is functional:
geoextent --help
geoextent --version

geoextent -b -t -input= /testdata/geojson/muenster_ring_zeit.geojson
geoextent -b -t -input= /testdata/shapefile/gis_osm_buildings_a_free_1.shp
geoextent -b -t /testdata/geojson/muenster_ring_zeit.geojson
geoextent -b -t /testdata/shapefile/gis_osm_buildings_a_free_1.shp

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:

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

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

geoextent -b muenster_ring_zeit.geojson
geoextent --version
geoextent --help


Upload to PyPI
^^^^^^^^^^^^^^
Expand Down
26 changes: 21 additions & 5 deletions docs/source/howto/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Basics
.. autoprogram:: geoextent.__main__:argparser
:prog: \


Examples
--------

Expand All @@ -31,7 +30,7 @@ Show help message
:stderr:

import geoextent.__main__ as geoextent
geoextent.print_help_fun()
geoextent.print_help()

Extract bounding box from a single file
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -41,7 +40,7 @@ Extract bounding box from a single file

::

geoextent -b -input= 'muenster_ring_zeit.geojson'
geoextent -b muenster_ring_zeit.geojson

Output:

Expand All @@ -55,9 +54,12 @@ Output:
Extract time interval from a single file
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. note::
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>`_.

::

geoextent -t -input='file.geojson'
geoextent -t muenster_ring_zeit.geojson

Output:

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

.. note::
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>`_.

::

geoextent -b -t -input= 'file.geojson'
geoextent -b -t muenster_ring_zeit.geojson

.. jupyter-execute::
:hide-code:
:stderr:

import geoextent.lib.extent as geoextent
geoextent.fromFile('../tests/testdata/geojson/muenster_ring_zeit.geojson', True, True)

Debugging
^^^^^^^^^

You can enable detailed logs by passing the ``--debug`` option, or by setting the environment variable ``GEOEXTENT_DEBUG=1``.

::

geoextent --debug -b -t muenster_ring_zeit.geojson

GEOEXTENT_DEBUG=1 geoextent -b -t muenster_ring_zeit.geojson
8 changes: 4 additions & 4 deletions docs/source/supportedformats/index_supportedformats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The file used in the example can be in the code repository: `muenster_ring_zeit.

::

geoextent -b -t -input= 'muenster_ring_zeit.geojson'
geoextent -b -t muenster_ring_zeit.geojson

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

::

geoextent -b -t -input= 'cities_NL.csv'
geoextent -b -t cities_NL.csv

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

::

geoextent -b -input= 'wf_100m_klas.tif'
geoextent -b wf_100m_klas.tif

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

::

geoextent 'gis_osm_buildings_a_07_1.shp'
geoextent -b gis_osm_buildings_a_07_1.shp

.. jupyter-execute::
:hide-code:
Expand Down
2 changes: 1 addition & 1 deletion geoextent/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name = "geoextent"

__version__ = '0.2.0'
__version__ = '0.3.0'
87 changes: 54 additions & 33 deletions geoextent/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from . import __version__ as current_version
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.WARNING)
logger = logging.getLogger("geoextent")

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

parser.add_argument(
Expand All @@ -70,36 +70,41 @@ def get_argparser():
help='show installed version'
)

parser.add_argument(
'--debug',
help='turn on debug logging, alternatively set environment variable GEOEXTENT_DEBUG=1',
action='store_true'
)

parser.add_argument(
'-b', '--bounding-box',
action='store_true',
default=False,
help='extract spatial extent (bounding box)'
)

parser.add_argument(
'-t', '--time-box',
action='store_true',
default=False,
help='extract temporal extent'
)

parser.add_argument(
'-input=',
'files',
action=readable_file_or_dir,
default=os.getcwd(),
nargs='+',
nargs=argparse.REMAINDER,
help="input file or path"
)

return parser

def print_help_fun():
def print_help():
print(help_description)
argparser.print_help()
print_examples()
print_supported_formats()

def print_examples():
print(help_epilog)
print_supported_formats()

def print_supported_formats():
print(supported_formats)
Expand All @@ -113,34 +118,50 @@ def print_version():
def main():
# Check if there is no arguments, then print help
if len(sys.argv[1:])==0:
print_help_fun()
print_help()
argparser.exit()

args = vars(argparser.parse_args())
logger.debug('Extracting from inputs %s', args['input='])

if(args['help']):
print_help_fun()
elif(args['version']):
# version, help, and formats must be checked before parse, as otherwise files are required
# but argpase gives an error if allowed to be parsed first
if "--help" in sys.argv:
print_help()
argparser.exit()
if "--version" in sys.argv:
print_version()
elif(args['formats']):
argparser.exit()
if "--formats" in sys.argv:
print_supported_formats()
else:
# Check if file is exists happens in parser validation, see readable_file_or_dir
if os.path.isfile(os.path.join(os.getcwd(), args['input='])):
output = extent.fromFile(args['input='], bbox = args['bounding_box'], tbox = args['time_box'])
if os.path.isdir(os.path.join(os.getcwd(), args['input='])):
output = extent.fromDirectory(args['input='], bbox = args['bounding_box'], tbox = args['time_box'])

if output is None:
raise Exception("This file format is not supported")

# print output
if type(output) == list or type(output) == dict:
print(str(output))
else:
print(output)
argparser.exit()

args = vars(argparser.parse_args())
files = args['files']
logger.debug('Extracting from inputs %s', files)

# Set logging level
if(args['debug']):
logging.getLogger('geoextent').setLevel(logging.DEBUG)
if(os.environ.get('GEOEXTENT_DEBUG', None) == "1"):
logging.getLogger('geoextent').setLevel(logging.DEBUG)

# Check if file is exists happens in parser validation, see readable_file_or_dir
try:
if os.path.isfile(os.path.join(os.getcwd(), files)):
output = extent.fromFile(files, bbox = args['bounding_box'], tbox = args['time_box'])
if os.path.isdir(os.path.join(os.getcwd(), files)):
output = extent.fromDirectory(files, bbox = args['bounding_box'], tbox = args['time_box'])
except Exception as e:
if(logger.getEffectiveLevel() >= logging.DEBUG):
logger.exception(e)
sys.exit(1)

if output is None:
raise Exception("Did not find supported files at {}".format(files))

# print output
if type(output) == list or type(output) == dict:
print(str(output))
else:
print(output)

if __name__ == '__main__':
main()
Loading

0 comments on commit baf299f

Please sign in to comment.