Skip to content

Commit 713079c

Browse files
author
timlinux
committedMar 22, 2004
This is a c++ first draft of a port of a perl script by Schuyler to import Garmin gps dump files as a shapefile. The resulting imported file will be displayed in the map view. At the moment it only generates a point layer of the waypoints but a future version will generate polylines and perhaps polygons too using similar logic to that used by Shuylers perl stuff. Note this plugin is still under construction and I am commiting it mainly so that other developers can assist me when I get stuck. Also note that the plugins Makefile builds a standalone app based on the plugin gui that can be run separately from qgis.
git-svn-id: http://svn.osgeo.org/qgis/trunk@1058 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 0b7fc7b commit 713079c

20 files changed

+27959
-0
lines changed
 

‎plugins/gps_importer/Makefile.am

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Copyright (C) 2003 Gary Sherman <sherman at mrcc.com>
2+
#
3+
# This file is free software; as a special exception the author gives
4+
# unlimited permission to copy and/or distribute it, with or without
5+
# modifications, as long as this notice is preserved.
6+
#
7+
# This program is distributed in the hope that it will be useful, but
8+
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
9+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10+
#
11+
# $Id$
12+
13+
plugindir = ${pkglibdir}
14+
15+
#for plugin so
16+
plugin_LTLIBRARIES = libgpsimporterplugin.la
17+
18+
#for standalon executable
19+
bin_PROGRAMS = gpsimporter
20+
21+
%.moc.cpp: %.h
22+
$(MOC) -o $@ $<
23+
24+
%.h: %.ui
25+
$(UIC) -o $@ $<
26+
27+
%.cpp: %.ui
28+
$(UIC) -o $@ -impl $*.h $<
29+
30+
##
31+
## For plugin lib
32+
##
33+
34+
libgpsimporterplugin_la_SOURCES = plugin.cpp \
35+
» » » waypointtoshape.cpp \
36+
waypointtoshape.h \
37+
» » » utils.c \
38+
shpopen.c \
39+
dbfopen.c \
40+
shapefile.h \
41+
plugingui.cpp \
42+
$(plugin_UI)\
43+
$(plugin_MOC)
44+
45+
46+
plugin_MOC = plugin.moc.cpp \
47+
plugingui.moc.cpp \
48+
pluginguibase.moc.cpp \
49+
../../src/qgsmaplayer.moc.cpp \
50+
../../src/qgsvectorlayer.moc.cpp
51+
52+
plugin_UI = pluginguibase.h \
53+
pluginguibase.cpp
54+
55+
plugin_UIC = pluginguibase.ui
56+
57+
# UI dependencies
58+
pluginguibase.cpp: pluginguibase.h pluginguibase.ui
59+
60+
BUILT_SOURCES = $(plugin_MOC) $(plugin_UI)
61+
62+
AM_CXXFLAGS := $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) $(DEBUG_QGIS) -I../../src
63+
64+
libgpsimporterplugin_la_LIBADD = $(QT_LDADD) ../../src/libqgis.la
65+
66+
libgpsimporterplugin_la_LDFLAGS = -avoid-version -module
67+
68+
##
69+
## For standalone executable
70+
##
71+
72+
gpsimporter_SOURCES = main.cpp \
73+
» » » waypointtoshape.cpp \
74+
waypointtoshape.h \
75+
» » » utils.c \
76+
shpopen.c \
77+
dbfopen.c \
78+
shapefile.h \
79+
plugingui.cpp \
80+
pluginguibase.cpp \
81+
$(standalone_MOC)
82+
83+
gpsimporter_LDADD = $(QT_LDADD)
84+
85+
standalone_MOC = plugingui.moc.cpp \
86+
pluginguibase.moc.cpp
87+
88+
standalone_UI = pluginguibase.h \
89+
pluginguibase.cpp
90+
91+
92+
##
93+
## Anything that must go in the tarball gets added here
94+
##
95+
96+
EXTRA_DIST = $(plugin_UIC) icon.xpm \
97+
pluginguibase.h \
98+
pluginguibase.ui.h \
99+
plugingui.h \
100+
plugin.h \
101+
shapefil.h \
102+
utils.h \
103+
waypointtoshape.h

‎plugins/gps_importer/README

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
##############################################
2+
QGIS PLUGIN TEMPLATE DIRECTORY
3+
4+
T.Sutton 2004
5+
##############################################
6+
7+
Please do not edit the files in this directory
8+
unless you know exactly what you are doing -
9+
these files are used as the basis for creating
10+
new plugins. Altering these files may break
11+
the automated plugin template generation process.
12+
13+
Please visit: http://mrcc.com/qgiswiki/PluginDevelopersGuide
14+
15+
For more information on creating plugins.

‎plugins/gps_importer/dbfopen.c

Lines changed: 1073 additions & 0 deletions
Large diffs are not rendered by default.

‎plugins/gps_importer/gps.xpm

Lines changed: 11322 additions & 0 deletions
Large diffs are not rendered by default.

