Ejemplo n.º 1
1
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);
}
Ejemplo n.º 2
0
void ViewPort::GetLLFromPix( const wxPoint &p, double *lat, double *lon )
{
    int dx = p.x - ( pix_width / 2 );
    int dy = ( pix_height / 2 ) - p.y;

    double xpr = dx;
    double ypr = dy;

    //    Apply VP Rotation
    double angle = rotation;
    if(!g_bskew_comp)
        angle += skew;

    if( angle ) {
        xpr = ( dx * cos( angle ) ) - ( dy * sin( angle ) );
        ypr = ( dy * cos( angle ) ) + ( dx * sin( angle ) );
    }
    double d_east = xpr / view_scale_ppm;
    double d_north = ypr / view_scale_ppm;

    double slat, slon;
    if( PROJECTION_TRANSVERSE_MERCATOR == m_projection_type ) {
        double tmceasting, tmcnorthing;
        toTM( clat, clon, 0., clon, &tmceasting, &tmcnorthing );

        fromTM( d_east, d_north + tmcnorthing, 0., clon, &slat, &slon );
    } else if( PROJECTION_POLYCONIC == m_projection_type ) {
        double polyeasting, polynorthing;
        toPOLY( clat, clon, 0., clon, &polyeasting, &polynorthing );

        fromPOLY( d_east, d_north + polynorthing, 0., clon, &slat, &slon );
    }

    //TODO  This could be fromSM_ECC to better match some Raster charts
    //      However, it seems that cm93 (and S57) prefer no eccentricity correction
    //      Think about it....
    else
        fromSM( d_east, d_north, clat, clon, &slat, &slon );

    *lat = slat;

    if( slon < -180. ) slon += 360.;
    else if( slon > 180. ) slon -= 360.;
    *lon = slon;
}
Ejemplo n.º 3
0
void ViewPort::GetLLFromPix( const wxPoint2DDouble &p, double *lat, double *lon )
{
    double dx = p.m_x - ( pix_width / 2.0 );
    double dy = ( pix_height / 2.0 ) - p.m_y;

    double xpr = dx;
    double ypr = dy;

    //    Apply VP Rotation
    double angle = rotation;

    if( angle ) {
        xpr = ( dx * cos( angle ) ) - ( dy * sin( angle ) );
        ypr = ( dy * cos( angle ) ) + ( dx * sin( angle ) );
    }
    double d_east = xpr / view_scale_ppm;
    double d_north = ypr / view_scale_ppm;

    double slat = 0.0, slon = 0.0;
    switch( m_projection_type ) {
    case PROJECTION_MERCATOR:
        //TODO  This could be fromSM_ECC to better match some Raster charts
        //      However, it seems that cm93 (and S57) prefer no eccentricity correction
        //      Think about it....
        fromSM( d_east, d_north, clat, clon, &slat, &slon );
        break;

    case PROJECTION_TRANSVERSE_MERCATOR:
    {
        double tmceasting, tmcnorthing;
        toTM( clat, clon, 0., clon, &tmceasting, &tmcnorthing );

        fromTM( d_east, d_north + tmcnorthing, 0., clon, &slat, &slon );
    }
    break;

    case PROJECTION_POLYCONIC:
    {
        double polyeasting, polynorthing;
        toPOLY( clat, clon, 0., clon, &polyeasting, &polynorthing );

        fromPOLY( d_east, d_north + polynorthing, 0., clon, &slat, &slon );
    }
    break;

    case PROJECTION_ORTHOGRAPHIC:
        fromORTHO( d_east, d_north, clat, clon, &slat, &slon );
        break;

    case PROJECTION_POLAR:
        fromPOLAR( d_east, d_north, clat, clon, &slat, &slon );
        break;

    case PROJECTION_STEREOGRAPHIC:
        fromSTEREO( d_east, d_north, clat, clon, &slat, &slon );
        break;

    case PROJECTION_GNOMONIC:
        fromGNO( d_east, d_north, clat, clon, &slat, &slon );
        break;

    case PROJECTION_EQUIRECTANGULAR:
        fromEQUIRECT( d_east, d_north, clat, clon, &slat, &slon );
        break;

    default:
        printf("unhandled projection\n");
    }

    *lat = slat;

    if( slon < -180. ) slon += 360.;
    else if( slon > 180. ) slon -= 360.;
    *lon = slon;
}
Ejemplo n.º 4
0
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);
}