wxPoint2DDouble ViewPort::GetDoublePixFromLL( double lat, double lon ) { double easting = 0; double northing = 0; double xlon = lon; /* Make sure lon and lon0 are same phase */ if( xlon * clon < 0. ) { if( xlon < 0. ) xlon += 360.; else xlon -= 360.; } if( fabs( xlon - clon ) > 180. ) { if( xlon > clon ) xlon -= 360.; else xlon += 360.; } // update cache of trig functions used for projections if(clat != lat0_cache) { lat0_cache = clat; switch( m_projection_type ) { case PROJECTION_MERCATOR: cache0 = toSMcache_y30(clat); break; case PROJECTION_POLAR: cache0 = toPOLARcache_e(clat); break; case PROJECTION_ORTHOGRAPHIC: case PROJECTION_STEREOGRAPHIC: case PROJECTION_GNOMONIC: cache_phi0(clat, &cache0, &cache1); break; } } switch( m_projection_type ) { case PROJECTION_MERCATOR: #if 0 toSM( lat, xlon, clat, clon, &easting, &northing ); #else toSMcache( lat, xlon, cache0, clon, &easting, &northing ); #endif break; case PROJECTION_TRANSVERSE_MERCATOR: // We calculate northings as referenced to the equator // And eastings as though the projection point is midscreen. double tmeasting, tmnorthing; double tmceasting, tmcnorthing; toTM( clat, clon, 0., clon, &tmceasting, &tmcnorthing ); toTM( lat, xlon, 0., clon, &tmeasting, &tmnorthing ); northing = tmnorthing - tmcnorthing; easting = tmeasting - tmceasting; break; case PROJECTION_POLYCONIC: // We calculate northings as referenced to the equator // And eastings as though the projection point is midscreen. double pceasting, pcnorthing; toPOLY( clat, clon, 0., clon, &pceasting, &pcnorthing ); double peasting, pnorthing; toPOLY( lat, xlon, 0., clon, &peasting, &pnorthing ); easting = peasting; northing = pnorthing - pcnorthing; break; case PROJECTION_ORTHOGRAPHIC: toORTHO( lat, xlon, cache0, cache1, clon, &easting, &northing ); break; case PROJECTION_POLAR: toPOLAR( lat, xlon, cache0, clat, clon, &easting, &northing ); break; case PROJECTION_STEREOGRAPHIC: toSTEREO( lat, xlon, cache0, cache1, clon, &easting, &northing ); break; case PROJECTION_GNOMONIC: toGNO( lat, xlon, cache0, cache1, clon, &easting, &northing ); break; case PROJECTION_EQUIRECTANGULAR: toEQUIRECT( lat, xlon, clat, clon, &easting, &northing ); break; default: printf("unhandled projection\n"); } if( !wxFinite(easting) || !wxFinite(northing) ) return wxPoint2DDouble( easting, northing ); double epix = easting * view_scale_ppm; double npix = northing * view_scale_ppm; double dxr = epix; double dyr = npix; // Apply VP Rotation double angle = rotation; if( angle ) { dxr = epix * cos( angle ) + npix * sin( angle ); dyr = npix * cos( angle ) - epix * sin( angle ); } return wxPoint2DDouble(( pix_width / 2.0 ) + dxr, ( pix_height / 2.0 ) - dyr); }
wxPoint2DDouble ViewPort::GetDoublePixFromLL( double lat, double lon ) { double easting, northing; double xlon = lon; /* Make sure lon and lon0 are same phase */ if( xlon * clon < 0. ) { if( xlon < 0. ) xlon += 360.; else xlon -= 360.; } if( fabs( xlon - clon ) > 180. ) { if( xlon > clon ) xlon -= 360.; else xlon += 360.; } if( PROJECTION_TRANSVERSE_MERCATOR == m_projection_type ) { // We calculate northings as referenced to the equator // And eastings as though the projection point is midscreen. double tmeasting, tmnorthing; double tmceasting, tmcnorthing; toTM( clat, clon, 0., clon, &tmceasting, &tmcnorthing ); toTM( lat, xlon, 0., clon, &tmeasting, &tmnorthing ); northing = tmnorthing - tmcnorthing; easting = tmeasting - tmceasting; } else if( PROJECTION_POLYCONIC == m_projection_type ) { // We calculate northings as referenced to the equator // And eastings as though the projection point is midscreen. double pceasting, pcnorthing; toPOLY( clat, clon, 0., clon, &pceasting, &pcnorthing ); double peasting, pnorthing; toPOLY( lat, xlon, 0., clon, &peasting, &pnorthing ); easting = peasting; northing = pnorthing - pcnorthing; } else { #if 0 toSM( lat, xlon, clat, clon, &easting, &northing ); #else if(clat != toSM_lat0_cache) { toSM_lat0_cache = clat; toSM_y30_cache = toSMcache_y30(clat); } toSMcache( lat, xlon, toSM_y30_cache, clon, &easting, &northing ); #endif } if( !wxFinite(easting) || !wxFinite(northing) ) return wxPoint( 0, 0 ); double epix = easting * view_scale_ppm; double npix = northing * view_scale_ppm; double dxr = epix; double dyr = npix; // Apply VP Rotation double angle = rotation; if(!g_bskew_comp) angle += skew; if( angle ) { dxr = epix * cos( angle ) + npix * sin( angle ); dyr = npix * cos( angle ) - epix * sin( angle ); } return wxPoint2DDouble(( pix_width / 2 ) + dxr, ( pix_height / 2 ) - dyr); }