‎plugins/gps_importer/icon.xpm

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
/* XPM */
2+
static const char *icon[]={
3+
"22 22 180 2",
4+
"Qt c None",
5+
"#g c #33383b",
6+
"#h c #394044",
7+
"#i c #434847",
8+
"#p c #444746",
9+
"#. c #4a4e4f",
10+
"#o c #4c5151",
11+
".8 c #4d5051",
12+
".0 c #4f5251",
13+
"#f c #504749",
14+
"#e c #50524e",
15+
"#r c #505452",
16+
"#q c #515758",
17+
"#j c #555959",
18+
"an c #566a4d",
19+
"## c #575a58",
20+
"#w c #585a57",
21+
"#n c #585b56",
22+
"aw c #596b54",
23+
".9 c #5a5c5a",
24+
".J c #5d5e59",
25+
"#H c #5d636d",
26+
"#s c #606464",
27+
"#G c #606b73",
28+
"au c #60a945",
29+
".O c #61635b",
30+
"av c #61a84d",
31+
"at c #62ae43",
32+
"ak c #62ae44",
33+
"#I c #636565",
34+
"am c #63ab47",
35+
"#R c #64696d",
36+
".B c #656765",
37+
".1 c #656863",
38+
"ae c #656e61",
39+
"#F c #656e73",
40+
"al c #65aa49",
41+
"#m c #676963",
42+
"#v c #676a64",
43+
"#d c #686a65",
44+
".6 c #696c67",
45+
"#E c #696e70",
46+
".7 c #6a6c66",
47+
"#L c #6a6d66",
48+
".X c #6a6d67",
49+
"#1 c #6d6e68",
50+
"#z c #6d706b",
51+
"#a c #6d706e",
52+
".w c #6f7374",
53+
"#M c #6f7676",
54+
"#2 c #70716d",
55+
"a. c #70726b",
56+
".Z c #70736e",
57+
".E c #707575",
58+
"ai c #707a6a",
59+
"as c #70a85c",
60+
"ar c #717e6a",
61+
".P c #72736c",
62+
"#x c #72746f",
63+
"aj c #72af5a",
64+
".F c #73746c",
65+
"#D c #737570",
66+
"ah c #74766f",
67+
".N c #747979",
68+
".2 c #757975",
69+
"#U c #757a78",
70+
"#T c #77797b",
71+
"#y c #787b76",
72+
"#0 c #787b7c",
73+
"#Z c #787c7c",
74+
"aF c #787d7d",
75+
"#K c #797c7d",
76+
"#P c #798fa8",
77+
"#7 c #7a7a78",
78+
"#9 c #7a7c7d",
79+
"ab c #7aaf64",
80+
"aq c #7b7d77",
81+
"a# c #7b7d79",
82+
"ag c #7b7e7e",
83+
"ap c #7b7e7f",
84+
"ay c #7b7f7f",
85+
".W c #7b7f80",
86+
"#A c #7c7f7a",
87+
".5 c #7c8080",
88+
"#c c #7f8284",
89+
".Q c #81827b",
90+
".Y c #81847d",
91+
"aU c #82837e",
92+
"#l c #828587",
93+
".f c #83857f",
94+
"az c #848580",
95+
".I c #85857d",
96+
".x c #85867d",
97+
"#Q c #858ea0",
98+
"#u c #868a8c",
99+
"aR c #878682",
100+
"aH c #878a89",
101+
".n c #878b8b",
102+
"aA c #878c8a",
103+
".G c #88887e",
104+
".A c #898a84",
105+
".s c #8a8c89",
106+
"aS c #8b8b86",
107+
"aV c #8b8c88",
108+
"#C c #8b8f90",
109+
".R c #8c8d86",
110+
"aM c #8c8f8c",
111+
"aT c #8d8e88",
112+
".o c #8d8f86",
113+
"#J c #8d8f89",
114+
"aL c #8d9090",
115+
".S c #8e9089",
116+
"#S c #8e908a",
117+
"aI c #8f8f89",
118+
"#B c #8f918c",
119+
"ad c #8fb57e",
120+
"#O c #90a2b8",
121+
".3 c #92948e",
122+
"#8 c #939590",
123+
"af c #949791",
124+
"aK c #949b9b",
125+
".r c #959792",
126+
"aE c #959b9e",
127+
"aW c #969591",
128+
"#b c #969791",
129+
"#t c #969892",
130+
"#N c #96a5b6",
131+
"ao c #979a94",
132+
".H c #98978d",
133+
"ac c #98b58b",
134+
"#k c #999b95",
135+
".T c #9b9c96",
136+
".4 c #9c9d97",
137+
"aJ c #9da09c",
138+
".V c #9e9f96",
139+
"ax c #9fa09b",
140+
".U c #a0a199",
141+
"#V c #a3a7a9",
142+
"aX c #a4a3a0",
143+
"aB c #a5acad",
144+
".y c #a6a69c",
145+
"aD c #a7b0b5",
146+
"aG c #a8a9a4",
147+
".K c #a9aaa2",
148+
"aN c #a9aba6",
149+
".z c #aaaaa1",
150+
"aO c #aaaba6",
151+
"aC c #b2bdbf",
152+
"aP c #b4b4b0",
153+
"#W c #b4b8ba",
154+
".p c #babcb1",
155+
".g c #bfc1b7",
156+
".L c #c1c2bb",
157+
".C c #c1c3bd",
158+
".M c #c2c3bc",
159+
".q c #c4c6bd",
160+
"#X c #cacfd3",
161+
"#Y c #cbced0",
162+
"aa c #cbd4c5",
163+
"aQ c #cdcdcd",
164+
".h c #d5d8cf",
165+
".i c #d9dcd5",
166+
".e c #dadbdb",
167+
"#3 c #dcdbd9",
168+
".D c #dddfd9",
169+
".t c #dfe2dc",
170+
".a c #e2e3e0",
171+
".j c #e2e4e0",
172+
"#5 c #e3e2e0",
173+
"#6 c #e4e4e1",
174+
"#4 c #e5e4e2",
175+
".b c #e6e7e4",
176+
".# c #eaeae9",
177+
".c c #ebebe9",
178+
".v c #ecedea",
179+
".d c #f0f0ef",
180+
".l c #f0f1ef",
181+
".u c #f0f2ef",
182+
".k c #f4f7f3",
183+
".m c #f5f5f3",
184+
"QtQtQtQtQtQtQtQtQt.#.a.b.c.dQtQtQtQtQtQtQtQt",
185+
"QtQtQtQtQtQtQt.e.f.g.h.i.j.k.l.mQtQtQtQtQtQt",
186+
"QtQtQtQtQtQtQt.n.o.p.q.r.s.t.u.vQtQtQtQtQtQt",
187+
"QtQtQtQtQtQtQt.w.x.y.z.A.B.C.D.DQtQtQtQtQtQt",
188+
"QtQtQtQtQtQtQt.E.F.G.H.I.J.K.L.MQtQtQtQtQtQt",
189+
"QtQtQtQtQtQtQt.N.O.P.Q.R.S.T.U.VQtQtQtQtQtQt",
190+
"QtQtQtQtQtQtQt.W.X.Y.Z.0.1.2.3.4QtQtQtQtQtQt",
191+
"QtQtQtQtQtQtQt.5.6.7.8.9#.###a#bQtQtQtQtQtQt",
192+
"QtQtQtQtQtQtQt#c#d#e#f#g#h#i#j#kQtQtQtQtQtQt",
193+
"QtQtQtQtQtQtQt#l#m#n#o#p#q#r#s#tQtQtQtQtQtQt",
194+
"QtQtQtQtQtQtQt#u#m#v#w#x#y#z#A#BQtQtQtQtQtQt",
195+
"QtQtQtQtQtQtQt#C.7#D#E#F#G#H#I#JQtQtQtQtQtQt",
196+
"QtQtQtQtQtQtQt#K#L#M#N#O#P#Q#R#SQtQtQtQtQtQt",
197+
"QtQtQtQtQtQtQt#T#L#U#V#W#X#Y#Z.3QtQtQtQtQtQt",
198+
"QtQtQtQtQtQtQt#0#1#2#3#4#5#6#7#8QtQtQtQtQtQt",
199+
"QtQtQtQtQtQtQt#9a.a#aaabacadaeafQtQtQtQtQtQt",
200+
"QtQtQtQtQtQtQtagahaiajakalamanaoQtQtQtQtQtQt",
201+
"QtQtQtQtQtQtQtapaqarasatauavawaxQtQtQtQtQtQt",
202+
"QtQtQtQtQtQtQtayazaAaBaCaDaEaFaGQtQtQtQtQtQt",
203+
"QtQtQtQtQtQtQtaHaIaJaKaLaMaNaOaPQtQtQtQtQtQt",
204+
"QtQtQtQtQtQtQtaQaRaSaTaUaVaWaXQtQtQtQtQtQtQt",
205+
"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt"};

‎plugins/gps_importer/main.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifdef HAVE_CONFIG_H
2+
#include <config.h>
3+
#endif
4+
5+
#include <stdio.h>
6+
#include <stdlib.h>
7+
#include "plugingui.h"
8+
#include <qapplication.h>
9+
10+
int main(int argc, char *argv[])
11+
{
12+
QApplication a(argc, argv);
13+
14+
PluginGui *myPluginGui=new PluginGui();
15+
a.setMainWidget(myPluginGui);
16+
myPluginGui->show();
17+
18+
19+
return a.exec();
20+
21+
22+
return EXIT_SUCCESS;
23+
}

