question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
dazza-codescommented, Dec 5, 2019

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.

1reaction
elfmanryancommented, 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`
Read more comments on GitHub >

github_iconTop Results From Across the Web

GDAL reprojection error: in method 'Geometry_Transform ...
python - GDAL reprojection error: in method 'Geometry_Transform', argument 2 of type 'OSRCoordinateTransformationShadow *' - Stack Overflow. ...
Read more >
GDAL driver.Create() TypeError for datatype argument
You have several issues. One of them is by using '~/Desktop/arr.tif' as your destination path. It should be 'Desktop/arr.tif'.
Read more >
in method 'Dataset_GetRasterBand', argument 2 of type 'int'
[gdal-dev] TypeError: in method 'Dataset_GetRasterBand', argument 2 of type 'int'. Vincent Schut schut at sarvision.nl
Read more >
[gdal-dev] transform point problem using gdal 1.5 with osr
return int((lon + 180) / 6) + 1 ... SpatialReference() utm = osr.SpatialReference() ... TypeError: in method 'Geometry_Transform', argument 2 of type
Read more >
Re: [gdal-dev] TypeError Wrong number or type of arguments ...
Re: [gdal-dev] TypeError Wrong number or type of arguments for overloaded function ... ImportFromEPSG(int(proj_type)) > t = osgeo.osr.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found