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

TypeError: in method 'SpatialReference_ImportFromEPSG', argument 2 of type 'int' #30

Open
ryanjkelly opened this issue Sep 5, 2019 · 8 comments

Comments

@ryanjkelly
Copy link

I'm trying to convert the TIFFs from the FAA's VFR Raster Charts page and I'm getting this error:

Traceback (most recent call last):
  File "/usr/local/bin/gdal2mbtiles", line 11, in <module>
    load_entry_point('gdal2mbtiles==2.1.1', 'console_scripts', 'gdal2mbtiles')()
  File "/home/ryan/.local/lib/python2.7/site-packages/gdal2mbtiles/main.py", line 309, in main
    colors=colors, band=band)
  File "/home/ryan/.local/lib/python2.7/site-packages/gdal2mbtiles/helpers.py", line 194, in warp_mbtiles
    validate_resolutions(resolution=dataset.GetNativeResolution(),
  File "/home/ryan/.local/lib/python2.7/site-packages/gdal2mbtiles/gdal.py", line 497, in GetNativeResolution
    dst_ref = self.GetSpatialReference()
  File "/home/ryan/.local/lib/python2.7/site-packages/gdal2mbtiles/gdal.py", line 463, in GetSpatialReference
    sr = sr.FromEPSG(sr.GetEPSGCode())
  File "/home/ryan/.local/lib/python2.7/site-packages/gdal2mbtiles/gdal.py", line 799, in FromEPSG
    s.ImportFromEPSG(code)
  File "/home/ryan/.local/lib/python2.7/site-packages/osgeo/osr.py", line 1138, in ImportFromEPSG
    return _osr.SpatialReference_ImportFromEPSG(self, *args)
TypeError: in method 'SpatialReference_ImportFromEPSG', argument 2 of type 'int'

Here is the output from gdalinfo -noct test.tif:

Driver: GTiff/GeoTIFF
Files: test.tif
Size is 17921, 12358
Coordinate System is:
PROJCS["Lambert Conformal Conic",
    GEOGCS["NAD83",
        DATUM["North_American_Datum_1983",
            SPHEROID["GRS 1980",6378137,298.2572221010042,
                AUTHORITY["EPSG","7019"]],
            AUTHORITY["EPSG","6269"]],
        PRIMEM["Greenwich",0],
        UNIT["degree",0.0174532925199433],
        AUTHORITY["EPSG","4269"]],
    PROJECTION["Lambert_Conformal_Conic_2SP"],
    PARAMETER["standard_parallel_1",46.66666666666666],
    PARAMETER["standard_parallel_2",41.33333333333334],
    PARAMETER["latitude_of_origin",42.3],
    PARAMETER["central_meridian",-97],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]]]
Origin = (-411171.578339697443880,257040.430107307882281)
Pixel Size = (42.335440573740584,-42.334973725198978)
Metadata:
  AREA_OR_POINT=Area
  TIFFTAG_DATETIME=2019:06:21 12:39:53
  TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
  TIFFTAG_SOFTWARE=Adobe Photoshop CS5.1 Windows
  TIFFTAG_XRESOLUTION=300
  TIFFTAG_YRESOLUTION=300
