[PROJ] Affine transformation using DERIVEDPROJCRS
Even Rouault
even.rouault at spatialys.com
Mon Jul 4 02:40:16 PDT 2022
Le 04/07/2022 à 11:00, Bart via PROJ a écrit :
>
> Greetings all,
>
> Working with QGIS, I am in need of developing a ‘custom CRS’ with its
> own origin and orientation.
>
> Basically I need a CRS that is DERIVED from a PROJCRS, resulting in a
> *DERIVEDPROJCRS*.
>
> I have done some work to that extent, that can be seen at the
> following spreadsheet on GitHub:
>
> https://github.com/Duijndam-Dev/TopoLib/blob/master/TopoLib/Samples/DerivedProjectedCrsTests.xlsb
>
> Right now, I do this by hacking a WKT2 string, based on various
> examples found on the internet.
>
> https://gis.stackexchange.com/questions/353022/defining-a-coordinate-system-in-wkt-or-proj-format-that-has-an-affine-transforma
>
>
> https://gis.stackexchange.com/questions/350228/define-custom-projection-in-qgis-from-some-control-points
>
>
> https://gis.stackexchange.com/questions/408406/qgis-custom-projection-in-wkt-not-saving-prj-file
>
>
> https://gis.stackexchange.com/questions/366578/custom-crs-for-historic-site-grid
>
>
> https://gis.stackexchange.com/questions/408683/custom-derived-crs-by-affine-transformation-from-epsg32633-setting-as-layer-cr
>
>
> Doing the required affine transform is relatively straightforward.
> What is more of a concern is creating a WKT2 string to setup the
> DERIVEDPROJCRS.
>
> In particular, I would like to preserve the USAGE definition and BBOX
> field. Any closing ID field needs to be removed, as it is no longer valid.
>
> But the process of editing a WKT2 string is rather error prone. It is
> not something you’d like a ‘novice’ having to do.
>
> Now, the fact is that proj supports affine transforms since v6.0.0.
> See:
> https://proj.org/operations/transformations/affine.html?highlight=affine+transformation#
>
> Finally, to come to my question: would it be possible to define the
> following workflow in C++ code:
>
> 1. Create a projected CRS object (from EPSG code, or a WKT string)
> 2. Apply an affine transformation on this CRS
> 3. Export the modified CRS as a WKT string
>
> This automation would avoid any manual editing of the WKT2 string.
>
There's definitely everything needed in PROJ C++ API to do that.
The main entry point would be the DerivedProjectedCRS::create() method:
https://github.com/OSGeo/PROJ/blob/master/include/proj/crs.hpp#L1266
There's an example of its usage in
https://github.com/OSGeo/PROJ/blob/a390c57ab5998154535d7ffbc7de04aad2a73910/test/unit/test_crs.cpp#L5493
In this example, the creation of the conversion is rather dummy. A more
interesting example is at
https://github.com/OSGeo/PROJ/blob/a390c57ab5998154535d7ffbc7de04aad2a73910/test/unit/test_crs.cpp#L5164
Creation of the base CRS from a EPSG code:
https://github.com/OSGeo/PROJ/blob/a390c57ab5998154535d7ffbc7de04aad2a73910/test/unit/test_crs.cpp#L1225
Export of a CRS as WKT:
https://github.com/OSGeo/PROJ/blob/a390c57ab5998154535d7ffbc7de04aad2a73910/test/unit/test_crs.cpp#L2047
Even
> Maybe - if this isn’t the best approach - are any other ways
> conceivable to achieve my goal ?
>
> Much appreciate your advice.
>
> Bart Duijndam <mailto:Bart.Duijndam at ziggo.nl>
>
> Geoscience consultant
>
> www.duijndam.dev <http://www.duijndam.dev/>
>
>
> _______________________________________________
> PROJ mailing list
> PROJ at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/proj
--
http://www.spatialys.com
My software is free, but my time generally not.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/proj/attachments/20220704/5bb70854/attachment-0001.htm>
More information about the PROJ
mailing list