Skip to content

Commit 79ca0c6

Browse files
author
larsl
committedNov 27, 2004
** Fixed feature addition in GPX layers, it now works again
git-svn-id: http://svn.osgeo.org/qgis/trunk@2352 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 86d1a1f commit 79ca0c6

File tree

5 files changed

+167
-8
lines changed

5 files changed

+167
-8
lines changed
 

‎ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ QGIS Change Log
33
------------------------------------------------------------------------------
44
Version 0.6 'Simon' .... development version
55

6+
2004-11-27 [larsl] 0.5.0devel30
7+
** Fixed feature addition in GPX layers, it now works again
8+
69
2004-11-22 [mcoletti] 0.5.0devel29
710
** QgsProject properties now re-designed to be similar to QSettings
811

‎configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dnl ---------------------------------------------------------------------------
2626
MAJOR_VERSION=0
2727
MINOR_VERSION=5
2828
MICRO_VERSION=0
29-
EXTRA_VERSION=29
29+
EXTRA_VERSION=30
3030
if test $EXTRA_VERSION -eq 0; then
3131
VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}
3232
else

‎providers/gpx/gpsdata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class GPSData {
216216
static void releaseData(const QString& filename);
217217

218218

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

222222
protected:

‎providers/gpx/qgsgpxprovider.cpp

Lines changed: 161 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
#endif
4545

4646

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

5151

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

533533

534534
bool QgsGPXProvider::addFeatures(std::list<QgsFeature*> flist) {
535+
536+
// add all the features
535537
for (std::list<QgsFeature*>::const_iterator iter = flist.begin();
536538
iter != flist.end(); ++iter) {
537539
if (!addFeature(*iter))
538540
return false;
539541
}
542+
543+
// write back to file
544+
QDomDocument qdd;
545+
data->fillDom(qdd);
546+
QFile file(mFileName);
547+
if (!file.open(IO_WriteOnly))
548+
return false;
549+
QTextStream ostr(&file);
550+
ostr<<qdd.toString();
540551
return true;
541552
}
542553

543554

544555
bool QgsGPXProvider::addFeature(QgsFeature* f) {
545-
return false;
556+
unsigned char* geo = f->getGeometry();
557+
int featureId;
558+
bool success = false;
559+
GPSObject* obj = NULL;
560+
const std::vector<QgsFeatureAttribute>& attrs(f->attributeMap());
561+
562+
// is it a waypoint?
563+
if (mFeatureType == WaypointType && geo != NULL && geo[1] == 1) {
564+
565+
// add geometry
566+
Waypoint wpt;
567+
std::memcpy(&wpt.lon, geo+5, sizeof(double));
568+
std::memcpy(&wpt.lat, geo+13, sizeof(double));
569+
570+
// add waypoint-specific attributes
571+
for (int i = 0; i < attrs.size(); ++i) {
572+
if (attrs[i].fieldName() == attr[EleAttr]) {
573+
bool eleIsOK;
574+
double ele = attrs[i].fieldValue().toDouble(&eleIsOK);
575+
if (eleIsOK)
576+
wpt.ele = ele;
577+
}
578+
else if (attrs[i].fieldName() == attr[SymAttr]) {
579+
wpt.sym = attrs[i].fieldValue();
580+
}
581+
}
582+
583+
featureId = data->addWaypoint(wpt);
584+
success = true;
585+
obj = &(data->getWaypoint(featureId));
586+
}
587+
588+
// is it a route?
589+
if (mFeatureType == RouteType && geo != NULL && geo[1] == 2) {
590+
591+
Route rte;
592+
593+
// reset bounds
594+
rte.xMin = std::numeric_limits<double>::max();
595+
rte.xMax = -std::numeric_limits<double>::max();
596+
rte.yMin = std::numeric_limits<double>::max();
597+
rte.yMax = -std::numeric_limits<double>::max();
598+
599+
// add geometry
600+
int nPoints;
601+
std::memcpy(&nPoints, geo + 5, 4);
602+
for (int i = 0; i < nPoints; ++i) {
603+
double lat, lon;
604+
std::memcpy(&lon, geo + 9 + 16 * i, sizeof(double));
605+
std::memcpy(&lat, geo + 9 + 16 * i + 8, sizeof(double));
606+
Routepoint rtept;
607+
rtept.lat = lat;
608+
rtept.lon = lon;
609+
rte.points.push_back(rtept);
610+
rte.xMin = rte.xMin < lon ? rte.xMin : lon;
611+
rte.xMax = rte.xMax > lon ? rte.xMax : lon;
612+
rte.yMin = rte.yMin < lat ? rte.yMin : lat;
613+
rte.yMax = rte.yMax > lat ? rte.yMax : lat;
614+
}
615+
616+
// add route-specific attributes
617+
for (int i = 0; i < attrs.size(); ++i) {
618+
if (attrs[i].fieldName() == attr[NumAttr]) {
619+
bool numIsOK;
620+
long num = attrs[i].fieldValue().toLong(&numIsOK);
621+
if (numIsOK)
622+
rte.number = num;
623+
}
624+
}
625+
626+
featureId = data->addRoute(rte);
627+
success = true;
628+
obj = &(data->getRoute(featureId));
629+
}
630+
631+
// is it a track?
632+
if (mFeatureType == TrackType && geo != NULL && geo[1] == 2) {
633+
634+
Track trk;
635+
TrackSegment trkseg;
636+
637+
// reset bounds
638+
trk.xMin = std::numeric_limits<double>::max();
639+
trk.xMax = -std::numeric_limits<double>::max();
640+
trk.yMin = std::numeric_limits<double>::max();
641+
trk.yMax = -std::numeric_limits<double>::max();
642+
643+
// add geometry
644+
int nPoints;
645+
std::memcpy(&nPoints, geo + 5, 4);
646+
for (int i = 0; i < nPoints; ++i) {
647+
double lat, lon;
648+
std::memcpy(&lon, geo + 9 + 16 * i, sizeof(double));
649+
std::memcpy(&lat, geo + 9 + 16 * i + 8, sizeof(double));
650+
Trackpoint trkpt;
651+
trkpt.lat = lat;
652+
trkpt.lon = lon;
653+
trkseg.points.push_back(trkpt);
654+
trk.xMin = trk.xMin < lon ? trk.xMin : lon;
655+
trk.xMax = trk.xMax > lon ? trk.xMax : lon;
656+
trk.yMin = trk.yMin < lat ? trk.yMin : lat;
657+
trk.yMax = trk.yMax > lat ? trk.yMax : lat;
658+
}
659+
660+
// add track-specific attributes
661+
for (int i = 0; i < attrs.size(); ++i) {
662+
if (attrs[i].fieldName() == attr[NumAttr]) {
663+
bool numIsOK;
664+
long num = attrs[i].fieldValue().toLong(&numIsOK);
665+
if (numIsOK)
666+
trk.number = num;
667+
}
668+
}
669+
670+
trk.segments.push_back(trkseg);
671+
featureId = data->addTrack(trk);
672+
success = true;
673+
obj = &(data->getTrack(featureId));
674+
}
675+
676+
677+
// add common attributes
678+
if (obj) {
679+
for (int i = 0; i < attrs.size(); ++i) {
680+
if (attrs[i].fieldName() == attr[NameAttr]) {
681+
obj->name = attrs[i].fieldValue();
682+
}
683+
else if (attrs[i].fieldName() == attr[CmtAttr]) {
684+
obj->cmt = attrs[i].fieldValue();
685+
}
686+
else if (attrs[i].fieldName() == attr[DscAttr]) {
687+
obj->desc = attrs[i].fieldValue();
688+
}
689+
else if (attrs[i].fieldName() == attr[SrcAttr]) {
690+
obj->src = attrs[i].fieldValue();
691+
}
692+
else if (attrs[i].fieldName() == attr[URLAttr]) {
693+
obj->url = attrs[i].fieldValue();
694+
}
695+
else if (attrs[i].fieldName() == attr[URLNameAttr]) {
696+
obj->urlname = attrs[i].fieldValue();
697+
}
698+
}
699+
}
700+
701+
return success;
546702
}
547703

548704

‎providers/gpx/qgsgpxprovider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class QgsGPXProvider : public QgsVectorDataProvider {
148148
*/
149149
bool boundsCheck(double x, double y);
150150

151-
bool supportsFeatureAddition(){return false;}
151+
bool supportsFeatureAddition(){return true;}
152152

153153
private:
154154

0 commit comments

Comments
 (0)
Please sign in to comment.