-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alfred Sawatzky
committed
Sep 7, 2014
1 parent
2918539
commit 034d9ed
Showing
37 changed files
with
2,025 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
data/ | ||
*.pyc | ||
GoogleDrive-BeeSafe/ | ||
canvass-packages/*.html | ||
canvass-packages/*.png | ||
BeeSafeBoulder.vpp | ||
BeeSafeBoulder.vpp~1 | ||
TileMillProjects/export/ | ||
TileMillProjects/output/ | ||
TileMillProjects/project/test/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
c:\Python27-32bit\python.exe PublicProjectMiller.py | ||
|
||
pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#------------------------------------------------------------------------------- | ||
# Name: ProjectMiller | ||
# Purpose: Generates Asset mbtiles files from a TileMill map. Also uploads the mbtiles. | ||
# | ||
# Author: Alfred | ||
# | ||
# Created: 12/12/2012 | ||
#------------------------------------------------------------------------------- | ||
from TileMill import * | ||
import os | ||
import shutil | ||
|
||
tilemill_dir = r'C:\Program Files (x86)\TileMill-v0.10.1\tilemill' | ||
projectFilesLocation = r'C:\personal\BeeSafeBoulder\TileMillProjects' | ||
|
||
access_account = r'MAPBOX_USERNAME' | ||
access_token = r'MAPBOX_ACCESS_TOKEN' | ||
|
||
# remove the cache directory so that we can use the most recent outage information | ||
# from the internet. | ||
cachePath = os.path.join(projectFilesLocation, 'cache') | ||
if os.path.exists(cachePath): | ||
shutil.rmtree(cachePath) | ||
|
||
output_dir = os.path.join(projectFilesLocation, 'output') | ||
if os.path.exists(output_dir): | ||
shutil.rmtree(output_dir) | ||
|
||
if not os.path.exists(output_dir): | ||
os.mkdir(output_dir) | ||
|
||
tm = TileMill(tilemill_dir) | ||
|
||
|
||
projects = [ | ||
{'projectName': 'BeeSafeBoulderPublic', | ||
'bbox': '-105.6674,39.9098,-105.0558,40.2608', | ||
'minzoom': 0, | ||
'maxzoom': 15} | ||
] | ||
|
||
for project in projects: | ||
name = project['projectName'] | ||
filename = os.path.join(output_dir, '%s.png' % (name)) | ||
tm.render(name, filename, | ||
format='png', | ||
bbox=project['bbox'], | ||
width=400, | ||
height=400, | ||
files=projectFilesLocation) | ||
|
||
filename = os.path.join(output_dir, '%s.mbtiles' % (name)) | ||
|
||
tm.render(name, filename, | ||
format='mbtiles', | ||
bbox=project['bbox'], | ||
minzoom=project['minzoom'], | ||
maxzoom=project['maxzoom'], | ||
metatile=2, | ||
quiet=True, | ||
files=projectFilesLocation) | ||
|
||
tm.modify_metadata(filename, | ||
{'name': name}) | ||
|
||
tm.upload(name, filename, access_account, access_token, files=projectFilesLocation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
cd code | ||
c:\Python27-32bit\python.exe update_pledge_spreadsheet.py | ||
c:\Python27-32bit\python.exe update_neighborhoods_and_blocks.py | ||
c:\Python27-32bit\python.exe create_canvass_packages.py | ||
c:\Python27-32bit\python.exe create_private_maps.py | ||
c:\Python27-32bit\python.exe create_pledge_summary.py | ||
cd .. | ||
c:\Python27-32bit\python.exe PublicProjectMiller.py | ||
|
||
pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# TileMill | ||
|
||
This product contains code for automating TileMill rendering and export. It requires that you have [TileMill](http://mapbox.com/tilemill/) installed on your computer. | ||
|
||
The Python wrapper currently supports rendering a project with `render()`, updating an MBTile file's metadata with `modify_metadata()` and uploading an MBTile file to [MapBox](http://mapbox.com) if you have an account with `upload()`. | ||
|
||
Example of rendering a project to PNG file. | ||
|
||
~~~python | ||
from TileMill import * | ||
|
||
tilemill_dir = r'C:\Program Files (x86)\TileMill-v0.10.1\tilemill' | ||
tm = TileMill(tilemill_dir) | ||
|
||
tilemill_project_name = 'SLO' | ||
tm.render(tilemill_project_name,r'c:\temp\SLO.png', | ||
format='png', | ||
width=400, | ||
height=400) | ||
~~~ | ||
|
||
You can review the code in `iFactorSandbox\python\SLOmap\SLOProjectMiller.py` for an example of rendering to MBTile format and then uploading to a MapBox account. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#------------------------------------------------------------------------------- | ||
# Name: module1 | ||
# Purpose: | ||
# | ||
# Author: Alfred | ||
# | ||
# Created: 12/12/2012 | ||
# Copyright: (c) Alfred 2012 | ||
# Licence: <your licence> | ||
#------------------------------------------------------------------------------- | ||
import subprocess | ||
import os | ||
import sqlite3 | ||
|
||
|
||
class TileMill(): | ||
""" provides wrappers around some TileMill -export commands | ||
""" | ||
|
||
def __init__(self, tilemill_dir): | ||
""" tilemill_dir : directory that contains | ||
""" | ||
self.__tilemill_dir = tilemill_dir | ||
|
||
def __run_export(self, args): | ||
""" runs TileMill's "index.js export" command line | ||
""" | ||
|
||
full_args = ['node.exe', 'index.js', 'export'] | ||
full_args.extend(args) | ||
print " ".join(full_args) | ||
|
||
|
||
print subprocess.call(full_args, shell=True, cwd=self.__tilemill_dir) | ||
|
||
def render(self, project_name, output_file_name, **kwargs): | ||
""" **kwargs are the same as defined in the help for "index.js export" | ||
""" | ||
args = [project_name, output_file_name] | ||
|
||
job_file_name = os.path.splitext(output_file_name)[0] + ".export" | ||
|
||
for key in kwargs: | ||
args.append("--%s=%s" % (key, str(kwargs[key]))) | ||
|
||
args.append("--log") | ||
if os.path.exists(job_file_name): | ||
args.append("--job=%s" % (job_file_name)) | ||
|
||
self.__run_export(args) | ||
|
||
|
||
def upload(self, mapbox_map_id, mbtiles_file_name, sync_account, sync_access_token, files=None): | ||
|
||
args = [mapbox_map_id, | ||
mbtiles_file_name, | ||
'--format=upload', | ||
'--syncAccount=%s' % sync_account, | ||
'--syncAccessToken=%s' % sync_access_token] | ||
|
||
if files is not None: | ||
args.append('--files={}'.format(files)) | ||
|
||
self.__run_export(args) | ||
|
||
def modify_metadata(self, mbtiles_file_name, data): | ||
''' modifies metadata in mbtiles_file_name based on values in DATA dict | ||
''' | ||
conn = sqlite3.connect(mbtiles_file_name) | ||
c = conn.cursor() | ||
|
||
try: | ||
for k in data: | ||
c.execute('REPLACE INTO metadata (name, value) VALUES (?, ?)', (k, data[k])) | ||
|
||
conn.commit() | ||
finally: | ||
c.close() | ||
conn.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#------------------------------------------------------------------------------- | ||
# Name: module1 | ||
# Purpose: | ||
# | ||
# Author: Alfred | ||
# | ||
# Created: 12/12/2012 | ||
# Copyright: (c) Alfred 2012 | ||
# Licence: <your licence> | ||
#------------------------------------------------------------------------------- | ||
import unittest | ||
from TileMill import TileMill | ||
|
||
class TileMillTestCase(unittest.TestCase): | ||
''' | ||
''' | ||
|
||
def test_constructor(self): | ||
tm = TileMill(r'C:\Program Files (x86)\TileMill-v0.10.1\tilemill') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from TileMill import TileMill | ||
|
||
__all__ = ['TileMill'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{"key":"/api/Export/1407202231247","val":{"progress":0,"status":"waiting","id":"1407202231247","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":693,"height":800}} | ||
{"key":"/api/Export/1407202231247","val":{"progress":0,"status":"processing","id":"1407202231247","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":693,"height":800,"pid":270132,"created":1407202355607}} | ||
{"key":"/api/Export/1407202231247","val":{"progress":1,"status":"complete","id":"1407202231247","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":693,"height":800,"pid":270132,"created":1407202355607,"remaining":0,"updated":1407202363529}} | ||
{"key":"/api/Export/1407202538730","val":{"progress":0,"status":"waiting","id":"1407202538730","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":800,"height":914}} | ||
{"key":"/api/Export/1407202538730","val":{"progress":0,"status":"processing","id":"1407202538730","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":800,"height":914,"pid":270964,"created":1407202548977}} | ||
{"key":"/api/Export/1407202538730","val":{"progress":0,"status":"processing","id":"1407202538730","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate_5e16a1.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":800,"height":914,"pid":270964,"created":1407202548977}} | ||
{"key":"/api/Export/1407202538730","val":{"progress":1,"status":"complete","id":"1407202538730","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate_5e16a1.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":800,"height":914,"pid":270964,"created":1407202548977,"remaining":0,"updated":1407202560264}} | ||
{"key":"/api/Export/1407202638740","val":{"progress":0,"status":"waiting","id":"1407202638740","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":1000,"height":1143}} | ||
{"key":"/api/Export/1407202638740","val":{"progress":0,"status":"processing","id":"1407202638740","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":1000,"height":1143,"pid":269428,"created":1407202646433}} | ||
{"key":"/api/Export/1407202638740","val":{"progress":0,"status":"processing","id":"1407202638740","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate_a6624e.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":1000,"height":1143,"pid":269428,"created":1407202646433}} | ||
{"key":"/api/Export/1407202638740","val":{"progress":1,"status":"complete","id":"1407202638740","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate_a6624e.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":1000,"height":1143,"pid":269428,"created":1407202646433,"remaining":0,"updated":1407202652147}} | ||
{"key":"/api/Export/1407202721031","val":{"progress":0,"status":"waiting","id":"1407202721031","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":800,"height":914}} | ||
{"key":"/api/Export/1407202721031","val":{"progress":0,"status":"processing","id":"1407202721031","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":800,"height":914,"pid":267428,"created":1407202729159}} | ||
{"key":"/api/Export/1407202721031","val":{"progress":0,"status":"processing","id":"1407202721031","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate_3d4500.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":800,"height":914,"pid":267428,"created":1407202729159}} | ||
{"key":"/api/Export/1407202721031","val":{"progress":1,"status":"complete","id":"1407202721031","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate_3d4500.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":800,"height":914,"pid":267428,"created":1407202729159,"remaining":0,"updated":1407202740403}} | ||
{"key":"/api/Export/1407202884423","val":{"progress":0,"status":"waiting","id":"1407202884423","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":400,"height":457}} | ||
{"key":"/api/Export/1407202884423","val":{"progress":0,"status":"processing","id":"1407202884423","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":400,"height":457,"pid":270024,"created":1407202889515}} | ||
{"key":"/api/Export/1407202884423","val":{"progress":0,"status":"processing","id":"1407202884423","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate_1cb07d.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":400,"height":457,"pid":270024,"created":1407202889515}} | ||
{"key":"/api/Export/1407202884423"} | ||
{"key":"/api/Export/1407202898149","val":{"progress":0,"status":"waiting","id":"1407202898149","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":800,"height":914}} | ||
{"key":"/api/Export/1407202898149","val":{"progress":0,"status":"processing","id":"1407202898149","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":800,"height":914,"pid":272196,"created":1407202904245}} | ||
{"key":"/api/Export/1407202898149","val":{"progress":0,"status":"processing","id":"1407202898149","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate_12e28d.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":800,"height":914,"pid":272196,"created":1407202904245}} | ||
{"key":"/api/Export/1407202898149","val":{"progress":1,"status":"complete","id":"1407202898149","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate_12e28d.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":800,"height":914,"pid":272196,"created":1407202904245,"remaining":0,"updated":1407202916527}} | ||
{"key":"/api/Export/1407203033711","val":{"progress":0,"status":"waiting","id":"1407203033711","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":800,"height":914}} | ||
{"key":"/api/Export/1407203033711","val":{"progress":0,"status":"processing","id":"1407203033711","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":800,"height":914,"pid":274328,"created":1407203039259}} | ||
{"key":"/api/Export/1407203033711","val":{"progress":0,"status":"processing","id":"1407203033711","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate_ce0b6a.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":800,"height":914,"pid":274328,"created":1407203039259}} | ||
{"key":"/api/Export/1407203033711","val":{"progress":1,"status":"complete","id":"1407203033711","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate_ce0b6a.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":800,"height":914,"pid":274328,"created":1407203039259,"remaining":0,"updated":1407203055814}} | ||
{"key":"/api/Export/1407203248993","val":{"progress":0,"status":"waiting","id":"1407203248993","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":1200,"height":1371}} | ||
{"key":"/api/Export/1407203248993","val":{"progress":0,"status":"processing","id":"1407203248993","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":1200,"height":1371,"pid":271692,"created":1407203267204}} | ||
{"key":"/api/Export/1407203248993","val":{"progress":0,"status":"processing","id":"1407203248993","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate_ee7fbd.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":1200,"height":1371,"pid":271692,"created":1407203267204}} | ||
{"key":"/api/Export/1407203248993","val":{"progress":1,"status":"complete","id":"1407203248993","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate_ee7fbd.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":1200,"height":1371,"pid":271692,"created":1407203267204,"remaining":0,"updated":1407203286058}} | ||
{"key":"/api/Export/1407203343446","val":{"progress":0,"status":"waiting","id":"1407203343446","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":1200,"height":1371}} | ||
{"key":"/api/Export/1407203343446","val":{"progress":0,"status":"processing","id":"1407203343446","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":1200,"height":1371,"pid":267456,"created":1407203348693}} | ||
{"key":"/api/Export/1407203343446","val":{"progress":0,"status":"processing","id":"1407203343446","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate_6f715e.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":1200,"height":1371,"pid":267456,"created":1407203348693}} | ||
{"key":"/api/Export/1407203343446","val":{"progress":1,"status":"complete","id":"1407203343446","format":"png","project":"BeeSafeBoulderPrivate","zooms":[0,22],"metatile":2,"filename":"BeeSafeBoulderPrivate_6f715e.png","bbox":[-105.2619,39.9689,-105.2464,39.9826],"width":1200,"height":1371,"pid":267456,"created":1407203348693,"remaining":0,"updated":1407203363329}} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.