aboutsummaryrefslogtreecommitdiff
path: root/examples/pj_obs_api_mini_demo.c
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-04-19 22:53:31 +0200
committerEven Rouault <even.rouault@spatialys.com>2019-04-19 22:55:56 +0200
commita8080f3f17f96449a6c706bfed9ab3d7f9a75e5b (patch)
tree1edf92dac6ab584da164f52419571e45e8e1b49c /examples/pj_obs_api_mini_demo.c
parente1da8e5f6933bfb914dccb26a755a23b5ce9f36f (diff)
downloadPROJ-a8080f3f17f96449a6c706bfed9ab3d7f9a75e5b.tar.gz
PROJ-a8080f3f17f96449a6c706bfed9ab3d7f9a75e5b.zip
Doc: update quickstart with PROJ 6 API (fixes #1403)
Diffstat (limited to 'examples/pj_obs_api_mini_demo.c')
-rw-r--r--examples/pj_obs_api_mini_demo.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/examples/pj_obs_api_mini_demo.c b/examples/pj_obs_api_mini_demo.c
index 94520490..3df94e2d 100644
--- a/examples/pj_obs_api_mini_demo.c
+++ b/examples/pj_obs_api_mini_demo.c
@@ -42,23 +42,42 @@
int main (void) {
PJ_CONTEXT *C;
PJ *P;
+ PJ* P_for_GIS;
PJ_COORD a, b;
/* or you may set C=PJ_DEFAULT_CTX if you are sure you will */
/* use PJ objects from only one thread */
C = proj_context_create();
- P = proj_create (C, "+proj=utm +zone=32 +ellps=GRS80");
- if (0==P)
- return puts ("Oops"), 0;
+ P = proj_create_crs_to_crs (C,
+ "EPSG:4326",
+ "+proj=utm +zone=32 +datum=WGS84", /* or EPSG:32632 */
+ NULL);
+
+ if (0==P) {
+ fprintf(stderr, "Oops\n");
+ return 1;
+ }
+
+ /* This will ensure that the order of coordinates for the input CRS */
+ /* will be longitude, latitude, whereas EPSG:4326 mandates latitude, */
+ /* longitude */
+ P_for_GIS = proj_normalize_for_visualization(C, P);
+ if( 0 == P_for_GIS ) {
+ fprintf(stderr, "Oops\n");
+ return 1;
+ }
+ proj_destroy(P);
+ P = P_for_GIS;
/* a coordinate union representing Copenhagen: 55d N, 12d E */
- /* note: PROJ.4 works in radians, hence the proj_torad() calls */
- a = proj_coord (proj_torad(12), proj_torad(55), 0, 0);
+ /* Given that we have used proj_normalize_for_visualization(), the order of
+ /* coordinates is longitude, latitude, and values are expressed in degrees. */
+ a = proj_coord (12, 55, 0, 0);
/* transform to UTM zone 32, then back to geographical */
b = proj_trans (P, PJ_FWD, a);
- printf ("easting: %g, northing: %g\n", b.enu.e, b.enu.n);
+ printf ("easting: %.3f, northing: %.3f\n", b.enu.e, b.enu.n);
b = proj_trans (P, PJ_INV, b);
printf ("longitude: %g, latitude: %g\n", b.lp.lam, b.lp.phi);