Le 17/11/2022 à 16:01, Brendan Heberlein a écrit :
Thank you, Mike & Even.

Supposing I wanted to have the output grid origin & dimensions computed automatically, but with a specified rotation angle, is that possible?

There's no API in GDAL for it. You indeed have to set something like the following


gt[1] = cos(angle) * pixel_x_size

gt[2] = -sin(angle) * pixel_x_size

gt[4] = sin(angle) * pixel_y_size

gt[5] = cos(angle) * pixel_y_size


I assume the above only works if the origin (gt[0], gt[3]) is the lower-left corner coordinate, not the upper-one. And I might certainly have got some signs wrong :-)


Slightly related code in the ENVI driver to transform the rotation angle from its header file to a geotransform matrix (but conventions might be slightly different):

https://github.com/OSGeo/gdal/blob/66d9fe0b1a34a8992c804c2444f7f23c2436b937/frmts/raw/envidataset.cpp#L1536


Anyway I can calculate these parameters myself, so it is not a big issue. Your suggestion worked for me.

Cheers!
Brendan

------------------------------------------------------------------------
*From:* Even Rouault <even.roua...@spatialys.com>
*Sent:* Saturday, November 5, 2022 4:36 AM
*To:* Michael Sumner <mdsum...@gmail.com>; Brendan Heberlein <bheberl...@wisc.edu>
*Cc:* gdal-dev <gdal-dev@lists.osgeo.org>
*Subject:* Re: [gdal-dev] Specify Grid Rotation for gdal.Warp() with Geolocation Arrays


Le 05/11/2022 à 04:33, Michael Sumner a écrit :
yes I see, well you can probably set a target GeoTIFF with the geotransform that you want - and gdalwarp to that as the target.

something like

out_ds = gdal.GetDriverByName("GTiff").Create("output.tif", width, height, number_of_bands, data_type, options = ["TILED=YES"])

out_ds.SetGeoTransform([ some geotransform with rotational terms ])

srs = osr.SpatialReference()

srs.ImportFromEPSG( xxx ) / srs.ImportFromWkt( xxx )

out_ds.SetSpatialRef( srs )

gdal.Warp(out_ds, src_ds, .... )



I don't believe you can do that with gdalwarp directly, and I have no idea with python - and finally I'm sorry to add irrelevant discussion - but this is interesting and I'm going to try it out in R and C++ and would love to see a python example too.

Cheers, Mike





On Sat, Nov 5, 2022 at 2:21 PM Brendan Heberlein <bheberl...@wisc.edu <mailto:bheberl...@wisc.edu>> wrote:

    Hi Mike,

    regardless of the map projection, it may be desirable to have the
    grid oriented in one direction or another, e.g. due to the
    spatial distribution of data points. Although the CRS/SRS
    designates the coordinate axes, these are not always aligned with
    the desired grid orientation.

    So, basically I want to be able to specify an arbitrary
    geotransform array for the output grid. This would allow the grid
    to be assigned an arbitrary orientation within the CRS frame.

    Thanks,
    Brendan
    ------------------------------------------------------------------------
    *From:* Michael Sumner <mdsum...@gmail.com
    <mailto:mdsum...@gmail.com>>
    *Sent:* Friday, November 4, 2022 6:57 PM
    *To:* Brendan Heberlein <bheberl...@wisc.edu
    <mailto:bheberl...@wisc.edu>>
    *Cc:* gdal-dev <gdal-dev@lists.osgeo.org
    <mailto:gdal-dev@lists.osgeo.org>>
    *Subject:* Re: [gdal-dev] Specify Grid Rotation for gdal.Warp()
    with Geolocation Arrays
    well, the map projection does this - there are many
    possibilities. Or, do you have another geolocation array you want
    as the target?

    If you have an example I'm happy to try a few things, but I'd
    assumed you had a target map projection in mind. What kind of crs
    to choose depends on your goal, or is purely to not have north up?

    Perhaps there's something terminology wise I'm missing ...

    Mike

    On Sat, 5 Nov 2022, 10:50 Brendan Heberlein, <bheberl...@wisc.edu
    <mailto:bheberl...@wisc.edu>> wrote:

        Hi Mike,

        thanks for the response.

        Can you clarify how I would go about specifying the grid
        orientation for the output raster? None of -te, -ts or -t_srs
        address this.


        ------------------------------------------------------------------------
        *From:* Michael Sumner <mdsum...@gmail.com
        <mailto:mdsum...@gmail.com>>
        *Sent:* Friday, November 4, 2022 6:41 PM
        *To:* Brendan Heberlein <bheberl...@wisc.edu
        <mailto:bheberl...@wisc.edu>>
        *Cc:* gdal-dev <gdal-dev@lists.osgeo.org
        <mailto:gdal-dev@lists.osgeo.org>>
        *Subject:* Re: [gdal-dev] Specify Grid Rotation for
        gdal.Warp() with Geolocation Arrays
        that's exactly what the warper does with geolocation arrays,
        set the target extent, dimension, and crs with -te, -ts,
        -t_srs with gdalwarp.

        python will have those analogous controls for the warper.

        Cheers, Mike



        On Sat, 5 Nov 2022, 01:23 Brendan Heberlein via gdal-dev,
        <gdal-dev@lists.osgeo.org <mailto:gdal-dev@lists.osgeo.org>>
        wrote:

            Hello,

            I would like to be able to warp an image dataset using a
            geolocation array, while specifying the grid to which the
            output dataset is sampled. Specifically, I want to be
            able to warp the dataset to a grid which is not oriented
            North-up.

            Can GDAL support this currently? Or, what is the
            likelihood this could be supported in the future?

            I primarily rely on the Python bindings, so a solution
            within that framework would be ideal for me.

            Thanks!
                 — Brendan


            _______________________________________________
            gdal-dev mailing list
            gdal-dev@lists.osgeo.org <mailto:gdal-dev@lists.osgeo.org>
            https://lists.osgeo.org/mailman/listinfo/gdal-dev
            <https://lists.osgeo.org/mailman/listinfo/gdal-dev>



--
Michael Sumner
Software and Database Engineer
Australian Antarctic Division
Hobart, Australia
e-mail: mdsum...@gmail.com <mailto:mdsum...@gmail.com>

_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org  <mailto:gdal-dev@lists.osgeo.org>
https://lists.osgeo.org/mailman/listinfo/gdal-dev  
<https://lists.osgeo.org/mailman/listinfo/gdal-dev>
--
http://www.spatialys.com  <http://www.spatialys.com>
My software is free, but my time generally not.

--
http://www.spatialys.com
My software is free, but my time generally not.
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to