Skip to content

Commit cb1133b

Browse files
committed
add spatial check on startup
1 parent 5447d26 commit cb1133b

12 files changed

Lines changed: 60 additions & 23 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Please refer to [INSTALLATION.md](https://github.com/semuconsulting/PyGPSClient/
106106
1. Show Unused Satellites - Include or exclude satellites that are not used in the navigation solution (e.g. because their signal level is too low) from the graph and sky view panels.
107107
1. DataLogging - Turn Data logging in the selected format on or off. On first selection, you will be prompted to select the directory into which timestamped log files are saved.
108108
1. GPX Track - Turn track recording (in GPX format) on or off. On first selection, you will be prompted to select the directory into which timestamped GPX track files are saved.
109-
1. Database - Turn spatialite database recording (*where available*) on or off. On first selection, you will be prompted to select the directory into which the `pygpsclient.sqlite` database is saved. Note that, when first created, the database's spatial metadata will take a few seconds to initialise. **NB** This facility is dependent on your Python environment supporting the requisite sqlite3 `mod_spatialite` extension - see [INSTALLATION.md](https://github.com/semuconsulting/PyGPSClient/blob/master/INSTALLATION.md#prereqs) for further details.
109+
1. Database - Turn spatialite database recording (*where available*) on or off. On first selection, you will be prompted to select the directory into which the `pygpsclient.sqlite` database is saved. Note that, when first created, the database's spatial metadata will take a few seconds to initialise (*up to a minute on Raspberry Pi and similar SBC*). **NB** This facility is dependent on your Python environment supporting the requisite [sqlite3 `mod_spatialite` extension](https://www.gaia-gis.it/fossil/libspatialite/index) - see [INSTALLATION.md](https://github.com/semuconsulting/PyGPSClient/blob/master/INSTALLATION.md#prereqs) for further details. If not supported, the option will be greyed out. Check the Menu..Help..About dialog for an indication of the current spatialite support status.
110110
1. To save the current configuration to a file, go to File..Save Configuration.
111111
1. To load a saved configuration file, go to File..Load Configuration. The default configuration file location is `$HOME/pygpsclient.json`. **NB** Any active serial or RTK connection must be stopped before loading a new configuration.
112112

3.62 MB
Loading
-3.24 MB
Binary file not shown.

examples/libspatialite_compile.sh

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/bin/bash
22

33
# bash shell script to compile and install libspatialite
4-
# (mod_spatialite.so) on platforms which do not include a suitable
5-
# binary in their standard repos (e.g. Raspberry Pi OS).
4+
# (mod_spatialite.so) on Debian Linux platforms which do not
5+
# include a suitable binary in their standard repos
6+
# (e.g. Raspberry Pi OS).
67
#
78
# Remember to run chmod +x libspatialite_compile.sh to make this script executable.
89
#
@@ -14,20 +15,45 @@
1415
# exit on error
1516
set -e
1617

17-
# install build dependencies (we'll omit the freexl dependency)
18-
sudo apt install libspatial-dev
18+
# install build dependencies if required and available (we'll omit the freexl dependency)
19+
sudo apt install libspatial-dev || true
20+
sudo apt install libproj-dev || true
21+
sudo apt install libgdal-dev || true
22+
sudo apt install libgeos-dev || true
1923
# download and unzip source code
2024
wget https://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-5.1.0.tar.gz
2125
tar zxvf libspatialite-5.1.0.tar.gz
2226
cd libspatialite-5.1.0
2327
# compile source and install - this will take several minutes
28+
# aarch64-unknown-linux-gnu is appropriate for ARM-based SBC platforms like RPi
2429
./configure --build=aarch64-unknown-linux-gnu --enable-freexl=no
2530
make
2631
sudo make install-strip
2732

2833
# typically installs mod_spatialite.so to /usr/local/lib, which
2934
# must be added to the LD_LIBRARY_PATH environment variable:
3035
#
31-
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
36+
export LD_LIBRARY_PATH=/usr/local/lib
3237

3338
# make this permanent via your .bashrc or .zshrc shell profile
39+
echo "Adding directory to PATH..."
40+
BASHPROF1=$HOME/.profile
41+
BASHPROF2=$HOME/.bashrc
42+
ZSHPROF1=$HOME/.zprofile
43+
ZSHPROF2=$HOME/.zshrc
44+
if test -f $BASHPROF1
45+
then
46+
PROF=$BASHPROF1
47+
elif test -f $BASHPROF2
48+
then
49+
PROF=$BASHPROF2
50+
fi
51+
if test -f $ZSHPROF1
52+
then
53+
PROF=$ZSHPROF1
54+
elif test -f $ZSHPROF2
55+
then
56+
PROF=$ZSHPROF2
57+
fi
58+
sed -i '$a# Path to mod_spatialite.so\nexport LD_LIBRARY_PATH=/usr/local/lib' $PROF
59+
source $PROF # this will throw an error if running as bash script in zsh shell

examples/pygpsclient_debian_install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ EOF
5151

5252
echo "Adding directory to PATH..."
5353
BASHPROF1=$HOME/.profile
54-
BASHPROF2=$HOME/.bash_rc
54+
BASHPROF2=$HOME/.bashrc
5555
ZSHPROF1=$HOME/.zprofile
5656
ZSHPROF2=$HOME/.zshrc
5757
if test -f $BASHPROF1

examples/python_compile.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ sudo apt install build-essential gdb lcov pkg-config \
4949
libbz2-dev libffi-dev libgdbm-dev libgdbm-compat-dev \
5050
libncurses5-dev libreadline6-dev libsqlite3-dev libssl-dev \
5151
lzma tk-dev uuid-dev zlib1g-dev -y
52-
sudo apt install liblzma-dev -y
52+
sudo apt install liblzma-dev || true
5353
# liblzma-dev may be lzma-dev on some platforms
54-
# sudo apt install lzma-dev -y
55-
sudo apt install libspatialite -y
54+
sudo apt install lzma-dev || true
55+
sudo apt install libspatialite || true
5656
# libspatialite may not be available as standard on some platforms
5757
# (e.g. Rasperry PI OS) but it is relatively straightforward to
5858
# compile from source using the libspatialite_compile.sh script

images/app.png

-7.25 KB
Loading

pygpsclient.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"mapzoom_disabled_b": 0,
4141
"gpxmaptype_s": "custom",
4242
"gpxmapzoom_n": 10,
43+
"gpxtype_s": "track",
4344
"showtrack_b": 0,
4445
"legend_b": 1,
4546
"unusedsat_b": 0,

src/pygpsclient/about_dialog.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
SPONSOR_URL,
4040
)
4141
from pygpsclient.helpers import check_latest
42-
from pygpsclient.sqllite_handler import DBINMEM, SQLVER
4342
from pygpsclient.strings import ABOUTTXT, COPYRIGHTTXT, DLGTABOUT, GITHUB_URL
4443
from pygpsclient.toplevel_dialog import ToplevelDialog
4544

