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

Registration for images with transposed GeoTransform currently works but subsequent requests fail #439

Open
Schpidi opened this issue Jan 29, 2020 · 1 comment
Assignees
Labels

Comments

@Schpidi
Copy link
Member

Schpidi commented Jan 29, 2020

Because we're always using elements 1 and 5 of the GeoTransform for the offset vector which are 0 in the case of transposed images the extent is 0 which yields an error.

Ideally we'd support serving images like this but as long as MapServer can't handle them we should fail during ingestion with a proper failure message.

@Schpidi Schpidi added the Priority: critical Level 3 label Jan 29, 2020
@Schpidi Schpidi assigned Schpidi and constantinius and unassigned Schpidi Jan 29, 2020
@lubojr
Copy link
Contributor

lubojr commented Mar 2, 2020

Or fix the image geotransform during registration:

def correct_geo_transform(src_dst):
    ulx, xres, xskew, uly, yskew, yres = src_dst.GetGeoTransform()
    # test geotransform if necessary to shift
    if xres == 0.0 and yres == 0.0:
        # malformed image, compute xres and yres switched in geotransform
        lrx = ulx + (src_dst.RasterXSize * xskew)
        lry = uly + (src_dst.RasterYSize * yskew)
        # [ulx, lrx, lry, uly] - bounds = lon_min, lon_max, lat_min, lat_max
        fp = [[0, src_dst.RasterXSize, src_dst.RasterXSize, 0], [0, 0, src_dst.RasterYSize, src_dst.RasterYSize]]
        tp = [[ulx, lrx, lrx, ulx], [lry, lry, uly, uly]]
        pix = list(zip(fp[0], fp[1]))
        coor = list(zip(tp[0], tp[1]))
        # compute the gdal.GCP parameters
        gcps = []
        for index, txt in enumerate(pix):
            gcps.append(gdal.GCP())
            gcps[index].GCPPixel = pix[index][0]
            gcps[index].GCPLine = src_dst.RasterYSize - int(pix[index][1])
            gcps[index].GCPX = coor[index][0]
            gcps[index].GCPY = coor[index][1]
        # get correct geotransform from gcps
        geotransform_new = gdal.GCPsToGeoTransform(gcps)
        # overwrite geotransform with new
        src_dst.SetGeoTransform(geotransform_new)
    return src_dst

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

No branches or pull requests

3 participants