2021年2月3日水曜日

Proj4 C++ 座標変換忘備録

Proj4 ver 6.3.1 で座標変換するコードの習作
#include <proj.h>
#include <iostream>

int main() {

  PJ_CONTEXT* C;
  PJ*         P;
  PJ*         P_for_GIS;

  C = proj_context_create();
  P = proj_create_crs_to_crs( C, "EPSG:3857", "EPSG:6679", NULL );
  if( !P ) {
    std::cerr << "Fail to create proj crs conversion" << std::endl;
    return 1;
  }
  P_for_GIS = proj_normalize_for_visualization(C,P);
  if( !P_for_GIS ) {
    std::cerr << "Fail to normalize proj" << std::endl;
    return 1;
  }
  proj_destroy(P);
  P = P_for_GIS;
  
  PJ_COORD sp = proj_coord(15734773.4,5323579.9,0,0);
  
  PJ_COORD dp = proj_trans(P, PJ_FWD, sp);
  std::cout << std::fixed << sp.v[0] << "," << sp.v[1] << std::endl;
  std::cout << " to ";
  std::cout << dp.v[0] << "," << dp.v[1] << std::endl;
  
  proj_destroy(P);
  proj_context_destroy(C);
  
  return 0;
}
参考: https://github.com/OSGeo/PROJ/blob/master/examples/pj_obs_api_mini_demo.c

0 件のコメント: