source: subversion/applications/utils/export/osm2pgsql/reprojection.c @ 3210

Last change on this file since 3210 was 2827, checked in by jonb, 13 years ago

osm2pgsql - make experimental version current, move previous implementation to legacy

File size: 976 bytes
Line 
1/* reprojection.c
2 *
3 * Convert OSM lattitude / longitude from degrees to mercator
4 * so that Mapnik does not have to project the data again
5 *
6 */
7
8#include <stdio.h>
9#include <unistd.h>
10#include <proj_api.h>
11
12static projPJ pj_ll, pj_merc;
13
14void project_init(void)
15{
16        pj_ll   = pj_init_plus("+proj=latlong +ellps=GRS80 +no_defs");
17        pj_merc = pj_init_plus("+proj=merc +datum=WGS84  +k=1.0 +units=m +over +no_defs");
18                       
19        if (!pj_ll || !pj_merc) {
20                fprintf(stderr, "Projection code failed to initialise\n");
21                exit(1);
22        }
23}
24
25void project_exit(void)
26{
27        pj_free(pj_ll);
28        pj_ll = NULL;
29        pj_free(pj_merc);
30        pj_merc = NULL;
31}
32
33void reproject(double *lat, double *lon)
34{
35        double x[1], y[1], z[1];
36        //projUV p, q;
37        //p.u = *lat * DEG_TO_RAD;
38        //p.v = *lon * DEG_TO_RAD;
39
40        x[0] = *lon * DEG_TO_RAD;
41        y[0] = *lat * DEG_TO_RAD;
42        z[0] = 0;
43       
44        pj_transform(pj_ll, pj_merc, 1, 1, x, y, z);
45       
46        //printf("%.4f\t%.4f -> %.4f\t%.4f\n", *lat, *lon, y[0], x[0]);
47        *lat = y[0];
48        *lon = x[0];
49}
50
Note: See TracBrowser for help on using the repository browser.