[PROJ] Creating projection *not* from full init string?
Even Rouault
even.rouault at spatialys.com
Tue Mar 9 10:33:58 PST 2021
Le 09/03/2021 à 19:18, Matthew Woehlke a écrit :
> On 09/03/2021 13.04, Even Rouault wrote:
>> Le 09/03/2021 à 18:59, Matthew Woehlke a écrit :
>>> I'm trying (again) to port some geodetic conversion code from the
>>> PROJ 4 API.
>>>
>>> Our system uses EPSG identifiers to specify coordinate systems.
>>> (Yes, yes, I'm — vaguely — aware we should also be using epochs, but
>>> frankly it's a struggle to get our users to even be *aware* that
>>> there are different coordinate systems, and more often than not we
>>> have to assume 4326 because we don't know *anything*. Getting
>>> anything more is simply not practical.)
>>>
>>> This was manageable in PROJ 4. With 6.3.2, however, I can't seem to
>>> create a *usable* projection except by specifying a complete init
>>> string. Calling `proj_create(0, "EPSG:4326")` gives back a non-null
>>> pointer, but any calls to proj_trans fail, proj_info gives back an
>>> empty definition, and proj_angular_{in,out}put all return 0.
>>
>> Yes, `proj_create(0, "EPSG:4326")` creates a CRS object, not a
>> coordinate operation one. proj_trans() requires a coordinate
>> operation and will not work on a CRS. You need to use
>> proj_create_crs_to_crs() to gt an object usabled with proj_trans()
>
> Okay, I don't understand that at all.
>
> In PROJ 4, 4326 is "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84".
> If I use that with proj_create, I get something usable. What's the
> difference?
PROJ >= 6 now makes a difference between a CRS and a coordinate
operation. A PROJ string without +type=crs is assumed to be a coordinate
operation, and with +type=crs to be a CRS.
The old PROJ.4 definitions without +type=crs depending on the context
could be used as a CRS definition or a coordinate operation. PROJ >= 6
now requires to be explicit to avoid that confusion. You can't use a CRS
like "EPSG:4326" with proj_trans(). That doesn't make sense. A CRS
doesn't define a coordinate operation by itself. If you want to project
coordinates to EPSG:32631 for example, you can use the coordinate
operation returned by proj_create_crs_to_crs(ctx, "EPSG:4326",
"EPSG:32631", NULL) as an argument of proj_trans()
>
> p.s. How do I get that definition in PROJ 5? In PROJ 4, I could use
> pj_get_def. (See also https://stackoverflow.com/questions/66533885.)
Use proj_as_proj_string(). That can work on both CRS and coordinate
operation (when there's a single coordinate operation actually contained
in proj_create_crs_to_crs() )
--
http://www.spatialys.com
More information about the PROJ
mailing list