Add:Core:Initial coding for map datum conversion
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 14 Apr 2008 14:41:17 +0000 (14:41 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 14 Apr 2008 14:41:17 +0000 (14:41 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1009 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/src/coord.h
navit/src/projection.h
navit/src/transform.c

index d2fcda9..62c45f5 100644 (file)
@@ -32,6 +32,13 @@ struct coord_geo {
        double lat; /*!< Latitude */
 };
 
+//! A cartesian coordinate 
+struct coord_geo_cart {
+       double x; /*!< X-Value */
+       double y; /*!< Y-Value */
+       double z; /*!< Z-Value */
+};
+
 enum projection;
 
 struct coord * coord_get(unsigned char **p);
index 12f46ba..bad3a48 100644 (file)
@@ -5,6 +5,10 @@ enum projection {
        projection_none, projection_mg, projection_garmin
 };
 
+enum map_datum {
+       map_datum_none, map_datum_wgs84, map_datum_dhdn
+};
+
 enum projection projection_from_name(const char *name);
 char * projection_to_name(enum projection proj);
 
index 52d6618..0abe6fb 100644 (file)
@@ -78,6 +78,41 @@ transform_from_to(struct coord *cfrom, enum projection from, struct coord *cto,
        transform_from_geo(to, &g, cto);
 }
 
+void
+transform_geo_to_cart(struct coord_geo *geo, double a, double b, struct coord_geo_cart *cart)
+{
+       double n,ee=1-b*b/(a*a);
+       n = a/sqrt(1-ee*sin(geo->lat)*sin(geo->lat));
+        cart->x=n*cos(geo->lat)*cos(geo->lng);
+        cart->y=n*cos(geo->lat)*sin(geo->lng);
+        cart->z=n*(1-ee)*sin(geo->lat);
+}
+
+void
+transform_cart_to_geo(struct coord_geo_cart *cart, double a, double b, struct coord_geo *geo)
+{
+       double lat,lati,n,ee=1-b*b/(a*a), lng = atan(cart->y/cart->x);
+
+        lat = atan(cart->z / sqrt((cart->x * cart->x) + (cart->y * cart->y)));
+        do
+        {
+                lati = lat;
+
+                n = a / sqrt(1-ee*sin(lat)*sin(lat));
+                lat = atan((cart->z + ee * n * sin(lat)) / sqrt(cart->x * cart->x + cart->y * cart->y));
+        }
+        while (fabs(lat - lati) >= 0.000000000000001);
+
+       geo->lng=lng/M_PI*180;
+       geo->lat=lat/M_PI*180;
+}
+
+
+void
+transform_datum(struct coord_geo *from, enum map_datum from_datum, struct coord_geo *to, enum map_datum to_datum)
+{
+}
+
 int
 transform(struct transformation *t, enum projection pro, struct coord *c, struct point *p, int count, int unique)
 {