Skip to content
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

osgeo.utils -> osgeo_utils individual package #3259

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion autotest/pymod/test_py_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#

# path relative to gdal root
utils_subdir = 'swig/python/osgeo/utils'
utils_subdir = 'swig/python/gdal-utils/osgeo_utils'
samples_subdir = 'swig/python/samples'
samples_path = '../../gdal/' + samples_subdir

Expand Down
2 changes: 1 addition & 1 deletion autotest/pyscripts/test_gdal_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# test that numpy is available, if not skip all tests
try:
import numpy as np
from osgeo.utils import gdal_calc
from osgeo_utils import gdal_calc
from osgeo.gdal_array import GDALTypeCodeToNumericTypeCode
numpy_available = True
except (ImportError, AttributeError):
Expand Down
4 changes: 2 additions & 2 deletions autotest/pyscripts/test_pct.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@


from osgeo import gdal
from osgeo.utils import gdalattachpct, rgb2pct
import osgeo.utils.auxiliary.color_table as color_table
from osgeo_utils import gdalattachpct, rgb2pct
import osgeo_utils.auxiliary.color_table as color_table
import gdaltest
import test_py_scripts
import pytest
Expand Down
37 changes: 37 additions & 0 deletions gdal/swig/python/gdal-utils/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
gdal-utils
=============

This gdal-utils Python package includes modules and functions that use and extend the
GDAL_ Geospatial Data Abstraction Library.

The GDAL project (primarily Even Rouault) maintains SWIG generated Python
bindings for GDAL and OGR, which are included in the gdal package.

Please also refer to the osgeo documentation and to the GDAL API Tutorial.

Currently, The the gdal package also includes the utils package,
but in the future they might be available only in this gdal-utils package.

Because we don't test the utils against a different versions of gdal -
If you want to get the latest version of the utils, we do recommend you to upgrade
to the latest version of gdal and get the latest version of both.

But if you are unable to upgrade the gdal package for whatever reason,
You may still be able to upgrade the utils by installing this package.

Dependencies
------------

* gdal (the osgeo package)
* numpy (1.0.0 or greater) and header files (numpy-devel) (not explicitly
required, but many examples and utilities will not work without it)

Installation
------------

gdal-utils can be installed from pypi.org::

$ pip install gdal-utils

.. _GDAL API Tutorial: https://gdal.org/tutorials/
.. _GDAL: http://www.gdal.org
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import tempfile
from typing import Sequence, Union

from osgeo.utils.auxiliary import base
from osgeo_utils.auxiliary import base

PathOrStrings = Union[base.PathLike, Sequence[str]]
ColorPaletteOrPathOrStrings = Union['ColorPalette', PathOrStrings]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
from typing import Optional

from osgeo import gdal
from osgeo.utils.auxiliary.base import PathLike
from osgeo.utils.auxiliary.util import open_ds, path_or_ds
from osgeo.utils.auxiliary.color_palette import get_color_palette, ColorPaletteOrPathOrStrings
from osgeo_utils.auxiliary.base import PathLike
from osgeo_utils.auxiliary.util import open_ds, path_or_ds
from osgeo_utils.auxiliary.color_palette import get_color_palette, ColorPaletteOrPathOrStrings


def get_color_table_from_raster(path_or_ds: path_or_ds) -> Optional[gdal.ColorTable]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from typing import Optional, Union, Sequence, Dict

from osgeo import gdal
from osgeo.utils.auxiliary.rectangle import GeoRectangle
from osgeo_utils.auxiliary.rectangle import GeoRectangle


class Extent(Enum):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from typing import Optional, Union

from osgeo import gdal
from osgeo.utils.auxiliary.base import get_extension, is_path_like, PathLike
from osgeo_utils.auxiliary.base import get_extension, is_path_like, PathLike

path_or_ds = Union[PathLike, gdal.Dataset]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
import numpy as np

from osgeo import gdal
from osgeo.utils.auxiliary.base import num
from osgeo.utils.auxiliary.numpy_util import GDALTypeCodeAndNumericTypeCodeFromDataSet
from osgeo_utils.auxiliary.base import num
from osgeo_utils.auxiliary.numpy_util import GDALTypeCodeAndNumericTypeCodeFromDataSet


def Usage():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@

