Skip to content

Instantly share code, notes, and snippets.

@pramsey pramsey/proj.c
Last active Feb 16, 2019

Embed
What would you like to do?
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#include <math.h>
#include <regex.h>
#include "/usr/local/include/proj.h"
static void print_coord(PJ_COORD *c)
{
printf("COORD %g %g\n", c->xyzt.x, c->xyzt.y);
}
int main(int argc, char **argv)
{
PJ_COORD pj_coord_src, pj_coord_dst;
double x = -126;
double y = 45;
PJ *pj = proj_create_crs_to_crs(NULL, "EPSG:4326", "EPSG:3005", NULL);
int ango = proj_angular_output(pj, PJ_FWD);
int angi = proj_angular_input(pj, PJ_INV);
printf("transformation: %s\n", proj_as_proj_string(NULL, pj, PJ_PROJ_5, NULL));
PJ *pj_src_crs = proj_get_source_crs(NULL, pj);
PJ *pj_dst_crs = proj_get_target_crs(NULL, pj);
PJ *pj_src_cs = proj_crs_get_coordinate_system(NULL, pj_src_crs);
PJ *pj_dst_cs = proj_crs_get_coordinate_system(NULL, pj_dst_crs);
int axis_count = proj_cs_get_axis_count(NULL, pj_src_cs);
printf("axis_count = %d\n", axis_count);
for (int i = 0; i < axis_count; i++)
{
const char *out_name;
const char *out_abbrev;
const char *out_direction;
double out_unit_conv_factor;
const char *out_unit_name;
const char *out_unit_auth_name;
const char *out_unit_code;
proj_cs_get_axis_info(NULL, pj_src_cs, i,
&out_name,
&out_abbrev,
&out_direction,
&out_unit_conv_factor,
&out_unit_name,
&out_unit_auth_name,
&out_unit_code
);
printf("%s (%s) '%s' -- %s [%s:%s]\n",
out_name,
out_abbrev,
out_direction,
out_unit_name,
out_unit_auth_name,
out_unit_code
);
}
pj_coord_src = proj_coord(y, x, 0, 0);
print_coord(&pj_coord_src);
pj_coord_dst = proj_trans(pj, PJ_FWD, pj_coord_src);
int pj_errno_val = proj_errno(pj);
printf("pj_errno_val = %d\n", pj_errno_val);
print_coord(&pj_coord_dst);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.