‎plugins/gps_importer/plugin.cpp

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/***************************************************************************
2+
plugin.cpp
3+
Import tool for various worldmap analysis output files
4+
Functions:
5+
6+
-------------------
7+
begin : Jan 21, 2004
8+
copyright : (C) 2004 by Tim Sutton
9+
email : tim@linfiniti.com
10+
11+
***************************************************************************/
12+
13+
/***************************************************************************
14+
* *
15+
* This program is free software; you can redistribute it and/or modify *
16+
* it under the terms of the GNU General Public License as published by *
17+
* the Free Software Foundation; either version 2 of the License, or *
18+
* (at your option) any later version. *
19+
* *
20+
***************************************************************************/
21+
/* $Id$ */
22+
23+
// includes
24+
25+
#include "../../src/qgisapp.h"
26+
#include "../../src/qgsmaplayer.h"
27+
#include "../../src/qgsrasterlayer.h"
28+
#include "plugin.h"
29+
30+
31+
#include <qtoolbar.h>
32+
#include <qmenubar.h>
33+
#include <qmessagebox.h>
34+
#include <qpopupmenu.h>
35+
#include <qlineedit.h>
36+
#include <qaction.h>
37+
#include <qapplication.h>
38+
#include <qcursor.h>
39+
40+
//non qt includes
41+
#include <iostream>
42+
43+
//the gui subclass
44+
#include "plugingui.h"
45+
46+
// xpm for creating the toolbar icon
47+
#include "icon.xpm"
48+
//
49+
static const char *pluginVersion = "0.1";
50+
/**
51+
* Constructor for the plugin. The plugin is passed a pointer to the main app
52+
* and an interface object that provides access to exposed functions in QGIS.
53+
* @param qgis Pointer to the QGIS main window
54+
* @param _qI Pointer to the QGIS interface object
55+
*/
56+
Plugin::Plugin(QgisApp * theQGisApp, QgisIface * theQgisInterFace):
57+
qgisMainWindowPointer(theQGisApp), qGisInterface(theQgisInterFace)
58+
{
59+
/** Initialize the plugin and set the required attributes */
60+
pluginNameQString = "GpsImporter";
61+
pluginVersionQString = "Version 0.1";
62+
pluginDescriptionQString = "An importer for GPS dump files.";
63+
64+
}
65+
66+
Plugin::~Plugin()
67+
{
68+
69+
}
70+
71+
/* Following functions return name, description, version, and type for the plugin */
72+
QString Plugin::name()
73+
{
74+
return pluginNameQString;
75+
}
76+
77+
QString Plugin::version()
78+
{
79+
return pluginVersionQString;
80+
81+
}
82+
83+
QString Plugin::description()
84+
{
85+
return pluginDescriptionQString;
86+
87+
}
88+
89+
int Plugin::type()
90+
{
91+
return QgisPlugin::UI;
92+
}
93+
94+
/*
95+
* Initialize the GUI interface for the plugin
96+
*/
97+
void Plugin::initGui()
98+
{
99+
// add a menu with 2 items
100+
QPopupMenu *pluginMenu = new QPopupMenu(qgisMainWindowPointer);
101+
102+
pluginMenu->insertItem(QIconSet(icon),"&GpsImporter", this, SLOT(run()));
103+
104+
menuBarPointer = ((QMainWindow *) qgisMainWindowPointer)->menuBar();
105+
106+
menuIdInt = qGisInterface->addMenu("&Tools", pluginMenu);
107+
// Create the action for tool
108+
QAction *myQActionPointer = new QAction("Import GPS Data", QIconSet(icon), "&Wmi",0, this, "run");
109+
// Connect the action to the run
110+
connect(myQActionPointer, SIGNAL(activated()), this, SLOT(run()));
111+
// Add the toolbar
112+
toolBarPointer = new QToolBar((QMainWindow *) qgisMainWindowPointer, "Tools");
113+
toolBarPointer->setLabel("Import GPS Data");
114+
// Add the zoom previous tool to the toolbar
115+
myQActionPointer->addTo(toolBarPointer);
116+
117+
118+
}
119+
120+
// Slot called when the buffer menu item is activated
121+
void Plugin::run()
122+
{
123+
PluginGui *myPluginGui=new PluginGui(qgisMainWindowPointer,"Import GPS Data",true,0);
124+
//listen for when the layer has been made so we can draw it
125+
connect(myPluginGui, SIGNAL(drawRasterLayer(QString)), this, SLOT(drawRasterLayer(QString)));
126+
connect(myPluginGui, SIGNAL(drawVectorLayer(QString,QString,QString)), this, SLOT(drawVectorLayer(QString,QString,QString)));
127+
myPluginGui->show();
128+
}
129+
//!draw a raster layer in the qui - intended to respond to signal sent by diolog when it as finished creating
130+
//layer
131+
void Plugin::drawRasterLayer(QString theQString)
132+
{
133+
qGisInterface->addRasterLayer(theQString);
134+
}
135+
//!draw a vector layer in the qui - intended to respond to signal sent by diolog when it as finished creating a layer
136+
////needs to be given vectorLayerPath, baseName, providerKey ("ogr" or "postgres");
137+
void Plugin::drawVectorLayer(QString thePathNameQString, QString theBaseNameQString, QString theProviderQString)
138+
{
139+
qGisInterface->addVectorLayer( thePathNameQString, theBaseNameQString, theProviderQString);
140+
}
141+
142+
// Unload the plugin by cleaning up the GUI
143+
void Plugin::unload()
144+
{
145+
// remove the GUI
146+
menuBarPointer->removeItem(menuIdInt);
147+
delete toolBarPointer;
148+
}
149+
/**
150+
* Required extern functions needed for every plugin
151+
* These functions can be called prior to creating an instance
152+
* of the plugin class
153+
*/
154+
// Class factory to return a new instance of the plugin class
155+
extern "C" QgisPlugin * classFactory(QgisApp * theQGisAppPointer, QgisIface * theQgisInterfacePointer)
156+
{
157+
return new Plugin(theQGisAppPointer, theQgisInterfacePointer);
158+
}
159+
160+
// Return the name of the plugin - note that we do not user class members as
161+
// the class may not yet be insantiated when this method is called.
162+
extern "C" QString name()
163+
{
164+
return QString("Import GPS Data");
165+
}
166+
167+
// Return the description
168+
extern "C" QString description()
169+
{
170+
return QString("An importer for GPS dump files.");
171+
}
172+
173+
// Return the type (either UI or MapLayer plugin)
174+
extern "C" int type()
175+
{
176+
return QgisPlugin::UI;
177+
}
178+
179+
// Return the version number for the plugin
180+
extern "C" QString version()
181+
{
182+
return pluginVersion;
183+
}
184+
185+
// Delete ourself
186+
extern "C" void unload(QgisPlugin * thePluginPointer)
187+
{
188+
delete thePluginPointer;
189+
}