from osgeo import gdal
from osgeo import gdal_array
from osgeo.utils.auxiliary.base import is_path_like, PathLike
from osgeo.utils.auxiliary.util import GetOutputDriverFor
from osgeo.utils.auxiliary.extent_util import Extent, GT
from osgeo.utils.auxiliary import extent_util
from osgeo.utils.auxiliary.rectangle import GeoRectangle
from osgeo.utils.auxiliary.color_table import get_color_table
from osgeo_utils.auxiliary.base import is_path_like, PathLike
from osgeo_utils.auxiliary.util import GetOutputDriverFor
from osgeo_utils.auxiliary.extent_util import Extent, GT
from osgeo_utils.auxiliary import extent_util
from osgeo_utils.auxiliary.rectangle import GeoRectangle
from osgeo_utils.auxiliary.color_table import get_color_table

GDALDataType = int

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import time

from osgeo import gdal
from osgeo.utils.auxiliary.util import GetOutputDriverFor
from osgeo_utils.auxiliary.util import GetOutputDriverFor

progress = gdal.TermProgress_nocb

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import os.path
import sys
from osgeo import gdal
from osgeo.utils.auxiliary.util import GetOutputDriverFor
from osgeo_utils.auxiliary.util import GetOutputDriverFor


def Usage():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

from osgeo import gdal
from osgeo import ogr
from osgeo.utils.auxiliary.util import GetOutputDriverFor
from osgeo_utils.auxiliary.util import GetOutputDriverFor


def Usage():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import sys

from osgeo import gdal
from osgeo.utils.auxiliary.util import GetOutputDriverFor
from osgeo_utils.auxiliary.util import GetOutputDriverFor


def Usage():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import sys

from osgeo import gdal
from osgeo.utils.auxiliary.util import GetOutputDriverFor
from osgeo_utils.auxiliary.util import GetOutputDriverFor


def Usage():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import sys

from osgeo import gdal
from osgeo.utils.auxiliary.util import GetOutputDriverFor, open_ds
from osgeo.utils.auxiliary.color_table import get_color_table
from osgeo_utils.auxiliary.util import GetOutputDriverFor, open_ds
from osgeo_utils.auxiliary.color_table import get_color_table


def Usage():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

from osgeo import gdal
from osgeo import ogr
from osgeo.utils.auxiliary.util import GetOutputDriverFor
from osgeo_utils.auxiliary.util import GetOutputDriverFor


def Usage():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import numpy as np

from osgeo import gdal
from osgeo.utils.auxiliary.util import GetOutputDriverFor, open_ds
from osgeo.utils.auxiliary.color_palette import get_color_palette
from osgeo.utils.auxiliary.color_table import get_color_table
from osgeo_utils.auxiliary.util import GetOutputDriverFor, open_ds
from osgeo_utils.auxiliary.color_palette import get_color_palette
from osgeo_utils.auxiliary.color_table import get_color_table

progress = gdal.TermProgress_nocb

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import sys

from osgeo import gdal
from osgeo.utils.auxiliary.util import GetOutputDriverFor, open_ds
from osgeo.utils.auxiliary.color_table import get_color_table
from osgeo_utils.auxiliary.util import GetOutputDriverFor, open_ds
from osgeo_utils.auxiliary.color_table import get_color_table


def Usage():
Expand Down
53 changes: 53 additions & 0 deletions gdal/swig/python/gdal-utils/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Setup script for gdal-utils.

from setuptools import setup, find_packages

__pacakge_name__ = 'gdal-utils'
__version__ = '3.3.0.1'
__author__ = "Idan Miara"
__author_email__ = "[email protected]"
__maintainer__ = "Idan Miara"
__maintainer_email__ = "[email protected]"
__description__ = "gdal-utils: An extension library for GDAL - Geospatial Data Abstraction Library"
__license_type__ = "MIT"
__url__ = "http://www.gdal.org"

classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Topic :: Scientific/Engineering :: GIS',
'Topic :: Scientific/Engineering :: Information Analysis',
]

__readme__ = str(open('README.rst', 'rb').read())

package_root = '.' # package sources are under this dir
packages = find_packages(package_root)
package_dir = {'': package_root}