@@ -100,10 +99,9 @@ def _body(self):
10099
borderwidth=0,
101100
)
102101
tkv = Tcl().call("info", "patchlevel")
103-
spv = self.__app.sqlite_handler.open(dbname=DBINMEM)
104102
self._lbl_python_version = Label(
105103
self._frm_body,
106-
text=f"Python: {python_version()} Tk: {tkv} Spatial: {spv}",
104+
text=f"Python: {python_version()} Tk: {tkv} Spatial: {self.__app.db_enabled}",
107105
)
108106
self._lbl_lib_versions = []
109107
for nam, ver in LIBVERSIONS.items():

src/pygpsclient/app.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
from pygpsclient.nmea_handler import NMEAHandler
8787
from pygpsclient.rtcm3_handler import RTCM3Handler
8888
from pygpsclient.sbf_handler import SBFHandler
89-
from pygpsclient.sqllite_handler import SQLOK, SqliteHandler
89+
from pygpsclient.sqllite_handler import DBINMEM, SQLOK, SqliteHandler
9090
from pygpsclient.stream_handler import StreamHandler
9191
from pygpsclient.strings import (
9292
CONFIGERR,
@@ -179,10 +179,11 @@ def __init__(self, master, **kwargs): # pylint: disable=too-many-statements
179179
self._last_gui_update = datetime.now()
180180
self._socket_thread = None
181181
self._socket_server = None
182-
self.database_enabled = False
183182
self._colcount = 0
184183
self._rowcount = 0
185184
self._consoledata = []
185+
# check if platform supports spatialite database
186+
self.db_enabled = self.sqlite_handler.open(dbname=DBINMEM)
186187

187188
# load config from json file
188189
configfile = kwargs.pop("config", CONFIGFILE)
@@ -221,7 +222,11 @@ def __init__(self, master, **kwargs): # pylint: disable=too-many-statements
221222

222223
# open database if database recording enabled
223224
dbpath = self.configuration.get("databasepath_s")
224-
if self.configuration.get("database_b") and dbpath != "":
225+
if (
226+
self.db_enabled == SQLOK
227+
and self.configuration.get("database_b")
228+
and dbpath != ""
229+
):
225230
rc = self.sqlite_handler.open(dbpath=dbpath)
226231
self.configuration.set("database_b", rc == SQLOK)
227232

@@ -417,7 +422,8 @@ def set_connection(self, message, color=OKCOL):
417422
418423
"""
419424

420-
self.frm_status.set_connection(message, color=color)
425+
if hasattr(self, "frm_status"):
426+
self.frm_status.set_connection(message, color=color)
421427

422428
def set_status(self, message, color=OKCOL):
423429
"""
@@ -428,9 +434,10 @@ def set_status(self, message, color=OKCOL):
428434
429435
"""
430436

431-
color = INFOCOL if color == "blue" else color
432-
self.frm_status.set_status(message, color)
433-
self.update_idletasks()
437+
if hasattr(self, "frm_status"):
438+
color = INFOCOL if color == "blue" else color
439+
self.frm_status.set_status(message, color)
440+
self.update_idletasks()
434441

435442
def set_event(self, evt: str):
436443
"""

0 commit comments

Comments
 (0)