|
- //经纬度转utm坐标
- int convert_lonlat_utm(const new3s_PointXYZ &lon_lat_coord, new3s_PointXYZ &utm_coord)
- {
- OGRSpatialReference *RefSource = new OGRSpatialReference;
- RefSource->SetWellKnownGeogCS("WGS84");
-
- OGRSpatialReference *RefTarget = new OGRSpatialReference;
- RefTarget = RefSource->CloneGeogCS();
- int utmzone = lon_lat_coord.get_x() / 6 + 31;
- RefTarget->SetProjCS("UTM(WGS84) in northern hemisphere.");
- RefTarget->SetUTM(utmzone, TRUE);
- OGRCoordinateTransformation *poTransform = OGRCreateCoordinateTransformation(RefSource, RefTarget);
-
- double tempX = lon_lat_coord.get_x();
- double tempY = lon_lat_coord.get_y();
- double tempZ = lon_lat_coord.get_z();
-
- poTransform->Transform(1, &tempX, &tempY, &tempZ);
- utm_coord.set_x(tempX);
- utm_coord.set_y(tempY);
- utm_coord.set_z(tempZ);
-
- return utmzone;
- }
- //utm转经纬度
- void convert_utm_lonlat(const new3s_PointXYZ &utm_coord, const int &utmzone, new3s_PointXYZ &lon_lat_coord)
- {
- //建立投影坐标系到经纬度坐标系的转换
- OGRSpatialReference *RefSource = new OGRSpatialReference;
- RefSource->SetWellKnownGeogCS("WGS84");
- RefSource->SetProjCS("UTM(WGS84) in northern hemisphere.");
- RefSource->SetUTM(utmzone, TRUE);
- OGRSpatialReference *RefTarget = new OGRSpatialReference;
- RefTarget = RefSource->CloneGeogCS();
- OGRCoordinateTransformation *poTranform = OGRCreateCoordinateTransformation(RefSource, RefTarget);
-
- OGRPoint *poPoint = new OGRPoint();
- double tempx = utm_coord.get_x();
- double tempy = utm_coord.get_y();
- double tempz = utm_coord.get_z();
-
- poTranform->Transform(1, &tempx, &tempy, NULL);
- lon_lat_coord = new3s_PointXYZ(tempx, tempy, tempz);
- }
-
- (CGPoint)lonLat2Mercator:(CGPoint) lonLat
- {
- CGPoint mercator;
- double x = lonLat.x *20037508.34/180;
- double y = log(tan((90+lonLat.y)*M_PI/360))/(M_PI/180);
- y = y *20037508.34/180;
- mercator.x = x;
- mercator.y = y;
- return mercator ;
- }
-
- (CGPoint)Mercator2lonLat:(CGPoint) mercator
- {
- CGPoint lonLat;
- double x = mercator.x/20037508.34*180;
- double y = mercator.y/20037508.34*180;
- y= 180/M_PI*(2*atan(exp(y*M_PI/180))-M_PI/2);
- lonLat.x = x;
- lonLat.y = y;
- return lonLat;
- }
|