setup(
name=__pacakge_name__,
version=__version__,
author=__author__,
author_email=__author_email__,
maintainer=__maintainer__,
maintainer_email=__maintainer_email__,
long_description=__readme__,
long_description_content_type='text/x-rst',
description=__description__,
license=__license_type__,
classifiers=classifiers,
url=__url__,
python_requires='>=3.6.0',
packages=packages,
package_dir=package_dir,
install_requires=['gdal'],
extras_require={'numpy': ['numpy > 1.0.0']},
)

23 changes: 12 additions & 11 deletions gdal/swig/python/osgeo/gdal.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,21 @@ class _object:


have_warned = 0
def deprecation_warn(module, sub_package=None):
global have_warned
def deprecation_warn(module, sub_package=None, new_module=None):
global have_warned

if have_warned == 1:
return
if have_warned == 1:
return

have_warned = 1
if sub_package:
new_module = sub_package+'.'+module
else:
new_module = module
have_warned = 1
if sub_package is None or sub_package == 'utils':
sub_package = 'osgeo_utils'
if new_module is None:
new_module = module
new_module = '{}.{}'.format(sub_package, new_module)

from warnings import warn
warn('%s.py was placed in a namespace, it is now available as osgeo.%s' % (module, new_module),
from warnings import warn
warn('{}.py was placed in a namespace, it is now available as {}' .format(module, new_module),
DeprecationWarning)


Expand Down
3 changes: 3 additions & 0 deletions gdal/swig/python/osgeo/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
raise ImportError("Please use `import osgeo_utils` (GDAL >= 3.3) "
"instead of `import osgeo.utils` (GDAL == 3.2). "
"For more details see GDAL RFC #78")
2 changes: 1 addition & 1 deletion gdal/swig/python/samples/tile_extent_from_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import sys
from osgeo import gdal, ogr
from osgeo.utils.auxiliary.util import GetOutputDriverFor
from osgeo_utils.auxiliary.util import GetOutputDriverFor


def Usage():
Expand Down
8 changes: 4 additions & 4 deletions gdal/swig/python/scripts/epsg_tr.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3

import sys
# import osgeo.utils.epsg_tr as a convenience to use as a script
from osgeo.utils.epsg_tr import * # noqa
from osgeo.utils.epsg_tr import main
# import osgeo_utils.epsg_tr as a convenience to use as a script
from osgeo_utils.epsg_tr import * # noqa
from osgeo_utils.epsg_tr import main
from osgeo.gdal import deprecation_warn


deprecation_warn('epsg_tr', 'utils')
deprecation_warn('epsg_tr')
sys.exit(main(sys.argv))
8 changes: 4 additions & 4 deletions gdal/swig/python/scripts/esri2wkt.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3

import sys
# import osgeo.utils.esri2wkt as a convenience to use as a script
from osgeo.utils.esri2wkt import * # noqa
from osgeo.utils.esri2wkt import main
# import osgeo_utils.esri2wkt as a convenience to use as a script
from osgeo_utils.esri2wkt import * # noqa
from osgeo_utils.esri2wkt import main
from osgeo.gdal import deprecation_warn


deprecation_warn('esri2wkt', 'utils')
deprecation_warn('esri2wkt')
sys.exit(main(sys.argv))
8 changes: 4 additions & 4 deletions gdal/swig/python/scripts/gcps2vec.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3

import sys
# import osgeo.utils.gcps2vec as a convenience to use as a script
from osgeo.utils.gcps2vec import * # noqa
from osgeo.utils.gcps2vec import main
# import osgeo_utils.gcps2vec as a convenience to use as a script
from osgeo_utils.gcps2vec import * # noqa
from osgeo_utils.gcps2vec import main
from osgeo.gdal import deprecation_warn


deprecation_warn('gcps2vec', 'utils')
deprecation_warn('gcps2vec')
sys.exit(main(sys.argv))
8 changes: 4 additions & 4 deletions gdal/swig/python/scripts/gcps2wld.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3

import sys
# import osgeo.utils.gcps2wld as a convenience to use as a script
from osgeo.utils.gcps2wld import * # noqa
from osgeo.utils.gcps2wld import main
# import osgeo_utils.gcps2wld as a convenience to use as a script
from osgeo_utils.gcps2wld import * # noqa
from osgeo_utils.gcps2wld import main
from osgeo.gdal import deprecation_warn


deprecation_warn('gcps2wld', 'utils')
deprecation_warn('gcps2wld')
sys.exit(main(sys.argv))
Loading