‎plugins/gps_importer/plugin.h

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/***************************************************************************
2+
plugin.h
3+
Functions:
4+
-------------------
5+
begin : Jan 21, 2004
6+
copyright : (C) 2004 by Tim Sutton
7+
email : tim@linfiniti.com
8+
9+
***************************************************************************/
10+
11+
/***************************************************************************
12+
* *
13+
* This program is free software; you can redistribute it and/or modify *
14+
* it under the terms of the GNU General Public License as published by *
15+
* the Free Software Foundation; either version 2 of the License, or *
16+
* (at your option) any later version. *
17+
* *
18+
***************************************************************************/
19+
/* $Id$ */
20+
#ifndef PLUGIN
21+
#define PLUGIN
22+
#include "../qgisplugin.h"
23+
#include <qwidget.h>
24+
#include <qgisapp.h>
25+
26+
/**
27+
* \class Plugin
28+
* \brief OpenModeller plugin for QGIS
29+
*
30+
*/
31+
class Plugin:public QObject, public QgisPlugin
32+
{
33+
Q_OBJECT public:
34+
/**
35+
* Constructor for a plugin. The QgisApp and QgisIface pointers are passed by
36+
* QGIS when it attempts to instantiate the plugin.
37+
* @param qgis Pointer to the QgisApp object
38+
* @param qI Pointer to the QgisIface object.
39+
*/
40+
Plugin(QgisApp * , QgisIface * );
41+
/**
42+
* Virtual function to return the name of the plugin. The name will be used when presenting a list
43+
* of installable plugins to the user
44+
*/
45+
virtual QString name();
46+
/**
47+
* Virtual function to return the version of the plugin.
48+
*/
49+
virtual QString version();
50+
/**
51+
* Virtual function to return a description of the plugins functions
52+
*/
53+
virtual QString description();
54+
/**
55+
* Return the plugin type
56+
*/
57+
virtual int type();
58+
//! init the gui
59+
virtual void initGui();
60+
//! Destructor
61+
virtual ~ Plugin();
62+
public slots:
63+
//! Show the dialog box
64+
void run();
65+
//!draw a raster layer in the qui
66+
void drawRasterLayer(QString);
67+
//! Add a vector layer given vectorLayerPath, baseName, providerKey ("ogr" or "postgres");
68+
void drawVectorLayer(QString,QString,QString);
69+
//! unload the plugin
70+
void unload();
71+
//! show the help document
72+
void help();
73+
private:
74+
75+
76+
//! Name of the plugin
77+
QString pluginNameQString;
78+
//! Version
79+
QString pluginVersionQString;
80+
//! Descrption of the plugin
81+
QString pluginDescriptionQString;
82+
//! Plugin type as defined in QgisPlugin::PLUGINTYPE
83+
int pluginType;
84+
//! Id of the plugin's menu. Used for unloading
85+
int menuIdInt;
86+
//! Pointer to our toolbar
87+
QToolBar *toolBarPointer;
88+
//! Pointer to our menu
89+
QMenuBar *menuBarPointer;
90+
//! Pionter to QGIS main application object
91+
QgisApp *qgisMainWindowPointer;
92+
//! Pointer to the QGIS interface object
93+
QgisIface *qGisInterface;
94+
};
95+
96+
#endif

‎plugins/gps_importer/plugingui.cpp

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/***************************************************************************
2+
* Copyright (C) 2003 by Tim Sutton *
3+
* tim@linfiniti.com *
4+
* *
5+
* This is a plugin generated from the QGIS plugin template *
6+
* *
7+
* This program is free software; you can redistribute it and/or modify *
8+
* it under the terms of the GNU General Public License as published by *
9+
* the Free Software Foundation; either version 2 of the License, or *
10+
* (at your option) any later version. *
11+
***************************************************************************/
12+
#include "plugingui.h"
13+
14+
//qt includes
15+
#include <qpushbutton.h>
16+
#include <qlineedit.h>
17+
#include <qspinbox.h>
18+
#include <qfiledialog.h>
19+
#include "waypointtoshape.h"
20+
//standard includes
21+
#include <iostream>
22+
23+
PluginGui::PluginGui() : PluginGuiBase()
24+
{
25+
26+
}
27+
PluginGui::PluginGui( QWidget* parent , const char* name , bool modal , WFlags fl )
28+
: PluginGuiBase( parent, name, modal, fl )
29+
{
30+
31+
}
32+
PluginGui::~PluginGui()
33+
{
34+
}
35+
36+
void PluginGui::pbnOK_clicked()
37+
{
38+
//
39+
// If you have a produced a raster layer using your plugin, you can ask qgis to
40+
// add it to the view using:
41+
// emit drawRasterLayer(QString("layername"));
42+
WayPointToShape * myWayPointToShape = new WayPointToShape(leOutputShapeFile->text(),leInputFile->text());
43+
// or for a vector layer
44+
// emit drawVectorLayer(QString("pathname"),QString("layername"),QString("provider name (either ogr or postgres"));
45+
//
46+
delete myWayPointToShape;
47+
//close the dialog
48+
done(1);
49+
}
50+
51+
52+
void PluginGui::pbnSelectInputFile_clicked()
53+
{
54+
std::cout << " Gps File Importer::pbnSelectInputFile_clicked() " << std::endl;
55+
QString myFileTypeQString;
56+
QString myFilterString="Text File (*.txt)";
57+
QString myFileNameQString = QFileDialog::getOpenFileName(
58+
"." , //initial dir
59+
myFilterString, //filters to select
60+
this , //parent dialog
61+
"OpenFileDialog" , //QFileDialog qt object name
62+
"Select GPS dump text file" , //caption
63+
&myFileTypeQString //the pointer to store selected filter
64+
);
65+
std::cout << "Selected filetype filter is : " << myFileTypeQString << std::endl;
66+
leInputFile->setText(myFileNameQString);
67+
if ( (leOutputShapeFile->text()=="") || (leInputFile->text()=="") )
68+
{
69+
pbnOK->setEnabled(false);
70+
}
71+
else
72+
{
73+
pbnOK->setEnabled(true);
74+
}
75+
}
76+
77+
78+
void PluginGui::pbnSelectOutputFile_clicked()
79+
{
80+
std::cout << " Gps File Importer Gui::pbnSelectOutputFile_clicked() " << std::endl;
81+
QString myOutputFileNameQString = QFileDialog::getSaveFileName(
82+
".",
83+
"ESRI Shapefile (*.shp)",
84+
this,
85+
"save file dialog"
86+
"Choose a filename to save under" );
87+
leOutputShapeFile->setText(myOutputFileNameQString);
88+
if ( leOutputShapeFile->text()=="" || leInputFile->text()=="" )
89+
{
90+
pbnOK->setEnabled(false);
91+
}
92+
else
93+
{
94+
pbnOK->setEnabled(true);
95+
}
96+
}
97+
98+
99+
void PluginGui::pbnCancel_clicked()
100+
{
101+
102+
}
103+

