This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Coordinate conversion

Tags: None
(comma "," separated)
michaeleriksen
Registered Member
Posts
1
Karma
0

Coordinate conversion

Sat Jun 22, 2013 5:28 pm
How do I draw an ellipse at a GeoDataCoordinates with a width and height in meters?

I want the width and height to be in degrees so the ellipse scales with the zoom.

So something like this

qreal xMeter = 2.0;
qreal yMeter = 2.5;

qreal meterToLon = (how do I do the conversion from meters to a lon value?)
qreal meterToLat = (how do I do the conversion from meters to a lat value?)

painter->drawEllipse(myGeoCoordinates, meterToLon, meterToLat, true);

Thanks,

Michael
kenzensberger
Registered Member
Posts
2
Karma
0

Re: Coordinate conversion

Sat Oct 12, 2013 10:06 am
Hi,

this works, minor and major values are elipse radius in Km,
centerLon and centerLat are the elipse center point coordinates,
br, konrad

// Initialize variables
qreal centerLon = 10.0;
qreal centerLat = 47.0;
qreal altitude = 0.0;

qreal width = (qreal)minor; //min radius in Km
qreal height= (qreal)major;//max radius in Km
qreal DEG2RAD = PI / 180.0;
qreal RAD2DEG = 180.0 / PI;

// Ensure a valid latitude range:
if ( centerLat + 0.5 * height > 90.0 || centerLat - 0.5 * height < -90.0 ) {
return;
}

// Don't show the ellipse if it's too small:
GeoDataLatLonBox ellipseBox( centerLat + 0.5 * height, centerLat - 0.5 * height,
centerLon + 0.5 * width, centerLon - 0.5 * width, GeoDataCoordinates::Degree );

if ( !d->m_marbleWidget->viewport()->viewLatLonAltBox().intersects( ellipseBox ) ||
!d->m_marbleWidget->viewport()->resolves( ellipseBox ) ) return;

GeoDataLineString ellipse; //the resulting ellipse
qreal lon = 0.0;
qreal lat = 0.0;

// Optimizing the precision by determining the size which the
// ellipse covers on the screen:
qreal degreeResolution = d->m_marbleWidget->viewport()->angularResolution() * RAD2DEG;

// To create a circle shape even for very small precision we require uneven numbers:
int precision = width / degreeResolution / 8 + 1;
if ( precision > 81 ) precision = 81;
precision = 180;

// Calculate the shape of the upper half of the ellipse:
for ( int i = 0; i < precision; ++i ) {
qreal t = 1.0 - 2.0 * (qreal)(i) / (qreal)(precision);
lat = centerLat + 0.5 * height * sqrt( 1.0 - t * t );
lon = centerLon + 0.5 * width * t;
ellipse << GeoDataCoordinates( lon, lat, altitude, GeoDataCoordinates::Degree );
}
// Calculate the shape of the lower half of the ellipse:
for ( int i = 0; i < precision; ++i ) {
qreal t = 2.0 * (qreal)(i) / (qreal)(precision) - 1.0;
lat = centerLat - 0.5 * height * sqrt( 1.0 - t * t );
lon = centerLon + 0.5 * width * t;
ellipse << GeoDataCoordinates( lon, lat, altitude, GeoDataCoordinates::Degree );
}


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], Evergrowing, Google [Bot], lockheed, mesutakcan, Sogou [Bot]