north-road / qgis-processing-r

QGIS Processing R Provider Plugin
https://north-road.github.io/qgis-processing-r/
GNU General Public License v3.0
63 stars 14 forks source link

CRS parameter as WKT #98

Closed gavg712 closed 2 years ago

gavg712 commented 2 years ago

Consider the following script example:

##Demo=group
##testthat=name
##Testing CRS input=display_name
##Point=point
##CRS=crs
##Point_reproj=output vector
Point_reproj <- st_transform(Point, crs = CRS)

If the crs input is a "User defined CRS", then the parameter setting in the R script will be "USER:...". This is a useless string for CRS transformations within a R session:

For instance, using this inputs...

{'Point' : '-78.513938,-0.218095 [EPSG:4326]', 
 'CRS' : QgsCoordinateReferenceSystem('USER:100001'), 
 'Point_reproj' : 'TEMPORARY_OUTPUT' }

...the algorithm will set in R

 ======== test data settings========
point_crs <- st_crs('GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]')
Point <- st_sfc(st_point(c(-78.513938,-0.218095)), crs = point_crs)
CRS <- "USER:100001"
=============================

If this CRS object is used, an error will occur. The sf and sp functions will not find a way to handle the string "USER:100001"

======= Testing CRS string ========
Point CRS Transform
Error in CPL_transform(x, crs, aoi, pipeline, reverse, desired_accuracy, :
crs not found: is it missing?
Calls: st_transform ... st_transform.sfc -> st_sfc -> structure -> CPL_transform

Is there any reason to set authid instead of WKT or Proj4string in the crs parameter in R?