[GRASS-SVN] r60332 - grass-addons/grass6/raster/r.out.mbtiles_prep

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 19 01:24:01 PDT 2014


Author: hamish
Date: 2014-05-19 01:24:01 -0700 (Mon, 19 May 2014)
New Revision: 60332

Modified:
   grass-addons/grass6/raster/r.out.mbtiles_prep/r.out.mbtiles_prep
Log:
add flag to try and create the MBTiles file (not working yet);
drop reset_metadata flag in the mapurl file.


Modified: grass-addons/grass6/raster/r.out.mbtiles_prep/r.out.mbtiles_prep
===================================================================
--- grass-addons/grass6/raster/r.out.mbtiles_prep/r.out.mbtiles_prep	2014-05-19 08:14:15 UTC (rev 60331)
+++ grass-addons/grass6/raster/r.out.mbtiles_prep/r.out.mbtiles_prep	2014-05-19 08:24:01 UTC (rev 60332)
@@ -74,11 +74,16 @@
 #% answer: 225
 #%End
 #%Flag
+#% key: m
+#% description: Create a MBTiles database (requires SQLite3)
+#%End
+#%Flag
 #% key: t
-#% description: Create a tarball
+#% description: Create a tarball of the tile tree
 #%End
 
 
+
 if  [ -z "$GISBASE" ] ; then
    echo "You must be in GRASS GIS to run this program." >&2
    exit 1
@@ -404,7 +409,7 @@
 description=Exported zoom level(s) $ZOOM from GRASS GIS r.out.mbtiles_prep
 defaultzoom=$default_zoom
 format=$ext
-request_type=run,fill,load,reset_metadata
+request_type=run,fill,load
 EOF
 
 cd "$OUT_DIR"
@@ -463,6 +468,66 @@
 mv "$OUT_DIR" "$OUTFILE"
 mv "$OUTFILE"/*.mapurl "$OUTFILE"/..
 
+
+#### Set up SQLite commands to build MBTiles database
+# must use sqlite3+
+if [ "$GIS_FLAG_M" -eq 1 ] ; then
+
+   g.message "Creating SQLite instructions ..."
+
+   if [ ! -x "`which sqlite3`" ] ; then
+      g.message -e "sqlite3 is required for creating the MBTiles database, please install it first."
+      cleanup
+      exit 1
+   fi
+
+   TITLE_CLEAN=`echo "$TITLE" | sed -e "s|'|''|g"`
+
+   cat << EOF > "$TMPFILE.sql"
+CREATE TABLE metadata (name text, value text);
+INSERT INTO metadata VALUES ('name', '`basename "$OUTFILE"`');
+INSERT INTO metadata VALUES ('type', 'baselayer');
+INSERT INTO metadata VALUES ('version', '1');
+INSERT INTO metadata VALUES ('description', '$TITLE_CLEAN');
+INSERT INTO metadata VALUES ('format', '$ext');
+INSERT INTO metadata VALUES ('bounds', '$ll_w,$ll_s,$ll_e,$ll_n');
+CREATE TABLE tiles (zoom_level integer, tile_column integer, tile_row integer, tile_data blob);
+BEGIN TRANSACTION;
+EOF
+
+   (
+   for file in `find "$OUTFILE" -name "*.$ext"` ; do
+      crop=`echo "$file" | sed -e "s|.*$OUTFILE/||" -e "s|\.$ext||"`
+      zoomlevel=`echo "$crop" | cut -f1 -d'/'`
+      column=`echo "$crop" | cut -f2 -d'/'`
+      row=`echo "$crop" | cut -f3 -d'/'`
+
+      echo "INSERT INTO tiles ($zoomlevel, $row, $column, 'X`hexdump -v -e '1/1 "%.2x"' $file`');"
+   done
+   ) > "${TMPFILE}_tiles.sql"
+
+
+   sort -n "${TMPFILE}_tiles.sql" >> "$TMPFILE.sql"
+
+   echo "COMMIT TRANSACTION;" >> "$TMPFILE.sql"
+
+   if [ `wc -l < "${TMPFILE}_tiles.sql"` -gt 65535 ] ; then
+      echo "FIXME: insert some 'COMMIT TRANSACTION; BEGIN TRANSACTION;' inline the sql"
+   fi
+
+   mv "$TMPFILE.sql" "$OUTFILE.sql"
+
+   g.message "Populating SQLite database ..."
+   cat "$OUTFILE.sql" | sqlite3 "$OUTFILE.mbtiles"
+
+fi
+
+
+if [ "$GIS_FLAG_T" -eq 1 ] ; then
+   cd `dirname "$OUTFILE"`
+   tar cf `basename "$OUTFILE"`.tar `basename "$OUTFILE"` `basename "$OUTFILE"`.mapurl
+fi
+
 cleanup
 
 if [ "$GIS_FLAG_T" -eq 1 ] ; then
@@ -470,6 +535,7 @@
    tar cf `basename "$OUTFILE"`.tar `basename "$OUTFILE"` `basename "$OUTFILE"`.mapurl
 fi
 
+
 g.message message=""
 g.message "Done."
 g.message "Next copy the '$OUTFILE' directory and mapurl file to \



More information about the grass-commit mailing list