[Proj] Coming releases of PROJ.4

Roger Bivand Roger.Bivand at nhh.no
Fri Jun 23 01:02:19 PDT 2017


The listing for the R rgdal package is:

#include <projects.h> 

Was used until access to share/proj files was provided, 
needed for rgdal (and sf below) to check for proj metadata files 
on package install.

Is still used in the essential function by Barry Rowlingson:

#include <projects.h>

int inversetest(PJ *P){
  return (P->inv ? 1: 0);

}

test for the existence of an inverse, see also examples in:

https://r-forge.r-project.org/scm/viewvc.php/pkg/man/project.Rd?view=markup&root=rgdal

getPROJ4VersionInfo()
projs <- as.character(projInfo()$name)
res <- logical(length(projs))
names(res) <- projs
msgs <- character(length(projs))
names(msgs) <- projs
owarn <- options("warn")$warn
options(warn=2L)
for (i in seq(along=res)) {
  iprs <- paste("+proj=", projs[i], sep="")
  xy <- try(project(cbind(0, 0), iprs, legacy=TRUE), silent=TRUE)
  if (class(xy) == "try-error") {
    res[i] <- NA
    msgs[i] <- paste("fwd:", strsplit(xy, "\n")[[1]][2])
  } else {
    out <- try(project(xy, iprs, inv=TRUE, legacy=TRUE), silent=TRUE)
    if (class(out) == "try-error") {
      res[i] <- NA
      msgs[i] <- paste("inv:", strsplit(out, "\n")[[1]][2])
    } else res[i] <- isTRUE(all.equal(cbind(0,0), out))
  }
}
options(warn=owarn)

The problem is that pj_inv() hard fails when an inverse is attempted and
none exists, so we need protection to avoid crashing the R session:

  if ( inversetest(pj) == 0) {
    pj_free(pj);
    error("No inverse for this projection");
  };


The effective usage is:

#include <proj_api.h>

pj_ctx_fclose
pj_ctx_fgets
pj_free
pj_fwd
pj_get_datums_ref
pj_get_def
pj_get_default_ctx
pj_get_ellps_ref
pj_get_errno_ref
pj_get_list_ref
pj_get_release
pj_get_units_ref
pj_init_plus
pj_inv
pj_is_latlong
pj_open_lib
pj_strerrno
pj_transform

for R package proj4:

#include <proj_api.h>

pj_free
pj_fwd
pj_get_errno_ref
pj_init_plus
pj_inv
pj_strerrno
pj_transform

and for R package sf:

#include <proj_api.h>

pj_ctx_fclose
pj_free
pj_get_datums_ref
pj_get_def
pj_get_default_ctx
pj_get_ellps_ref
pj_get_errno_ref
pj_get_list_ref
pj_get_units_ref
pj_init_plus
pj_init_plus
pj_open_lib
pj_open_lib
pj_strerrno

here with CPL_transform() used for projection through the GDAL -> Proj4
dependence.

Roger



-----
Roger Bivand
NHH Norwegian School of Economics, Bergen, Norway
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Coming-releases-of-PROJ-4-tp5325216p5325292.html
Sent from the PROJ.4 mailing list archive at Nabble.com.



More information about the Proj mailing list