‎plugins/gps_importer/plugingui.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/***************************************************************************
2+
* Copyright (C) 2003 by Tim Sutton *
3+
* tim@linfiniti.com *
4+
* *
5+
* This is a plugin generated from the QGIS plugin template *
6+
* *
7+
* This program is free software; you can redistribute it and/or modify *
8+
* it under the terms of the GNU General Public License as published by *
9+
* the Free Software Foundation; either version 2 of the License, or *
10+
* (at your option) any later version. *
11+
***************************************************************************/
12+
#ifndef PLUGINGUI_H
13+
#define PLUGINGUI_H
14+
15+
#include <pluginguibase.h>
16+
17+
/**
18+
@author Tim Sutton
19+
*/
20+
class PluginGui : public PluginGuiBase
21+
{
22+
Q_OBJECT
23+
public:
24+
PluginGui();
25+
PluginGui( QWidget* parent , const char* name , bool modal , WFlags );
26+
~PluginGui();
27+
28+
private:
29+
30+
void pbnSelectInputFile_clicked();
31+
void pbnSelectOutputFile_clicked();
32+
void pbnCancel_clicked();
33+
void pbnOK_clicked();
34+
35+
signals:
36+
void drawRasterLayer(QString);
37+
void drawVectorrLayer(QString,QString,QString);
38+
};
39+
40+
#endif

‎plugins/gps_importer/pluginguibase.cpp

Lines changed: 12027 additions & 0 deletions
Large diffs are not rendered by default.

