Commits

Jason Scheirer committed ab4a124

Log to output/

Comments (0)

Files changed (2)

+#! /usr/bin/env python
+
+import json
+import os
+import sqlite3
+import sys
+
+def usage(name):
+    print "Usage: %s insqldb outgeojson" % name
+
+def main(infile, outfile):
+    print "Converting %s..." % infile
+    conn = sqlite3.connect(infile)
+    conn.text_factory = sqlite3.OptimizedUnicode
+    conn.row_factory = sqlite3.Row
+    cursor = conn.execute("select lat, lon, timestamp, hwaddress, ssid,"
+            "strength from networks")
+    features = []
+    out_structure = { 'type': 'FeatureCollection', 'features': features }
+    for row in cursor:
+        featurerow = {  'type': 'Feature', 
+                        'geometry': {'type': 'Point', 
+                                     'coordinates': [row['lon'], row['lat']]},
+                        'properties': {'timestamp': row['timestamp'],
+                                       'ssid': row['ssid'],
+                                       'hwaddress': row['hwaddress'],
+                                       'strength': row['strength']}
+                     }
+        features.append(featurerow)
+    with open(outfile, 'w') as fh:
+        json.dump(out_structure, fh)
+
+if __name__ == "__main__":
+    if len(sys.argv) != 3:
+        usage(sys.argv[0])
+    else:
+        main(*sys.argv[1:3])
+#! /bin/bash
+
+basefilename=$(date +%Y-%m-%d-%H:%M:%S%Z)
+
+echo Creating $basefilename.geojson
+
+if [ ! -e ./output ]
+then
+	mkdir ./output
+fi
+
+./log2geojson.py gpslog.sqlite output/$basefilename.geojson
+
+if [ -f ./output/$basefilename.geojson ]
+then
+    echo Converting to shp
+    ogr2ogr ./output/$basefilename.shp ./output/$basefilename.geojson
+    if [ -f ./output/$basefilename.shp ]
+    then
+	    rm output/$basefilename.geojson
+    else
+	    echo Failed creating shapefile! Geojson file $basefilename.geojson kept.
+    fi
+else
+    echo Failed creating geojson!
+fi