utmproj.h
上传用户:lbr_007
上传日期:2019-05-31
资源大小:282k
文件大小:2k
- // utmproj.h
- //
- #ifndef UTM_H_
- #define UTM_H_
- #include <geo.h>
- #include <projects.h>
- #include <proj_api.h>
- class UTMProjection {
- protected:
- PJ * m_pj;
- public:
- UTMProjection(void)
- {
- m_pj = 0;
- }
- ~UTMProjection(void)
- {
- if (m_pj)
- {
- pj_free(m_pj);
- }
- m_pj = 0;
- }
- void forward(double lat, double lon, double& x, double& y)
- {
- if (m_pj)
- {
- projUV sUV;
- sUV.u = lon * GEO::DE2RA;
- sUV.v = lat * GEO::DE2RA;
- sUV = pj_fwd( sUV, m_pj );
- x = (int)(sUV.u + 0.50);
- y = (int)(sUV.v + 0.50);
- }
- }
- void inverse(double x, double y, double& lat, double& lon)
- {
- if (m_pj)
- {
- projUV sUV;
- sUV.u = x;
- sUV.v = y;
- sUV = pj_inv( sUV, m_pj );
- lon = sUV.u * GEO::RA2DE;
- lat = sUV.v * GEO::RA2DE;
- }
- }
- void setup(INT32 zone, const char * ellps = 0)
- {
- if (m_pj)
- {
- pj_free(m_pj);
- }
- char pjData[4][24];
- char * pjPtrs[4];
-
- strcpy(pjData[0],"proj=utm");
- sprintf(pjData[1],"zone=%d",zone);
- if (ellps)
- {
- strcpy(pjData[2],"ellps=");
- strcat(pjData[2],ellps);
- }
- else
- {
- strcpy(pjData[2],"ellps=WGS84");
- }
- strcpy(pjData[3],"units=m");
-
- pjPtrs[0] = pjData[0];
- pjPtrs[1] = pjData[1];
- pjPtrs[2] = pjData[2];
- pjPtrs[3] = pjData[3];
-
- m_pj = pj_init(4,pjPtrs);
- }
- void DD2DMS(double ll, INT32& degrees, INT32& minutes, double& seconds)
- {
- double dd = ll;
- degrees = (int)(double)(long)fabs(dd);
- double mm = (double)((fabs(dd) - degrees)*60.0);
- minutes = (int)mm;
- seconds = (double)((mm - (double)(long)(minutes))*60.0);
- if (seconds >= 60.00)
- {
- if (minutes == 59)
- {
- if (degrees < 0.0)
- degrees -= 1;
- else
- degrees += 1;
- minutes = 0;
- seconds -= 60.0;
- }
- else
- {
- seconds -= 60.00;
- minutes += 1;
- }
- }
- }
- };
- #endif