‎plugins/gps_importer/pluginguibase.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/****************************************************************************
2+
** Form interface generated from reading ui file 'pluginguibase.ui'
3+
**
4+
** Created: Fri Mar 5 13:08:43 2004
5+
** by: The User Interface Compiler ($Id$)
6+
**
7+
** WARNING! All changes made in this file will be lost!
8+
****************************************************************************/
9+
10+
#ifndef PLUGINGUIBASE_H
11+
#define PLUGINGUIBASE_H
12+
13+
#include <qvariant.h>
14+
#include <qpixmap.h>
15+
#include <qdialog.h>
16+
17+
class QVBoxLayout;
18+
class QHBoxLayout;
19+
class QGridLayout;
20+
class QSpacerItem;
21+
class QFrame;
22+
class QLabel;
23+
class QTextEdit;
24+
class QPushButton;
25+
class QSpinBox;
26+
class QLineEdit;
27+
28+
class PluginGuiBase : public QDialog
29+
{
30+
Q_OBJECT
31+
32+
public:
33+
PluginGuiBase( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
34+
~PluginGuiBase();
35+
36+
QFrame* line1;
37+
QLabel* pixmapLabel1;
38+
QLabel* txtHeading;
39+
QTextEdit* teInstructions;
40+
QLabel* lblInputFile;
41+
QLabel* lblOutputFile;
42+
QLabel* lblMinTimeGap;
43+
QLabel* lblMinDistanceGap;
44+
QPushButton* pbnSelectInputFile;
45+
QPushButton* pbnSelectOutputFile;
46+
QSpinBox* spinMinTimeGap;
47+
QSpinBox* spinMinDistanceGap;
48+
QPushButton* pbnCancel;
49+
QLineEdit* leInputFile;
50+
QLineEdit* leOutputShapeFile;
51+
QPushButton* pbnOK;
52+
53+
public slots:
54+
virtual void pbnOK_clicked();
55+
virtual void pbnSelectInputFile_clicked();
56+
virtual void pbnSelectOutputFile_clicked();
57+
virtual void pbnCancel_clicked();
58+
59+
protected:
60+
61+
protected slots:
62+
virtual void languageChange();
63+
64+
private:
65+
QPixmap image0;
66+
QPixmap image1;
67+
68+
};
69+
70+
#endif // PLUGINGUIBASE_H

‎plugins/gps_importer/pluginguibase.ui

Lines changed: 389 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/****************************************************************************
2+
** ui.h extension file, included from the uic-generated form implementation.
3+
**
4+
** If you wish to add, delete or rename functions or slots use
5+
** Qt Designer which will update this file, preserving your code. Create an
6+
** init() function in place of a constructor, and a destroy() function in
7+
** place of a destructor.
8+
*****************************************************************************/
9+
10+
11+
12+
void PluginGuiBase::pbnOK_clicked()
13+
{
14+
15+
}
16+
17+
18+
void PluginGuiBase::pbnSelectInputFile_clicked()
19+
{
20+
21+
}
22+
23+
24+
void PluginGuiBase::pbnSelectOutputFile_clicked()
25+
{
26+
27+
}
28+
29+
30+
void PluginGuiBase::pbnCancel_clicked()
31+
{
32+
33+
}

‎plugins/gps_importer/shapefil.h

Lines changed: 351 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,351 @@
1+
#ifndef _SHAPEFILE_H_INCLUDED
2+
#define _SHAPEFILE_H_INCLUDED
3+
4+
/******************************************************************************
5+
* $Id$
6+
*
7+
* Project: Shapelib
8+
* Purpose: Primary include file for Shapelib.
9+
* Author: Frank Warmerdam, warmerda@home.com
10+
*
11+
******************************************************************************
12+
* Copyright (c) 1999, Frank Warmerdam
13+
*
14+
* This software is available under the following "MIT Style" license,
15+
* or at the option of the licensee under the LGPL (see LICENSE.LGPL). This
16+
* option is discussed in more detail in shapelib.html.
17+
*
18+
* --
19+
*
20+
* Permission is hereby granted, free of charge, to any person obtaining a
21+
* copy of this software and associated documentation files (the "Software"),
22+
* to deal in the Software without restriction, including without limitation
23+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
24+
* and/or sell copies of the Software, and to permit persons to whom the
25+
* Software is furnished to do so, subject to the following conditions:
26+
*
27+
* The above copyright notice and this permission notice shall be included
28+
* in all copies or substantial portions of the Software.
29+
*
30+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
31+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
33+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
35+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
36+
* DEALINGS IN THE SOFTWARE.
37+
******************************************************************************
38+
*
39+
* $Log$
40+
* Revision 1.1 2004/03/22 23:38:26 timlinux
41+
* This is a c++ first draft of a port of a perl script by Schuyler to import Garmin gps dump files as a shapefile. The resulting imported file will be displayed in the map view. At the moment it only generates a point layer of the waypoints but a future version will generate polylines and perhaps polygons too using similar logic to that used by Shuylers perl stuff. Note this plugin is still under construction and I am commiting it mainly so that other developers can assist me when I get stuck. Also note that the plugins Makefile builds a standalone app based on the plugin gui that can be run separately from qgis.
42+
*
43+
* Revision 1.15 2000/02/16 16:03:51 warmerda
44+
* added null shape support
45+
*
46+
* Revision 1.14 1999/11/05 14:12:05 warmerda
47+
* updated license terms
48+
*
49+
* Revision 1.13 1999/06/02 18:24:21 warmerda
50+
* added trimming code
51+
*
52+
* Revision 1.12 1999/06/02 17:56:12 warmerda
53+
* added quad'' subnode support for trees
54+
*
55+
* Revision 1.11 1999/05/18 19:11:11 warmerda
56+
* Added example searching capability
57+
*
58+
* Revision 1.10 1999/05/18 17:49:38 warmerda
59+
* added initial quadtree support
60+
*
61+
* Revision 1.9 1999/05/11 03:19:28 warmerda
62+
* added new Tuple api, and improved extension handling - add from candrsn
63+
*
64+
* Revision 1.8 1999/03/23 17:22:27 warmerda
65+
* Added extern "C" protection for C++ users of shapefil.h.
66+
*
67+
* Revision 1.7 1998/12/31 15:31:07 warmerda
68+
* Added the TRIM_DBF_WHITESPACE and DISABLE_MULTIPATCH_MEASURE options.
69+
*
70+
* Revision 1.6 1998/12/03 15:48:15 warmerda
71+
* Added SHPCalculateExtents().
72+
*
73+
* Revision 1.5 1998/11/09 20:57:16 warmerda
74+
* Altered SHPGetInfo() call.
75+
*
76+
* Revision 1.4 1998/11/09 20:19:33 warmerda
77+
* Added 3D support, and use of SHPObject.
78+
*
79+
* Revision 1.3 1995/08/23 02:24:05 warmerda
80+
* Added support for reading bounds.
81+
*
82+
* Revision 1.2 1995/08/04 03:17:39 warmerda
83+
* Added header.
84+
*
85+
*/
86+
87+
#include <stdio.h>
88+
89+
#ifdef USE_DBMALLOC
90+
#include <dbmalloc.h>
91+
#endif
92+
93+
#ifdef __cplusplus
94+
extern "C" {
95+
#endif
96+
97+
/************************************************************************/
98+
/* Configuration options. */
99+
/************************************************************************/
100+
101+
/* -------------------------------------------------------------------- */
102+
/* Should the DBFReadStringAttribute() strip leading and */
103+
/* trailing white space? */
104+
/* -------------------------------------------------------------------- */
105+
#define TRIM_DBF_WHITESPACE
106+
107+
/* -------------------------------------------------------------------- */
108+
/* Should we write measure values to the Multipatch object? */
109+
/* Reportedly ArcView crashes if we do write it, so for now it */
110+
/* is disabled. */
111+
/* -------------------------------------------------------------------- */
112+
#define DISABLE_MULTIPATCH_MEASURE
113+
114+
/************************************************************************/
115+
/* SHP Support. */
116+
/************************************************************************/
117+
typedef struct
118+
{
119+
FILE *fpSHP;
120+
FILE *fpSHX;
121+
122+
int nShapeType; /* SHPT_* */
123+
124+
int nFileSize; /* SHP file */
125+
126+
int nRecords;
127+
int nMaxRecords;
128+
int *panRecOffset;
129+
int *panRecSize;
130+
131+
double adBoundsMin[4];
132+
double adBoundsMax[4];
133+
134+
int bUpdated;
135+
} SHPInfo;
136+
137+
typedef SHPInfo * SHPHandle;
138+
139+
/* -------------------------------------------------------------------- */
140+
/* Shape types (nSHPType) */
141+
/* -------------------------------------------------------------------- */
142+
#define SHPT_NULL 0
143+
#define SHPT_POINT 1
144+
#define SHPT_ARC 3
145+
#define SHPT_POLYGON 5
146+
#define SHPT_MULTIPOINT 8
147+
#define SHPT_POINTZ 11
148+
#define SHPT_ARCZ 13
149+
#define SHPT_POLYGONZ 15
150+
#define SHPT_MULTIPOINTZ 18
151+
#define SHPT_POINTM 21
152+
#define SHPT_ARCM 23
153+
#define SHPT_POLYGONM 25
154+
#define SHPT_MULTIPOINTM 28
155+
#define SHPT_MULTIPATCH 31
156+
157+
158+
/* -------------------------------------------------------------------- */
159+
/* Part types - everything but SHPT_MULTIPATCH just uses */
160+
/* SHPP_RING. */
161+
/* -------------------------------------------------------------------- */
162+
163+
#define SHPP_TRISTRIP 0
164+
#define SHPP_TRIFAN 1
165+
#define SHPP_OUTERRING 2
166+
#define SHPP_INNERRING 3
167+
#define SHPP_FIRSTRING 4
168+
#define SHPP_RING 5
169+
170+
/* -------------------------------------------------------------------- */
171+
/* SHPObject - represents on shape (without attributes) read */
172+
/* from the .shp file. */
173+
/* -------------------------------------------------------------------- */
174+
typedef struct
175+
{
176+
int nSHPType;
177+
178+
int nShapeId; /* -1 is unknown/unassigned */
179+
180+
int nParts;
181+
int *panPartStart;
182+
int *panPartType;
183+
184+
int nVertices;
185+
double *padfX;
186+
double *padfY;
187+
double *padfZ;
188+
double *padfM;
189+
190+
double dfXMin;
191+
double dfYMin;
192+
double dfZMin;
193+
double dfMMin;
194+
195+
double dfXMax;
196+
double dfYMax;
197+
double dfZMax;
198+
double dfMMax;
199+
} SHPObject;
200+
201+
/* -------------------------------------------------------------------- */
202+
/* SHP API Prototypes */
203+
/* -------------------------------------------------------------------- */
204+
SHPHandle SHPOpen( const char * pszShapeFile, const char * pszAccess );
205+
SHPHandle SHPCreate( const char * pszShapeFile, int nShapeType );
206+
void SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType,
207+
double * padfMinBound, double * padfMaxBound );
208+
209+
SHPObject *SHPReadObject( SHPHandle hSHP, int iShape );
210+
int SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject * psObject );
211+
212+
void SHPDestroyObject( SHPObject * psObject );
213+
void SHPComputeExtents( SHPObject * psObject );
214+
SHPObject *SHPCreateObject( int nSHPType, int nShapeId,
215+
int nParts, int * panPartStart, int * panPartType,
216+
int nVertices, double * padfX, double * padfY,
217+
double * padfZ, double * padfM );
218+
SHPObject *SHPCreateSimpleObject( int nSHPType, int nVertices,
219+
double * padfX, double * padfY, double * padfZ );
220+
221+
void SHPClose( SHPHandle hSHP );
222+
223+
const char *SHPTypeName( int nSHPType );
224+
const char *SHPPartTypeName( int nPartType );
225+
226+
/* -------------------------------------------------------------------- */
227+
/* Shape quadtree indexing API. */
228+
/* -------------------------------------------------------------------- */
229+
230+
/* this can be two or four for binary or quad tree */
231+
#define MAX_SUBNODE 4
232+
233+
typedef struct shape_tree_node
234+
{
235+
/* region covered by this node */
236+
double adfBoundsMin[4];
237+
double adfBoundsMax[4];
238+
239+
/* list of shapes stored at this node. The papsShapeObj pointers
240+
or the whole list can be NULL */
241+
int nShapeCount;
242+
int *panShapeIds;
243+
SHPObject **papsShapeObj;
244+
245+
int nSubNodes;
246+
struct shape_tree_node *apsSubNode[MAX_SUBNODE];
247+
248+
} SHPTreeNode;
249+
250+
typedef struct
251+
{
252+
SHPHandle hSHP;
253+
254+
int nMaxDepth;
255+
int nDimension;
256+
257+
SHPTreeNode *psRoot;
258+
} SHPTree;
259+
260+
SHPTree *SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth,
261+
double *padfBoundsMin, double *padfBoundsMax );
262+
void SHPDestroyTree( SHPTree * hTree );
263+
264+
int SHPWriteTree( SHPTree *hTree, const char * pszFilename );
265+
SHPTree SHPReadTree( const char * pszFilename );
266+
267+
int SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject );
268+
int SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject );
269+
int SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId );
270+
271+
void SHPTreeTrimExtraNodes( SHPTree * hTree );
272+
273+
int *SHPTreeFindLikelyShapes( SHPTree * hTree,
274+
double * padfBoundsMin,
275+
double * padfBoundsMax,
276+
int * );
277+
int SHPCheckBoundsOverlap( double *, double *, double *, double *, int );
278+
279+
/************************************************************************/
280+
/* DBF Support. */
281+
/************************************************************************/
282+
typedef struct
283+
{
284+
FILE *fp;
285+
286+
int nRecords;
287+
288+
int nRecordLength;
289+
int nHeaderLength;
290+
int nFields;
291+
int *panFieldOffset;
292+
int *panFieldSize;
293+
int *panFieldDecimals;
294+
char *pachFieldType;
295+
296+
char *pszHeader;
297+
298+
int nCurrentRecord;
299+
int bCurrentRecordModified;
300+
char *pszCurrentRecord;
301+
302+
int bNoHeader;
303+
int bUpdated;
304+
} DBFInfo;
305+
306+
typedef DBFInfo * DBFHandle;
307+
308+
typedef enum {
309+
FTString,
310+
FTInteger,
311+
FTDouble,
312+
FTInvalid
313+
} DBFFieldType;
314+
315+
#define XBASE_FLDHDR_SZ 32
316+
317+
DBFHandle DBFOpen( const char * pszDBFFile, const char * pszAccess );
318+
DBFHandle DBFCreate( const char * pszDBFFile );
319+
320+
int DBFGetFieldCount( DBFHandle psDBF );
321+
int DBFGetRecordCount( DBFHandle psDBF );
322+
int DBFAddField( DBFHandle hDBF, const char * pszFieldName,
323+
DBFFieldType eType, int nWidth, int nDecimals );
324+
325+
DBFFieldType DBFGetFieldInfo( DBFHandle psDBF, int iField,
326+
char * pszFieldName,
327+
int * pnWidth, int * pnDecimals );
328+
329+
int DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField );
330+
double DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField );
331+
const char *DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField );
332+
333+
int DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField,
334+
int nFieldValue );
335+
int DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField,
336+
double dFieldValue );
337+
int DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField,
338+
const char * pszFieldValue );
339+
340+
const char *DBFReadTuple(DBFHandle psDBF, int hEntity );
341+
int DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple );
342+
343+
DBFHandle DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename );
344+
345+
void DBFClose( DBFHandle hDBF );
346+
347+
#ifdef __cplusplus
348+
}
349+
#endif
350+
351+
#endif /* ndef _SHAPEFILE_H_INCLUDED */

