Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

asc2hasc fails with rasters with CRS EPSG:4326 and/or with non-square pixels #36

@arkanoid87

Description

@arkanoid87

With the following image I get "numpy.linalg.linalg.LinAlgError: Matrix is singular" error

Driver: GTiff/GeoTIFF                                                                                                                                                                                                                          
Files: sagama20160824_ros.tif                                                                                                                                                                                                                  
       sagama20160824_ros.tif.aux.xml                                                                                                                                                                                                          
Size is 139, 115                                                                                                                                                                                                                               
Coordinate System is:                                                                                                                                                                                                                          
GEOGCS["WGS 84",                                                                                                                                                                                                                               
    DATUM["WGS_1984",                                                                                                                                                                                                                          
        SPHEROID["WGS 84",6378137,298.257223563,                                                                                                                                                                                               
            AUTHORITY["EPSG","7030"]],                                                                                                                                                                                                         
        AUTHORITY["EPSG","6326"]],                                                                                                                                                                                                             
    PRIMEM["Greenwich",0],                                                                                                                                                                                                                     
    UNIT["degree",0.0174532925199433],                                                                                                                                                                                                         
    AUTHORITY["EPSG","4326"]]                                                                                                                                                                                                                  
Origin = (8.520520469873661,40.293932069181139)                                                                                                                                                                                                
Pixel Size = (0.000898315284120,-0.000898315284120)                                                                                                                                                                                            
Metadata:                                                                                                                                                                                                                                      
  AREA_OR_POINT=Area                                                                                                                                                                                                                           
Image Structure Metadata:                                                                                                                                                                                                                      
  COMPRESSION=LZW                                                                                                                                                                                                                              
  INTERLEAVE=PIXEL                                                                                                                                                                                                                             