Image Structure Metadata:
  COMPRESSION=LZW
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  ( -411171.578,  257040.430) (102d10'43.70"W, 44d29'57.95"N)
Lower Left  ( -411171.578, -266135.175) (101d47'45.50"W, 39d47'47.93"N)
Upper Right (  347521.852,  257040.430) ( 92d37'16.44"W, 44d31'57.52"N)
Lower Right (  347521.852, -266135.175) ( 92d56'42.51"W, 39d49'38.48"N)
Center      (  -31824.863,   -4547.373) ( 97d23' 9.33"W, 42d15'30.11"N)
Band 1 Block=17921x1 Type=Byte, ColorInterp=Palette
  Color Table (RGB with 256 entries)

I'm using:

Ubuntu 18.04
Python 2.7.15+
pip 9.0.1
gdal2mbtiles 2.1.1
GDAL 2.4.2
@dazza-codes
Copy link

dazza-codes commented Oct 30, 2019

@rebkwok - is any maintainer able to fix this soon? Is there any WIP/PR to address it?

The gdal2mbtiles utility is not compatible with gdal 3.x yet.

OK versions in a docker image with conda/pip packages installed on Ubuntu 18.04:

$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.3 LTS"
$ python --version
Python 3.7.3
$ gdalinfo --version
GDAL 2.4.2, released 2019/06/28
$ which gdalinfo
/opt/conda/bin/gdalinfo
$ python --version
Python 3.7.3
$ which python
/opt/conda/bin/python
$ pip freeze | grep gdal
gdal2mbtiles==2.1.1

Failure versions on a laptop VM running Ubuntu 18.04 with conda/pip packages installed:

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.3 LTS"
$ python --version
Python 3.7.3
$ which python
/opt/conda/envs/gis/bin/python
$ gdalinfo --version
GDAL 3.0.1, released 2019/06/28
$ which gdalinfo
/opt/conda/envs/gis/bin/gdalinfo
$ pip freeze | grep gdal
gdal2mbtiles==2.1.1

@damon-rand
Copy link
Contributor

@darrenleeweber Not sure when we will get to addressing this particular issue. PRs accepted.

@dazza-codes
Copy link

dazza-codes commented Nov 23, 2019

@damon-rand - I'm not likely to work on this until it's essential to upgrade to a new version of GDAL and even then I'm not likely to work on it, as I have no experience with developing this project. If the contributors who develop this project have abandoned it, that would be good to know (and also why it is abandoned).

@damon-rand
Copy link
Contributor

@darrenleeweber Nothing has been abandoned. We welcome and merge community contributions and our own. We just have other, more pressing, priorities than this one.

@dazza-codes
Copy link

I suggest this issue is marked as a bug when using GDAL 3.x and the priority to fix bugs should be high enough for core project developers to attend to it.

@tomowatt
Copy link

tomowatt commented Dec 6, 2019

    def GetEPSGCode(self):
        epsg_string = self.GetEPSGString()
        if epsg_string:
            return int(epsg_string.split(':')[1])
        else:
            # HACK: The following is to cope with the fact that the Wkt
            #       representation of the Web Mercator is different for
            #       ESRI's WKID 102100 and EPSG's 3857 while both are
            #       equivalent. Yet, Proj4 does not understand ESRI's
            #       'mercator_auxiliary_sphere' projection name.
            projcs_name = self.GetAttrValue(str('PROJCS'))
            # Returning equivalent EPSG code
            if projcs_name == ESRI_102100_PROJ:
                return 3857
            elif projcs_name == ESRI_102113_PROJ:
                return 3785

So there is a bug with the Spatial Reference not being overwritten via the parameters or returning a correct Projection due to hardcoded logic which results in the issue @ryanjkelly is experiencing, we'll see if it can be corrected when possible, though community contributions are welcome.

@elfmanryan
Copy link

elfmanryan commented Dec 6, 2019

Been looking at this today aswell. going back bit earlier, when a Dataset is instantiated (helpers.py, line 193), attempts at calling the method GetSpatialReference() raises an error if the epsg is not recognised by method sr.AutoIdentifyEPSG() (gdal.py, line 458). This is true for the lambert canonical projection on the .tif above.
However we catch that error (gdal.py, line 460), and then try to instantiate another SpatialReference obj from epsg 3857 (a.k.a pseudo webmercator) (line 463) - here in lies the final error : 'argument type 2 is int' created by the method FromEPSG() (gdal.py line 798) (see below)
This method is inherited and same as calling osr.SpatialReference.FromEPSG(3857) which works. so the problem seems to be the way its inherited in our wrapper.
apologies if that was convoluted. written at end of the day in a hurry.

class SpatialReference(osr.SpatialReference):
    def __init__(self, *args, **kwargs):
        super(SpatialReference, self).__init__(*args, **kwargs)
        self._angular_transform = None

    @classmethod
    def FromEPSG(cls, code):
        s = cls()
        s.ImportFromEPSG(code) #<--------int error here
        return s`

@dazza-codes
Copy link

dazza-codes commented Jan 17, 2020

This issue is related/duplicates #28

Our team has bumped into this bug again, so now it's a blocker and I have to focus on a solution, either tracking down the bug with a quick hack-fix or finding a set of versions that work or looking closer at the CRS in our GeoTIFFs.

Using master

First, simple question - master has a few commits since the 2.1.1 release that target some CRS unit tests and possible fixes, but using master did not solve the problem. Tried using master, e.g.

# requirements.txt 
git+ssh://git@github.com/ecometrica/gdal2mbtiles.git@master#egg=gdal2mbtiles

overriding the CRS with an EPSG

Replacing the CRS (WKT) in the GeoTIFF profile with an EPSG code is a possible work around, if the CRS exactly matches an EPSG code (not always possible). But, bumped into another bug that's not specific to this issue (maybe there's another issue on this):

Traceback (most recent call last):
  File "/opt/conda/envs/gis-dataprocessing/bin/gdal2mbtiles", line 8, in <module>
    sys.exit(main())
  File "/opt/conda/envs/gis-dataprocessing/lib/python3.7/site-packages/gdal2mbtiles/main.py", line 309, in main
    colors=colors, band=band)
  File "/opt/conda/envs/gis-dataprocessing/lib/python3.7/site-packages/gdal2mbtiles/helpers.py", line 211, in warp_mbtiles
    pngdata=pngdata)
  File "/opt/conda/envs/gis-dataprocessing/lib/python3.7/site-packages/gdal2mbtiles/helpers.py", line 73, in image_mbtiles
    pyramid = preprocessor(**locals())
  File "/opt/conda/envs/gis-dataprocessing/lib/python3.7/site-packages/gdal2mbtiles/helpers.py", line 324, in resample_after_warp
    pyramid.dataset.resample(resolution=resolution)
  File "/opt/conda/envs/gis-dataprocessing/lib/python3.7/site-packages/gdal2mbtiles/vips.py", line 601, in resample
    ratios=self.GetScalingRatios(resolution=resolution, places=5)
  File "/opt/conda/envs/gis-dataprocessing/lib/python3.7/site-packages/gdal2mbtiles/vips.py", line 582, in _resample
    output_size=(dst_width, dst_height)
  File "/opt/conda/envs/gis-dataprocessing/lib/python3.7/site-packages/gdal2mbtiles/vips.py", line 392, in stretch
    interpolate='near'
  File "/opt/conda/envs/gis-dataprocessing/lib/python3.7/site-packages/gdal2mbtiles/vips.py", line 349, in _scale
    interpolate=interpolate)
  File "/opt/conda/envs/gis-dataprocessing/lib/python3.7/site-packages/gdal2mbtiles/vips.py", line 281, in affine
    image.__inputref = self.image
AttributeError: 'Image' object has no attribute '_VImageAdapter__inputref'

$ which vips
/usr/bin/vips
$ vips --version
vips-8.4.5-Wed Jan 18 12:36:44 UTC 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants