use example sqlite database

This commit is contained in:
Daniel afx 2020-09-29 06:18:26 +03:00
parent 355a9de14b
commit df639773d0
8 changed files with 14058 additions and 5 deletions

35
databases/populatedb.py Normal file
View file

@ -0,0 +1,35 @@
from xml.etree import ElementTree as ET
import sys
import sqlite_utils
KML = "{http://www.opengis.net/kml/2.2}"
def iterate_kml(filepath):
fp = open(filepath)
parser = ET.XMLPullParser(["end"])
while True:
chunk = fp.read(1024 * 8)
parser.feed(chunk)
for event, element in parser.read_events():
assert event == "end"
if element.tag == f"{KML}Placemark":
name = element.find(f".//{KML}name").text
description = 'soon'
#description = element.find(f".//{KML}description").text
longitude, latitude, unknown = map(
float, element.find(f".//{KML}coordinates").text.split(",")
)
yield {
"name": name,
"x": latitude,
"y": longitude,
"description": description,
}
if not chunk:
break
if __name__ == "__main__":
db = sqlite_utils.Database("trees.db")
db["locations"].insert_all(iterate_kml(sys.argv[-1]))

BIN
databases/trees.db Normal file

Binary file not shown.

13980
databases/trees.kml Normal file

File diff suppressed because it is too large Load diff

View file

@ -9,9 +9,9 @@
on_zoom:
self.zoom = 15 if self.zoom < 15 else self.zoom
on_lat:
pass
self.start_get_fov_trees()
on_lon:
pass
self.start_get_fov_trees()
GpsBlinker:
lat: root.lat
lon: root.lon

View file

@ -1,4 +1,31 @@
from kivy.garden.mapview import MapView
from kivy.clock import Clock
from kivy.app import App
class ForestMapView(MapView):
get_trees_timer = None
def start_get_fov_trees(self):
# After one second get the trees in field of view
try:
self.get_trees_timer.cancel()
except:
pass
self.get_trees_timer = Clock.schedule_once(self.get_fov_trees, 1)
def get_fov_trees(self, *args):
# Get reference to main app and the db cursor
app = App.get_running_app()
print(self.get_bbox()) # debug gps position
min_lat, min_lon, max_lat, max_lon = self.get_bbox()
sql_statement = "SELECT * FROM trees WHERE x > %s AND x < %s and y> %s AND Y < %s" % (min_lon, max_lon, min_lat, max_lat)
app.cursor.execute(sql_statement)
trees = app.cursor.fetchall()
print(trees)
for tree in trees:
self.add_tree(tree)
def add_tree(self, tree):
pass

13
main.py
View file

@ -1,10 +1,10 @@
# Import system modules
from random import randrange
import sqlite3
# Import Kivy modules
#from kivy.app import App
from kivy.app import App
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen, ScreenManager
@ -59,9 +59,18 @@ class MainApp(App):
#return SampleBoxLayout()
def on_start(self):
#Initialize GPS
connection = None
cursor = None
# Initialize GPS
GpsHelper().run()
# Connect to database
self.connection = sqlite3.connect("forest.db")
self.cursor = self.connection.cursor()
# Instantiate SearchPopupMenu
if __name__ == '__main__':
#screen_manager = ScreenManager()
#screen_manager.add_widget(ScreenOne(name="screen_one"))

View file

@ -1,4 +1,5 @@
ffpyplayer
sqlite_utils
Kivy
Kivy-examples
kivymd

View file

@ -12,6 +12,7 @@ sudo apt-get install -y \
python3-pip \
python3-dev \
ffmpeg \
sqlite3 \
libtinfo5 \
libffi-dev \
libssl-dev \