Corner Coordinates:                                                                                                                                                                                                                            
Upper Left  (   8.5205205,  40.2939321) (  8d31'13.87"E, 40d17'38.16"N)                                                                                                                                                                        
Lower Left  (   8.5205205,  40.1906258) (  8d31'13.87"E, 40d11'26.25"N)                                                                                                                                                                        
Upper Right (   8.6453863,  40.2939321) (  8d38'43.39"E, 40d17'38.16"N)                                                                                                                                                                        
Lower Right (   8.6453863,  40.1906258) (  8d38'43.39"E, 40d11'26.25"N)                                                                                                                                                                        
Center      (   8.5829534,  40.2422789) (  8d34'58.63"E, 40d14'32.20"N)   
 Input square cell area    : 8.069703494680006e-07
 Hexagon cell area         : 9.151043762967126e-07
 Hexagon side length       : 0.0005934844889809739
 Hexagon perpendicular     : 0.0005139726442095491
 Number of rows in mesh    : 101
 Number of columns in mesh : 141

Converting with Multi-quadratic interpolation ...
/usr/lib/python3/dist-packages/scipy/linalg/basic.py:223: RuntimeWarning: scipy.linalg.solve
Ill-conditioned matrix detected. Result is not guaranteed to be accurate.
Reciprocal condition number: 9.251858537656306e-18
  ' condition number: {}'.format(rcond), RuntimeWarning)
Traceback (most recent call last):
  File "/usr/local/bin/asc2hasc", line 7, in <module>
    from hex_utils.asc2hasc import main
  File "/usr/local/lib/python3.6/dist-packages/hex_utils/asc2hasc.py", line 109, in <module>
    main()
  File "/usr/local/lib/python3.6/dist-packages/hex_utils/asc2hasc.py", line 100, in main
    hexRaster.set(i, j, interpol(x, y))
  File "/usr/local/lib/python3.6/dist-packages/hex_utils/asc.py", line 137, in interpolMultiquadratic
    f = interpolate.Rbf(xx, yy, vals, epsilon=epsilon)
  File "/usr/lib/python3/dist-packages/scipy/interpolate/rbf.py", line 222, in __init__
    self.nodes = linalg.solve(self.A, self.di)
  File "/usr/lib/python3/dist-packages/scipy/linalg/basic.py", line 219, in solve
    raise LinAlgError('Matrix is singular.')
numpy.linalg.linalg.LinAlgError: Matrix is singular.

With the following image (that is the EPSG:32632 reprojection of the one above) I have "TypeError: '<=' not supported between instances of 'NoneType' and 'int'" error

Driver: GTiff/GeoTIFF                                                                                                                                                                                                                          
Files: sagama20160824_ros_32632.tif                                                                                                                                                                                                            
Size is 139, 116                                                                                                                                                                                                                               
Coordinate System is:                                                                                                                                                                                                                          
PROJCS["WGS 84 / UTM zone 32N",                                                                                                                                                                                                                
    GEOGCS["WGS 84",                                                                                                                                                                                                                           
        DATUM["WGS_1984",                                                                                                                                                                                                                      
            SPHEROID["WGS 84",6378137,298.257223563,                                                                                                                                                                                           
                AUTHORITY["EPSG","7030"]],                                                                                                                                                                                                     
            AUTHORITY["EPSG","6326"]],                                                                                                                                                                                                         
        PRIMEM["Greenwich",0,                                                                                                                                                                                                                  
            AUTHORITY["EPSG","8901"]],                                                                                                                                                                                                         
        UNIT["degree",0.0174532925199433,                                                                                                                                                                                                      
            AUTHORITY["EPSG","9122"]],                                                                                                                                                                                                         
        AUTHORITY["EPSG","4326"]],                                                                                                                                                                                                             
    PROJECTION["Transverse_Mercator"],                                                                                                                                                                                                         
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",9],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["Easting",EAST],
    AXIS["Northing",NORTH],
    AUTHORITY["EPSG","32632"]]
Origin = (459185.728300000017043,4460491.910400000400841)
Pixel Size = (76.796454676259017,-99.279828448282103)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (  459185.728, 4460491.910) (  8d31'11.25"E, 40d17'38.14"N)
Lower Left  (  459185.728, 4448975.450) (  8d31'13.89"E, 40d11'24.63"N)
Upper Right (  469860.436, 4460491.910) (  8d38'43.38"E, 40d17'39.78"N)
Lower Right (  469860.436, 4448975.450) (  8d38'45.33"E, 40d11'26.26"N)
Center      (  464523.082, 4454733.680) (  8d34'58.46"E, 40d14'32.27"N)
Error, malformed file. Expected cellsize but read dx
Traceback (most recent call last):
  File "/usr/local/bin/asc2hasc", line 7, in <module>
    from hex_utils.asc2hasc import main
  File "/usr/local/lib/python3.6/dist-packages/hex_utils/asc2hasc.py", line 109, in <module>
    main()
  File "/usr/local/lib/python3.6/dist-packages/hex_utils/asc2hasc.py", line 56, in main
    esriGrid.loadFromFile(args.inputFile)
  File "/usr/local/lib/python3.6/dist-packages/hex_utils/raster.py", line 86, in loadFromFile
    self._loadHeader()
  File "/usr/local/lib/python3.6/dist-packages/hex_utils/asc.py", line 148, in _loadHeader
    self._set_size( self._loadHeaderLine(self._file.readline(), self._key_size,   type(1.0)))
  File "/usr/local/lib/python3.6/dist-packages/hex_utils/asc.py", line 36, in _set_size
    if (size <= 0):
TypeError: '<=' not supported between instances of 'NoneType' and 'int'

I have to reproject the EPSG:4326 image into a map projection like EPSG:32632 and then warp it to make square pixels to be able to run asc2hasc with both interpolations successfully.

I've used:
gdalwarp -tr 10.0 -10.0 -r bilinear sagama20160824_ros_32632.tif sagama20160824_ros_32632_squared.tif

Driver: GTiff/GeoTIFF                                                                                                                                                                                                                          
Files: sagama20160824_ros_32632_squared.tif                                                                                                                                                                                                    
Size is 1067, 1154                                                                                                                                                                                                                             
Coordinate System is:                                                                                                                                                                                                                          
PROJCS["WGS 84 / UTM zone 32N",                                                                                                                                                                                                                
    GEOGCS["WGS 84",                                                                                                                                                                                                                           
        DATUM["WGS_1984",                                                                                                                                                                                                                      
            SPHEROID["WGS 84",6378137,298.257223563,                                                                                                                                                                                           
                AUTHORITY["EPSG","7030"]],                                                                                                                                                                                                     
            AUTHORITY["EPSG","6326"]],                                                                                                                                                                                                         
        PRIMEM["Greenwich",0,                                                                                                                                                                                                                  
            AUTHORITY["EPSG","8901"]],                                                                                                                                                                                                         
        UNIT["degree",0.0174532925199433,                                                                                                                                                                                                      
            AUTHORITY["EPSG","9122"]],                                                                                                                                                                                                         
        AUTHORITY["EPSG","4326"]],                                                                                                                                                                                                             
    PROJECTION["Transverse_Mercator"],                                                                                                                                                                                                         
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",9],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["Easting",EAST],
    AXIS["Northing",NORTH],
    AUTHORITY["EPSG","32632"]]
Origin = (459185.728300000017043,4460491.910400000400841)
Pixel Size = (10.000000000000000,-10.000000000000000)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (  459185.728, 4460491.910) (  8d31'11.25"E, 40d17'38.14"N)
Lower Left  (  459185.728, 4448951.910) (  8d31'13.89"E, 40d11'23.87"N)
Upper Right (  469855.728, 4460491.910) (  8d38'43.18"E, 40d17'39.78"N)
Lower Right (  469855.728, 4448951.910) (  8d38'45.13"E, 40d11'25.49"N)
Center      (  464520.728, 4454721.910) (  8d34'58.36"E, 40d14'31.88"N)
Geometries:                                                                                                                                                                                                                                    
 Input square cell area    : 100.0                                                                                                                                                                                                             
 Hexagon cell area         : 113.39999999999999                                                                                                                                                                                                
 Hexagon side length       : 6.606639111585838                                                                                                                                                                                                 
 Hexagon perpendicular     : 5.72151730426919                                                                                                                                                                                                  
 Number of rows in mesh    : 1009                                                                                                                                                                                                              
 Number of columns in mesh : 1077                                                                                                                                                                                                              
                                                                                                                                                                                                                                               
Converting with Multi-quadratic interpolation ...                                                                                                                                                                                              
Finished successfully.                                                                                                                                                                                                                          

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions