1

Running algorithm via window operation for output, it indulge pixel shift.

with ArcGIS projection tool

With the Code

This pixel shift is 2 rows down and 1 column right.

CODE:

def GetToUTM(Data, pixel_sz, Zone):

gdal.Open('\\myData\\asterDem.tif')
Past_ref = osr.SpatialReference()
Past_ref.ImportFromWkt(Data.GetProjectionRef())
newref = osr.SpatialReference()
newref.SetUTM(abs(Zone),Zone > 0)
transform = osr.CoordinateTransformation(Past_ref, newref)
geotransform = Data.GetGeoTransform()
nx, ny = Data.RasterXSize, Data.RasterYSize
print nx,ny
(ulx, uly, ulz) = transform.TransformPoint(geotransform[0], geotransform[3])
(lrx, lry, lrz) = transform.TransformPoint(geotransform[0]+ geotransform[1] * nx, geotransform[3] +
                                           geotransform[5] * ny)
getfile = gdal.GetDriverByName('GTiff')
dataout = getfile.Create('PyAster.tif', int((lrx-ulx)/pixel_sz), int((uly-lry)/pixel_sz), 1, gdal.GDT_Float64)
newGeoTrnsm = (ulx, pixel_sz, geotransform[2], uly, geotransform[4], -pixel_sz)
dataout.SetGeoTransform(newGeoTrnsm)
dataout.SetProjection(newref.ExportToWkt())
gdal.ReprojectImage(Data, dataout, Past_ref.ExportToWkt(), newref.ExportToWkt(), gdal.GRA_NearestNeighbour)

dataout = gdal.Open('\\untitled\\name_sake.tif')'

The Image is getting re-projected and pixel issue is resolved under my threshold.

Now that original image has value of range from 100-1211(float64), re-projected one report it from 0- 1190.43(float64) which is incorrect.

How can I make the necessary correction?

  • 2
    I suggest you edit your question to specify how you projected your raster using gdal - i.e. commandline gdalwarp, or the gdal API in a programming language like python and what exactly were your projection parameters? – user2856 Oct 31 '16 at 4:58
  • Thanks @Luke, but i have not used gdalwarp , instead called the image old reference and converted to new reference as said in point 1 of my question. I tried to project image using code but ended up in SpatialReference error so used ArcGIS to project in WGS84 (which is the old reference) and see if the other half , that is, my projection conversion script worked. – Anvesh Oct 31 '16 at 6:05
  • 1
    Your code has serious errors that make it un-runnable. Consider rewriting the code to provide a working example. – Logan Byers Oct 31 '16 at 12:30
  • @LoganByers Can you suggest some correction? – Anvesh Oct 31 '16 at 16:25
  • 1
    @Anvesh Could you provide the code to produce the result that you write about? – Logan Byers Oct 31 '16 at 16:42

Your Answer

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

Browse other questions tagged or ask your own question.