Skip to content

Commit

Permalink
** Fixed feature addition in GPX layers, it now works again
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@2352 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
larsl committed Nov 27, 2004
1 parent 86d1a1f commit 79ca0c6
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 8 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Expand Up @@ -3,6 +3,9 @@ QGIS Change Log
------------------------------------------------------------------------------
Version 0.6 'Simon' .... development version

2004-11-27 [larsl] 0.5.0devel30
** Fixed feature addition in GPX layers, it now works again

2004-11-22 [mcoletti] 0.5.0devel29
** QgsProject properties now re-designed to be similar to QSettings

Expand Down
2 changes: 1 addition & 1 deletion configure.in
Expand Up @@ -26,7 +26,7 @@ dnl ---------------------------------------------------------------------------
MAJOR_VERSION=0
MINOR_VERSION=5
MICRO_VERSION=0
EXTRA_VERSION=29
EXTRA_VERSION=30
if test $EXTRA_VERSION -eq 0; then
VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}
else
Expand Down
2 changes: 1 addition & 1 deletion providers/gpx/gpsdata.h
Expand Up @@ -216,7 +216,7 @@ class GPSData {
static void releaseData(const QString& filename);


/** operator<< is our friend. */
/** operator<< is our friend. For debugging, not for file I/O. */
friend std::ostream& operator<<(std::ostream& os, const GPSData& d);

protected:
Expand Down
166 changes: 161 additions & 5 deletions providers/gpx/qgsgpxprovider.cpp
Expand Up @@ -44,9 +44,9 @@
#endif


const char* QgsGPXProvider::attr[] = { "Name", "Elevation", "Symbol", "Number",
"Comment", "Description", "Source",
"URL", "URL name" };
const char* QgsGPXProvider::attr[] = { "name", "elevation", "symbol", "number",
"comment", "description", "source",
"url", "url name" };


QgsGPXProvider::QgsGPXProvider(QString uri) : mDataSourceUri(uri),
Expand Down Expand Up @@ -78,7 +78,7 @@ QgsGPXProvider::QgsGPXProvider(QString uri) : mDataSourceUri(uri),
else if (mFeatureType == RouteType || mFeatureType == TrackType) {
mGeomType = 2;
for (int i = 0; i < 8; ++i)
mAllAttributes.push_back(7);
mAllAttributes.push_back(i);
attributeFields.push_back(QgsField(attr[NumAttr], "text"));
}
attributeFields.push_back(QgsField(attr[CmtAttr], "text"));
Expand Down Expand Up @@ -532,17 +532,173 @@ bool QgsGPXProvider::isValid(){


bool QgsGPXProvider::addFeatures(std::list<QgsFeature*> flist) {

// add all the features
for (std::list<QgsFeature*>::const_iterator iter = flist.begin();
iter != flist.end(); ++iter) {
if (!addFeature(*iter))
return false;
}

// write back to file
QDomDocument qdd;
data->fillDom(qdd);
QFile file(mFileName);
if (!file.open(IO_WriteOnly))
return false;
QTextStream ostr(&file);
ostr<<qdd.toString();
return true;
}


bool QgsGPXProvider::addFeature(QgsFeature* f) {
return false;
unsigned char* geo = f->getGeometry();
int featureId;
bool success = false;
GPSObject* obj = NULL;
const std::vector<QgsFeatureAttribute>& attrs(f->attributeMap());

// is it a waypoint?
if (mFeatureType == WaypointType && geo != NULL && geo[1] == 1) {

// add geometry
Waypoint wpt;
std::memcpy(&wpt.lon, geo+5, sizeof(double));
std::memcpy(&wpt.lat, geo+13, sizeof(double));

// add waypoint-specific attributes
for (int i = 0; i < attrs.size(); ++i) {
if (attrs[i].fieldName() == attr[EleAttr]) {
bool eleIsOK;
double ele = attrs[i].fieldValue().toDouble(&eleIsOK);
if (eleIsOK)
wpt.ele = ele;
}
else if (attrs[i].fieldName() == attr[SymAttr]) {
wpt.sym = attrs[i].fieldValue();
}
}

featureId = data->addWaypoint(wpt);
success = true;
obj = &(data->getWaypoint(featureId));
}

// is it a route?
if (mFeatureType == RouteType && geo != NULL && geo[1] == 2) {

Route rte;

// reset bounds
rte.xMin = std::numeric_limits<double>::max();
rte.xMax = -std::numeric_limits<double>::max();
rte.yMin = std::numeric_limits<double>::max();
rte.yMax = -std::numeric_limits<double>::max();

// add geometry
int nPoints;
std::memcpy(&nPoints, geo + 5, 4);
for (int i = 0; i < nPoints; ++i) {
double lat, lon;
std::memcpy(&lon, geo + 9 + 16 * i, sizeof(double));
std::memcpy(&lat, geo + 9 + 16 * i + 8, sizeof(double));
Routepoint rtept;
rtept.lat = lat;
rtept.lon = lon;
rte.points.push_back(rtept);
rte.xMin = rte.xMin < lon ? rte.xMin : lon;
rte.xMax = rte.xMax > lon ? rte.xMax : lon;
rte.yMin = rte.yMin < lat ? rte.yMin : lat;
rte.yMax = rte.yMax > lat ? rte.yMax : lat;
}

// add route-specific attributes
for (int i = 0; i < attrs.size(); ++i) {
if (attrs[i].fieldName() == attr[NumAttr]) {
bool numIsOK;
long num = attrs[i].fieldValue().toLong(&numIsOK);
if (numIsOK)
rte.number = num;
}
}

featureId = data->addRoute(rte);
success = true;
obj = &(data->getRoute(featureId));
}

// is it a track?
if (mFeatureType == TrackType && geo != NULL && geo[1] == 2) {

Track trk;
TrackSegment trkseg;

// reset bounds
trk.xMin = std::numeric_limits<double>::max();
trk.xMax = -std::numeric_limits<double>::max();
trk.yMin = std::numeric_limits<double>::max();
trk.yMax = -std::numeric_limits<double>::max();

// add geometry
int nPoints;
std::memcpy(&nPoints, geo + 5, 4);
for (int i = 0; i < nPoints; ++i) {
double lat, lon;
std::memcpy(&lon, geo + 9 + 16 * i, sizeof(double));
std::memcpy(&lat, geo + 9 + 16 * i + 8, sizeof(double));
Trackpoint trkpt;
trkpt.lat = lat;
trkpt.lon = lon;
trkseg.points.push_back(trkpt);
trk.xMin = trk.xMin < lon ? trk.xMin : lon;
trk.xMax = trk.xMax > lon ? trk.xMax : lon;
trk.yMin = trk.yMin < lat ? trk.yMin : lat;
trk.yMax = trk.yMax > lat ? trk.yMax : lat;
}

// add track-specific attributes
for (int i = 0; i < attrs.size(); ++i) {
if (attrs[i].fieldName() == attr[NumAttr]) {
bool numIsOK;
long num = attrs[i].fieldValue().toLong(&numIsOK);
if (numIsOK)
trk.number = num;
}
}

trk.segments.push_back(trkseg);
featureId = data->addTrack(trk);
success = true;
obj = &(data->getTrack(featureId));
}


// add common attributes
if (obj) {
for (int i = 0; i < attrs.size(); ++i) {
if (attrs[i].fieldName() == attr[NameAttr]) {
obj->name = attrs[i].fieldValue();
}
else if (attrs[i].fieldName() == attr[CmtAttr]) {
obj->cmt = attrs[i].fieldValue();
}
else if (attrs[i].fieldName() == attr[DscAttr]) {
obj->desc = attrs[i].fieldValue();
}
else if (attrs[i].fieldName() == attr[SrcAttr]) {
obj->src = attrs[i].fieldValue();
}
else if (attrs[i].fieldName() == attr[URLAttr]) {
obj->url = attrs[i].fieldValue();
}
else if (attrs[i].fieldName() == attr[URLNameAttr]) {
obj->urlname = attrs[i].fieldValue();
}
}
}

return success;
}


Expand Down
2 changes: 1 addition & 1 deletion providers/gpx/qgsgpxprovider.h
Expand Up @@ -148,7 +148,7 @@ class QgsGPXProvider : public QgsVectorDataProvider {
*/
bool boundsCheck(double x, double y);

bool supportsFeatureAddition(){return false;}
bool supportsFeatureAddition(){return true;}

private:

Expand Down

0 comments on commit 79ca0c6

Please sign in to comment.