1

I don't have a clue why the conversion of a tif to an asc has that kind of behavior:

original tif metadata

Size is 466, 427
Coordinate System is:
PROJCS["ETRS89_UTM_zone_32N",
...
Origin = (-1181164.876702783396468,4539238.589259737171233)
Pixel Size = (6486.620049172968720,7717.850831012333401)
...

It's hacky to convert it into a Ascii Grid because a VRT is needed

$ gdalwarp -srcnodata -1 -dstnodata -1 -of vrt grid_tif.tif junk.vrt
$ gdal_translate -of AAIGrid junk.vrt grid_asc.asc

The resulting Ascii Grid has that metadata

Size is 427, 466
Coordinate System is:
PROJCS["ETRS89_UTM_zone_32N",
...
Origin = (-1181164.876702783396468,7834760.894102003425360)
Pixel Size = (7075.195267921446430,-7075.195267921446430)
...

The original tif is created over gdal_grid of a point shapefile in UTM32N

gdal_grid -of GTiff -zfield value -l data_points -outsize 466 427 -a "average:nodata=-1" data_points.shp grid_tif.tif
1

If you want to preserve the size of your raster, you have to specify that in the gdalwarp command line.

Otherwise gdalwarp tries an own guess, based on the average of x and y source resolution preserving the extent, leading to square raster cells. It is pure coincidence that the pixel and line values are swapped in your case.

You can force to preserve the size with:

gdalwarp -overwrite -ts 466 427 grid_tif.tif warped.tif
gdal_translate -of AAIGRID warped.tif warped.asc
gdalinfo warped.asc >warpout.txt

and you get:

Driver: AAIGrid/Arc/Info ASCII Grid
Files: warped.asc
       warped.asc.aux.xml
       warped.prj
Size is 466, 427
Coordinate System is:
PROJCS["ETRS89_UTM_zone_32N",
    GEOGCS["GCS_ETRS_1989",
        DATUM["European_Terrestrial_Reference_System_1989",
            SPHEROID["GRS_1980",6378137,298.257222101]],
        PRIMEM["Greenwich",0],
        UNIT["Degree",0.017453292519943295]],
    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["Meter",1]]
Origin = (-1181164.876702783400000,7834760.894102003400000)
Pixel Size = (6483.065191850767400,-7721.407482087573000)
Metadata:
  AREA_OR_POINT=Area
Corner Coordinates:
Upper Left  (-1181164.877, 7834760.894) ( 29d15'49.94"W, 65d45'28.20"N)
Lower Left  (-1181164.877, 4537719.899) ( 10d26' 9.65"W, 39d19'37.84"N)
Upper Right ( 1839943.503, 7834760.894) ( 41d23'31.52"E, 67d22' 2.42"N)
Lower Right ( 1839943.503, 4537719.899) ( 24d38'45.72"E, 39d55' 6.12"N)
Center      (  329389.313, 6186240.397) (  6d16'43.28"E, 55d47'29.86"N)
Band 1 Block=466x1 Type=Float32, ColorInterp=Gray

You can as well force to preserve the pixel resolution (but not both!):

gdalwarp -overwrite -tr 6486.620049172968720 7717.850831012333401 grid_tif.tif warped.tif
gdal_translate -of AAIGRID warped.tif warped.asc
gdalinfo warped.asc >warpout.txt

Which results in:

Driver: AAIGrid/Arc/Info ASCII Grid
Files: warped.asc
       warped.asc.aux.xml
       warped.prj
Size is 466, 427
Coordinate System is:
PROJCS["ETRS89_UTM_zone_32N",
    GEOGCS["GCS_ETRS_1989",
        DATUM["European_Terrestrial_Reference_System_1989",
            SPHEROID["GRS_1980",6378137,298.257222101]],
        PRIMEM["Greenwich",0],
        UNIT["Degree",0.017453292519943295]],
    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["Meter",1]]
Origin = (-1181164.876702783400000,7834760.894102003400000)
Pixel Size = (6486.620049172968700,-7717.850831012333400)
Metadata:
  AREA_OR_POINT=Area
Corner Coordinates:
Upper Left  (-1181164.877, 7834760.894) ( 29d15'49.94"W, 65d45'28.20"N)
Lower Left  (-1181164.877, 4539238.589) ( 10d26'23.03"W, 39d20'24.29"N)
Upper Right ( 1841600.066, 7834760.894) ( 41d25'26.15"E, 67d21'36.06"N)
Lower Right ( 1841600.066, 4539238.589) ( 24d40' 4.00"E, 39d55'44.24"N)
Center      (  330217.595, 6186999.742) (  6d17'29.08"E, 55d47'55.44"N)
Band 1 Block=466x1 Type=Float32, ColorInterp=Gray

which has the same size, but a little expanded extent.

Direct gdal_translating your tif to asc is not possible, because the AAIGrid driver can not handle input with south-north ordering (although this is default with gdal_grid). See my answer on gdal_translate creates images that are mirrored for more details on that.

The gdalwarp output is ordered north-south and suitable for AAIGrid.

  • I was just about to post a similar answer and was going to add that if @tee wants to use the output ascii grid in ArcGIS, it may be preferable to let gdalwarp resample the raster to a square pixel size as ArcGIS may not be able to read it otherwise. The warning that gdal_translate prints is "Producing a Golden Surfer style file with DX and DY instead of CELLSIZE since the input pixels are non-square. Use the FORCE_CELLSIZE=TRUE creation option to force use of DX for even though this will be distorted. Most ASCII Grid readers (ArcGIS included) do not support the DX and DY parameters." – user2856 Feb 5 '15 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.