‎plugins/gps_importer/shpopen.c

Lines changed: 1623 additions & 0 deletions
Large diffs are not rendered by default.

‎plugins/gps_importer/utils.c

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/* Taken from txt2dbf 1.0.2 by Frank Koormann, see
2+
* http://www.usf.uni-osnabrueck.de/~fkoorman/software/dbftools.en.html
3+
*/
4+
5+
/*
6+
* $Source$
7+
*
8+
* $Author$
9+
*
10+
* $Revision$
11+
*
12+
* Description: utils.c
13+
* collection of useful functions:
14+
* - getline
15+
* - do_nothing
16+
* - tabtok
17+
* explanations see below. *
18+
*
19+
*/
20+
21+
#include "utils.h"
22+
23+
/* getline -------------------------------------------------------------*/
24+
/* reads a line (limited by \n) out of stream fp, returns last
25+
* char, esp eof */
26+
int getline(FILE *fp, char s[] )
27+
{ int c, i;
28+
29+
i=0;
30+
while ( (c=getc(fp))!=EOF && c!='\n' )
31+
s[i++]=c;
32+
s[i]='\0';
33+
return c;
34+
}
35+
36+
/* do_nothing ----------------------------------------------------------*/
37+
/* dto. */
38+
void do_nothing( void )
39+
{
40+
}
41+
42+
/* tabtok --------------------------------------------------------------*/
43+
/* like strtok, breaks a string in sequences delimited by tabs, but do not
44+
* overreads sequences of directly followed tabs: like "\t\t\ttest" is
45+
* divided by strtok into "test" but by tabtok into "", "", "", "test" */
46+
char *tabtok( char *s )
47+
{
48+
static char *b, *e;
49+
50+
if ( s == NULL )
51+
b = e;
52+
else
53+
b = s;
54+
55+
if ( b == NULL )
56+
return b;
57+
else
58+
e = b;
59+
60+
while ( (*e != '\t') && (*e != '\0') )
61+
e++;
62+
63+
if ( *e == '\0' )
64+
e = NULL;
65+
else
66+
*e = '\0', e++;
67+
68+
return b;
69+
}
70+
71+
/* dtok --------------------------------------------------------------*/
72+
/* like strtok, breaks a string in sequences delimited by delim, but do not
73+
* overreads sequences of directly followed delims: like "\t\t\ttest" is
74+
* divided by strtok into "test" but by dtok into "", "", "", "test" */
75+
char *dtok( char *s, char delim )
76+
{
77+
static char *b, *e;
78+
79+
if ( s == NULL )
80+
b = e;
81+
else
82+
b = s;
83+
84+
if ( b == NULL )
85+
return b;
86+
else
87+
e = b;
88+
89+
while ( (*e != delim ) && (*e != '\0') )
90+
e++;
91+
92+
if ( *e == '\0' )
93+
e = NULL;
94+
else
95+
*e = '\0', e++;
96+
97+
return b;
98+
}

