Пример #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);
}
Пример #2
0
RDateTime& RDateTime::toLocalTime(void)
{
    if( dt_type == DATETIME_UTC ) {
        struct tm   tm0, *tm1;
        time_t      tt0;

        toTM(&tm0);

        tt0 = time_utc(&tm0);
        tt0 = tt0 + timeZone*3600;
        tm1 = gmtime(&tt0);

        year  = tm1->tm_year + 1900;
        month = tm1->tm_mon  + 1;
        day   = tm1->tm_mday;

        hour = tm1->tm_hour;
        min  = tm1->tm_min;
        sec  = tm1->tm_sec;

        dt_type = DATETIME_LOCAL;
    }

    return *this;
}
Пример #3
0
RDateTime& RDateTime::toUTC(void)
{
    if( dt_type == DATETIME_LOCAL ) {
        struct tm   tm0, *tm1;
        time_t      tt0;

        toTM(&tm0);

        // get second from 1970/1/1 and convert to UTC
        tt0 = time_utc(&tm0);
        tt0 = tt0 - timeZone*3600;
        tm1 = gmtime(&tt0);

        year  = tm1->tm_year + 1900;
        month = tm1->tm_mon  + 1;
        day   = tm1->tm_mday;

        hour = tm1->tm_hour;
        min  = tm1->tm_min;
        sec  = tm1->tm_sec;

        dt_type = DATETIME_UTC;
    }

    return *this;
}
Пример #4
0
double RDateTime::diffTime(RDateTime &t0)
{
    struct tm   tm0, tm1;
    time_t      tt0, tt1;
    double      dt;

    if( dt_type == t0.dt_type ) {
        t0.toTM(&tm0);
    } else {
        RDateTime t = t0;

        if( t0.dt_type == DATETIME_LOCAL ) {
            t.toUTC().toTM(&tm0);
        }
        if( t0.dt_type == DATETIME_UTC ) {
            t.toLocalTime().toTM(&tm0);
        }
    }

    toTM(&tm1);

    tt0 = time_utc(&tm0);
    tt1 = time_utc(&tm1);
    dt  = difftime(tt1, tt0);

    if( t0.nano_sec > nano_sec ) {
        dt = dt - 1.0 + 1.0*(t0.nano_sec - nano_sec)/1.0e9;
    } else {
        dt = dt + 1.0*(nano_sec - t0.nano_sec)/1.0e9;
    }

    return dt;
}
Пример #5
0
const ri64 RDateTime::toTime_t(void) const
{
    ri64        t;
    struct tm   tm;

    // get seconds since 1970/1/1
    toTM(&tm);
    t = time_utc(&tm);

    if( dt_type == DATETIME_LOCAL )
        t = t - timeZone*3600;

    return t;
}
Пример #6
0
const ri64 RDateTime::toTimeStamp(void) const
{
    ri64        t, ts;
    struct tm   tm;

    // get seconds since 1970/1/1
    toTM(&tm);
    t = time_utc(&tm);

    if( dt_type == DATETIME_LOCAL )
        t = t - timeZone*3600;

    ts = t*1000000 + nano_sec/1000;

    return ts;
}
Пример #7
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;
}
Пример #8
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;
}
Пример #9
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);
}