[Qgis-developer] MapCanvas->mapRenderer->distanceArea->bearing
Returns a NaN
Oscar De Leon
oleongomez at gmail.com
Tue Dec 15 12:38:12 EST 2009
Hello everybody:
I'm working in a simple application that shows the bearing and distance from
a reference point to the cursor position, but when I'm trying to calcute
them, distanceArea of MapRenderer returns a NaN
I've checked the configuration of mapcanvas and every thing looks fine. This
is a chunk of code where I do the configuration:
QString fileName = "config.xml";
configMgt = new ConfigMgt(fileName, this);
QgsProviderRegistry::instance(configMgt->sPluginDir);
QgsApplication::setPkgDataPath(configMgt->sPkgDir);
QgsApplication::setPrefixPath(configMgt->sPkgDir);
// Add Map Canvas
mpMapCanvas = new QgsMapCanvas(0, 0);
mpMapCanvas->enableAntiAliasing(true);
mpMapCanvas->useImageToRender(false);
mpMapCanvas->freeze(false);
mpMapCanvas->setVisible(true);
mpMapCanvas->refresh();
mpMapCanvas->show();
ui.Layout->addWidget(mpMapCanvas);
crs = new QgsCoordinateReferenceSystem(3344,
QgsCoordinateReferenceSystem::InternalCrsId);
And this is the code where I show the Result
QString sLat(QVariant(getDegreesY(pos)).toString() + QChar(0xB0)+
QVariant(getMinutesY(pos)).toString());
sLat.append(pos.y() < 0 ? " S" : " N");
this->ui.lbCursorPosLat->setText(sLat);
QString sLon(QVariant(getDegreesX(pos)).toString() + QChar(0xB0)+
QVariant(getMinutesX(pos)).toString());
sLon.append(pos.x() < 0 ? " W" : " E");
this->ui.lbCursorPosLon->setText(sLon);
//Calculo de RNG y BRG
QgsDistanceArea *daDistancia =new QgsDistanceArea();
daDistancia=mpMapCanvas->mapRenderer()->distanceArea();
daDistancia->setProjectionsEnabled(false);
QString * sRNG = new QString();
QgsPoint *uno=new QgsPoint();
QgsPoint *dos=new QgsPoint();
uno->setX(pos.x());
uno->setY(pos.y());
dos->setX(ptReference.x());
dos->setY(ptReference.y());
sRNG->setNum(toNM(daDistancia->measureLine(*uno, *dos)), 10, 0);
this->ui.laLat->setText(*sRNG + " NM");
QString * sBRG = new QString();
double dDeg =
RAD2DEG(/*daDistancia*/mpMapCanvas->mapRenderer()->distanceArea()->bearing(ptReference,pos));
dDeg = dDeg > 0 ? dDeg : 360 + dDeg;
dDeg = dDeg > dCorrectionReference ? dDeg - dCorrectionReference :
360 - dCorrectionReference + dDeg;
sBRG->setNum(dDeg, 10, 1);
this->ui.laLon->setText(*sBRG + " " + QChar(0xB0));
Thank you for your help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20091215/0ca821df/attachment.html
More information about the Qgis-developer
mailing list