‎plugins/gps_importer/utils.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* Taken from txt2dbf 1.0.2 by Frank Koormann, see
2+
* http://www.usf.uni-osnabrueck.de/~fkoorman/software/dbftools.en.html
3+
*/
4+
5+
/*
6+
* $Source$
7+
*
8+
* $Author$
9+
*
10+
* $Revision$
11+
*
12+
* Description: header of utils.c
13+
* collection of useful functions:
14+
* - getline
15+
* - do_nothing
16+
* - tabtok
17+
* explanations see below.
18+
*/
19+
20+
#ifndef __utils__
21+
#define __utils__
22+
23+
#include <stdio.h>
24+
#include <stdlib.h>
25+
#include <string.h>
26+
27+
/* global variables ----------------------------------------------------*/
28+
/* action of a program after evaluating the command line */
29+
#define ABORT 0
30+
#define EVALUATE 1
31+
#define LIST 2
32+
33+
/* function declaration ------------------------------------------------*/
34+
35+
/* getline: reads a line (limited by \n) out of stream fp, returns last
36+
* char, esp eof */
37+
int getline(FILE *fp, char s[]);
38+
39+
/* do_nothing: dto. */
40+
void do_nothing( void );
41+
42+
/* tabtok --------------------------------------------------------------
43+
* like strtok, breaks a string in sequences delimited by tabs, but do not
44+
* overreads sequences of directly followed tabs: like "\t\t\ttest" is
45+
* divided by strtok into "test" but by tabtok into "", "", "", "test" */
46+
char *tabtok( char *s );
47+
48+
/* dtok --------------------------------------------------------------
49+
* like strtok, breaks a string in sequences delimited by delim, but do not
50+
* overreads sequences of directly followed delims: like "\t\t\ttest" is
51+
* divided by strtok into "test", but by dtok into "", "", "", "test" */
52+
char *dtok( char *s , char delim );
53+
54+
#endif
55+
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#include "waypointtoshape.h"
2+
#include <stdio.h>
3+
#include <qtextstream.h>
4+
#include <iostream>
5+
#include <qfileinfo.h>
6+
#include <qstringlist.h>
7+
WayPointToShape::WayPointToShape(QString theOutputFileName, QString theInputFileName )
8+
{
9+
DBFHandle myDbfHandle; /* handle for dBase file */
10+
SHPHandle myShapeHandle; /* handle for shape files .shx and .shp */
11+
/* Open and prepare output files */
12+
myDbfHandle = createDbf(theOutputFileName);
13+
myShapeHandle = createShapeFile(theOutputFileName);
14+
std::cout << "WayPointToShape constructor called with " << theOutputFileName
15+
<< " for output file and " << theInputFileName << " for input file " << std::endl;
16+
//test the write point routine....
17+
generatePoints(theInputFileName,myDbfHandle,myShapeHandle);
18+
19+
DBFClose( myDbfHandle );
20+
SHPClose( myShapeHandle );
21+
return;
22+
}
23+
24+
/* DbfName need not include the file extension. */
25+
DBFHandle WayPointToShape::createDbf (QString theDbfName )
26+
{
27+
DBFHandle myDbfHandle;
28+
//remove the path part of the dbf name
29+
QFileInfo myFileInfo( theDbfName );
30+
QString myBaseString = myFileInfo.baseName(); // excludes any extension
31+
//create the dbf
32+
myDbfHandle = DBFCreate( myBaseString+".dbf" );
33+
//create an index field named after the base part of the file name
34+
35+
DBFAddField( myDbfHandle, myBaseString+"_id", FTInteger, 11, 0 );
36+
//create a second arbitary attribute field
37+
DBFAddField( myDbfHandle, "Date", FTString, 12, 0 );
38+
//close the dbf
39+
DBFClose( myDbfHandle );
40+
//reopen
41+
myDbfHandle = DBFOpen( myBaseString+".dbf", "r+b" );
42+
//exit this fn giving
43+
return myDbfHandle;
44+
}
45+
46+
SHPHandle WayPointToShape::createShapeFile(QString theFileName )
47+
{
48+
SHPHandle myShapeHandle;
49+
myShapeHandle = SHPCreate(theFileName, SHPT_POINT );
50+
return myShapeHandle;
51+
}
52+
53+
void WayPointToShape::writeDbfRecord (DBFHandle theDbfHandle, int theRecordIdInt, QString theLabel)
54+
{
55+
56+
57+
std::cerr << "writeDbfRecord : " << theRecordIdInt << " - " << theLabel;
58+
if (! DBFWriteIntegerAttribute(theDbfHandle, theRecordIdInt, 0, theRecordIdInt))
59+
{
60+
fprintf(stderr, "DBFWriteIntegerAttribute(hDBFs,%d,0,%d) failed.\n", theRecordIdInt, theRecordIdInt );
61+
62+
//exit(ERR_DBFWRITEINTEGERATTRIBUTE);
63+
}
64+
if (! DBFWriteStringAttribute(theDbfHandle, theRecordIdInt, 1, theLabel))
65+
{
66+
fprintf(stderr, "DBFWriteStringAttribute(hDBFs,%d,1,%s) failed.\n", theRecordIdInt, theLabel );
67+
//exit(ERR_DBFWRITEINTEGERATTRIBUTE);
68+
}
69+
std::cerr << " - OK! " << std::endl;
70+
//DBFWriteIntegerAttribute(theDbfHandle, theRecordIdInt, 0, theRecordIdInt);
71+
//DBFWriteStringAttribute(theDbfHandle, theRecordIdInt, 1, theLabel);
72+
}
73+
74+
void WayPointToShape::writePoint(SHPHandle theShapeHandle, int theRecordInt, double theXFloat, double theYFloat )
75+
{
76+
SHPObject * myShapeObject;
77+
myShapeObject = SHPCreateObject( SHPT_POINT, theRecordInt, 0, NULL, NULL, 1, &theXFloat, &theYFloat, NULL, NULL );
78+
SHPWriteObject( theShapeHandle, -1, myShapeObject );
79+
SHPDestroyObject( myShapeObject );
80+
}
81+
/* read from fp and generate point shapefile to theDbfHandle/theShapeHandle */
82+
void WayPointToShape::generatePoints (QString theInputFileName, DBFHandle theDbfHandle, SHPHandle theShapeHandle)
83+
{
84+
QFile myFile( theInputFileName );
85+
if ( myFile.open( IO_ReadOnly ) )
86+
{
87+
QTextStream myStream( &myFile );
88+
QString myLineString;
89+
int myRecordInt = 0;
90+
while ( !myStream.atEnd() )
91+
{
92+
// line of text excluding '\n'
93+
myLineString = myStream.readLine();
94+
//tokenise the line so we can get coords and records
95+
QStringList myQStringList = QStringList::split("\t",myLineString,true);
96+
97+
if (myQStringList.size()==4)
98+
{
99+
QString myDateQString = myQStringList[1];
100+
QString myLatQString = myQStringList[2];
101+
QString myLongQString = myQStringList[3];
102+
103+
//convert items 3 and 4 to lat and long...
104+
//TODO - continue here...
105+
float x=myLongQString.toFloat();
106+
float y=myLatQString.toFloat();
107+
//create the dbf and shape recs
108+
std::cerr << "Writing record: " << myDateQString << " - " << x << " - " << y << std::endl;
109+
writeDbfRecord(theDbfHandle, myRecordInt, myDateQString);
110+
writePoint(theShapeHandle, myRecordInt, x, y);
111+
myRecordInt++;
112+
}
113+
}
114+
myFile.close();
115+
}
116+
}
117+
118+
119+
120+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef _WAYPOINTTOSHAPE_H_
2+
#define _WAYPOINTTOSHAPE_H_
3+
4+
#include "shapefil.h"
5+
#include "utils.h"
6+
7+
//qt includes
8+
#include <qstring.h>
9+
#include <qfile.h>
10+
11+
class WayPointToShape
12+
{
13+
public:
14+
WayPointToShape::WayPointToShape(QString theOutputFileName, QString theInputFileName );
15+
~WayPointToShape() {};
16+
DBFHandle WayPointToShape::createDbf (QString theDbfName ) ;
17+
SHPHandle WayPointToShape::createShapeFile(QString theFileName );
18+
void writeDbfRecord (DBFHandle theDbfHandle, int theRecordIdInt, QString theLabel) ;
19+
void writePoint(SHPHandle theShapeHandle, int theRecordInt, double theXFloat, double y );
20+
void generatePoints (QString theInputFileName, DBFHandle theDbfHandle, SHPHandle theShapeHandle) ;
21+
22+
private:
23+
};
24+
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.