** Implemented getNextFeature(list<int>&) in the GPX provider

git-svn-id: http://svn.osgeo.org/qgis/trunk@1434 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
larsl 2004-05-19 15:18:39 +00:00
parent 5236f77594
commit 6cad51b07f
3 changed files with 145 additions and 6 deletions

View File

@ -1,8 +1,11 @@
QGIS Change Log
ChangeLog,v 1.84 2004/05/19 06:10:24 gsherman Exp
ChangeLog,v 1.85 2004/05/19 15:18:38 larsl Exp
------------------------------------------------------------------------------
Version 0.3 'Madison' .... development version
2004-05-19 [larsl] 0.2.0devel27
** Implemented getNextFeature(list<int>&) in the GPX provider
2004-05-18 [gsherman] 0.2.0devel26
** Saved the qgsappbase.ui and the qgsprojectpropertiesbase.ui files (modified
at version 0.2.0devel25) using qt designer 3.1.2 to preserve backward

View File

@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script.
dnl configure.in,v 1.88 2004/05/19 06:10:24 gsherman Exp
dnl configure.in,v 1.89 2004/05/19 15:18:38 larsl Exp
AC_INIT
@ -24,7 +24,7 @@ dnl ---------------------------------------------------------------------------
MAJOR_VERSION=0
MINOR_VERSION=2
MICRO_VERSION=0
EXTRA_VERSION=26
EXTRA_VERSION=27
if test $EXTRA_VERSION -eq 0; then
VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}
else

View File

@ -242,11 +242,147 @@ QgsFeature *QgsGPXProvider::getNextFeature(bool fetchAttributes) {
return result;
}
QgsFeature * QgsGPXProvider::getNextFeature(std::list<int>& attlist)
{
return 0;//soon
QgsFeature * QgsGPXProvider::getNextFeature(std::list<int>& attlist) {
QgsFeature* result = 0;
std::list<int>::const_iterator iter;
if (mFeatureType == "waypoint") {
// go through the list of waypoints and return the first one that is in
// the bounds rectangle
for (; mFid < data->getNumberOfWaypoints(); ++mFid) {
const Waypoint& wpt(data->getWaypoint(mFid));
if (boundsCheck(wpt.lon, wpt.lat)) {
result = new QgsFeature(mFid);
// some wkb voodoo
char* geo = new char[21];
std::memset(geo, 0, 21);
geo[0] = endian();
geo[1] = 1;
std::memcpy(geo+5, &wpt.lon, sizeof(double));
std::memcpy(geo+13, &wpt.lat, sizeof(double));
result->setGeometry((unsigned char *)geo, sizeof(wkbPoint));
result->setValid(true);
// add attributes if they are wanted
for (iter = attlist.begin(); iter != attlist.end(); ++iter) {
switch (*iter) {
case 0:
result->addAttribute("name", wpt.name);
break;
case 1:
result->addAttribute("lat", QString("%1").arg(wpt.lat));
break;
case 2:
result->addAttribute("lon", QString("%1").arg(wpt.lon));
break;
case 3:
if (isnan(wpt.ele))
result->addAttribute("ele", "");
else
result->addAttribute("ele", QString("%1").arg(wpt.ele));
break;
case 4:
result->addAttribute("url", wpt.url);
break;
}
}
++mFid;
break;
}
}
}
else if (mFeatureType == "route") {
// go through the routes and return the first one that is in the bounds
// rectangle
for (; mFid < data->getNumberOfRoutes(); ++mFid) {
const Route& rte(data->getRoute(mFid));
if (rte.points.size() == 0)
continue;
const Routepoint& rtept(rte.points[0]);
const QgsRect& b(*mSelectionRectangle);
if ((rte.xMax >= b.xMin()) && (rte.xMin <= b.xMax()) &&
(rte.yMax >= b.yMin()) && (rte.yMin <= b.yMax())) {
result = new QgsFeature(mFid);
// some wkb voodoo
int nPoints = rte.points.size();
char* geo = new char[9 + 16 * nPoints];
std::memset(geo, 0, 9 + 16 * nPoints);
geo[0] = endian();
geo[1] = 2;
std::memcpy(geo + 5, &nPoints, 4);
for (int i = 0; i < rte.points.size(); ++i) {
std::memcpy(geo + 9 + 16 * i, &rte.points[i].lon, sizeof(double));
std::memcpy(geo + 9 + 16 * i + 8, &rte.points[i].lat, sizeof(double));
}
result->setGeometry((unsigned char *)geo, 9 + 16 * nPoints);
result->setValid(true);
// add attributes if they are wanted
for (iter = attlist.begin(); iter != attlist.end(); ++iter) {
if (*iter == 0)
result->addAttribute("name", rte.name);
else if (*iter == 1)
result->addAttribute("url", rte.url);
}
++mFid;
break;
}
}
}
else if (mFeatureType == "track") {
// go through the tracks and return the first one that is in the bounds
// rectangle
for (; mFid < data->getNumberOfTracks(); ++mFid) {
const Track& trk(data->getTrack(mFid));
if (trk.segments.size() == 0)
continue;
if (trk.segments[0].points.size() == 0)
continue;
const Trackpoint& trkpt(trk.segments[0].points[0]);
const QgsRect& b(*mSelectionRectangle);
if ((trk.xMax >= b.xMin()) && (trk.xMin <= b.xMax()) &&
(trk.yMax >= b.yMin()) && (trk.yMin <= b.yMax())) {
result = new QgsFeature(mFid);
// some wkb voodoo
int nPoints = trk.segments[0].points.size();
char* geo = new char[9 + 16 * nPoints];
std::memset(geo, 0, 9 + 16 * nPoints);
geo[0] = endian();
geo[1] = 2;
std::memcpy(geo + 5, &nPoints, 4);
for (int i = 0; i < nPoints; ++i) {
std::memcpy(geo + 9 + 16 * i, &trk.segments[0].points[i].lon, sizeof(double));
std::memcpy(geo + 9 + 16 * i + 8, &trk.segments[0].points[i].lat, sizeof(double));
}
result->setGeometry((unsigned char *)geo, 9 + 16 * nPoints);
result->setValid(true);
// add attributes if they are wanted
for (iter = attlist.begin(); iter != attlist.end(); ++iter) {
if (*iter == 0)
result->addAttribute("name", trk.name);
else if (*iter == 1)
result->addAttribute("url", trk.url);
}
++mFid;
break;
}
}
}
return result;
}
/**
* Select features based on a bounding rectangle. Features can be retrieved
* with calls to getFirstFeature and getNextFeature.