Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into migurski/extend-py3…
Browse files Browse the repository at this point in the history
…hotfix
  • Loading branch information
migurski committed Jun 10, 2018
2 parents b8fd11b + 69a8171 commit 335d30e
Show file tree
Hide file tree
Showing 21 changed files with 390 additions and 414 deletions.
27 changes: 14 additions & 13 deletions README.md
@@ -1,4 +1,4 @@
#TileStache
# TileStache

_a stylish alternative for caching your map tiles_

Expand All @@ -9,7 +9,7 @@ based on rendered geographic data. You might be familiar with [TileCache](http:/
the venerable open source WMS server from MetaCarta. TileStache is similar, but we hope
simpler and better-suited to the needs of designers and cartographers.

##Synopsis
## Synopsis

import TileStache
import ModestMaps
Expand All @@ -33,34 +33,35 @@ simpler and better-suited to the needs of designers and cartographers.



##Dependencies
## Dependencies

###Required:
### Required:

- ModestMaps: http://modestmaps.com, http://github.com/migurski/modestmaps-py
- Python Imaging Library (Pillow): https://python-pillow.org

###Optional:
### Optional:

- Simplejson: https://github.com/simplejson/simplejson (optional if using >= python 2.6)
- mapnik: http://mapnik.org (optional)
- werkzeug: http://werkzeug.pocoo.org/ (optional)
- mapbox-vector-tile: https://github.com/tilezen/mapbox-vector-tile (optional if using TileStache.Goodies.VecTiles:Provider)

Install the pure python modules with pip:

sudo pip install -U python-pil modestmaps simplejson werkzeug uuid
sudo pip install -U pillow modestmaps simplejson werkzeug uuid mapbox-vector-tile

Install pip (http://www.pip-installer.org/) like:

curl -O -L https://raw.github.com/pypa/pip/master/contrib/get-pip.py
curl -O -L https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

Install Mapnik via instructions at:

http://mapnik.org/pages/downloads.html


##Installation
## Installation

TileStache can be run from the download directory as is. For example the scripts:

Expand All @@ -78,7 +79,7 @@ To install globally do:
to fully install TileStache.


##Quickstart
## Quickstart

To make sure TileStache is working start the development server:

Expand All @@ -92,14 +93,14 @@ This is a previewer that uses ModestMaps and OpenStreetMap tiles from
http://tile.osm.org as defined in the default config file 'tilestache.cfg'


##Documentation
## Documentation

The next step is to learn how build custom layers and serve them.

See the [docs](http://tilestache.org/doc/) for details.


##Features
## Features

Rendering providers:
* Mapnik
Expand All @@ -114,7 +115,7 @@ Caching backends:
* S3


##Design Goals
## Design Goals

The design of TileStache focuses on approachability at the expense of
cleverness or completeness. Our hope is to make it easy for anyone to design
Expand Down Expand Up @@ -147,6 +148,6 @@ necessary to support any external system, but we eschew complex, impenetrable
standards in favor of pragmatic, fast utility with basic web clients.


##License
## License

BSD, see LICENSE file.
12 changes: 1 addition & 11 deletions TileStache/Config.py
Expand Up @@ -61,17 +61,7 @@
import sys
import logging
from os.path import join as pathjoin
try:
from urllib.parse import urljoin, urlparse
except ImportError:
# Python 2
from urlparse import urljoin, urlparse
from mimetypes import guess_type
try:
from urllib.request import urlopen
except ImportError:
# Python 2
from urllib import urlopen
from json import dumps

try:
Expand All @@ -88,7 +78,7 @@
from . import Geography
from . import PixelEffects

from . import reduce
from .py3_compat import reduce, urljoin, urlparse, urlopen

class Configuration:
""" A complete site configuration, with a collection of Layer objects.
Expand Down
14 changes: 4 additions & 10 deletions TileStache/Core.py
Expand Up @@ -146,16 +146,10 @@
import logging
from sys import modules
from wsgiref.headers import Headers
try:
from io import BytesIO
except ImportError:
# Python 2
from StringIO import StringIO as BytesIO
try:
from urllib.parse import urljoin
except ImportError:
# Python 2
from urlparse import urljoin
from io import BytesIO

from .py3_compat import urljoin

from time import time

from .Pixels import load_palette, apply_palette, apply_palette256
Expand Down
51 changes: 22 additions & 29 deletions TileStache/Goodies/AreaServer.py
Expand Up @@ -2,97 +2,90 @@
that implement renderArea() (http://tilestache.org/doc/#custom-providers).
The built-in Mapnik provider (http://tilestache.org/doc/#mapnik-provider)
is one example.
There are no tiles here, just a quick & dirty way of getting variously-sized
images out of a codebase that's ordinarily oriented toward tile generation.
Example usage, with gunicorn (http://gunicorn.org):
gunicorn --bind localhost:8888 "TileStache.Goodies.AreaServer:WSGIServer('tilestache.cfg')"
AreaServer URLs are compatible with the built-in URL Template provider
(http://tilestache.org/doc/#url-template-provider) and implement a generic
kind of WMS (http://en.wikipedia.org/wiki/Web_Map_Service).
All six URL parameters shown in this example are required; any other
URL parameter is ignored:
http://localhost:8888/layer-name?width=600&height=600&xmin=-100&ymin=-100&xmax=100&ymax=100
"""

try:
from urllib.parse import parse_qsl
except ImportError:
# Python 2
from urlparse import parse_qsl
from datetime import timedelta
from datetime import datetime
try:
from io import StringIO
except ImportError:
# Python 2
from StringIO import StringIO
from io import BytesIO

from TileStache.py3_compat import parse_qsl

from TileStache import WSGITileServer
from TileStache.Core import KnownUnknown

class WSGIServer (WSGITileServer):
""" WSGI Application that can handle WMS-style requests for static images.
Inherits the constructor from TileStache WSGI, which just loads
a TileStache configuration file into self.config.
WSGITileServer autoreload argument is ignored, though. For now.
"""
def __call__(self, environ, start_response):
""" Handle a request, using PATH_INFO and QUERY_STRING from environ.
There are six required query string parameters: width, height,
xmin, ymin, xmax and ymax. Layer name must be supplied in PATH_INFO.
"""
try:
for var in 'QUERY_STRING PATH_INFO'.split():
if var not in environ:
raise KnownUnknown('Missing "%s" environment variable' % var)

query = dict(parse_qsl(environ['QUERY_STRING']))

for param in 'width height xmin ymin xmax ymax'.split():
if param not in query:
raise KnownUnknown('Missing "%s" parameter' % param)

layer = environ['PATH_INFO'].strip('/')
layer = self.config.layers[layer]
provider = layer.provider

if not hasattr(provider, 'renderArea'):
raise KnownUnknown('Layer "%s" provider %s has no renderArea() method' % (layer.name(), provider.__class__))

width, height = [int(query[p]) for p in 'width height'.split()]
xmin, ymin, xmax, ymax = [float(query[p]) for p in 'xmin ymin xmax ymax'.split()]

#
# Don't supply srs or zoom parameters, which may cause problems for
# some providers. TODO: add optional support for these two parameters.
#
output = StringIO()

output = BytesIO()
image = provider.renderArea(width, height, None, xmin, ymin, xmax, ymax, None)
image.save(output, format='PNG')

headers = [('Content-Type', 'image/png')]

if layer.allowed_origin:
headers.append(('Access-Control-Allow-Origin', layer.allowed_origin))

if layer.max_cache_age is not None:
expires = datetime.utcnow() + timedelta(seconds=layer.max_cache_age)
headers.append(('Expires', expires.strftime('%a %d %b %Y %H:%M:%S GMT')))
headers.append(('Cache-Control', 'public, max-age=%d' % layer.max_cache_age))

start_response('200 OK', headers)
return output.getvalue()

except KnownUnknown, e:
start_response('400 Bad Request', [('Content-Type', 'text/plain')])
return str(e)
3 changes: 2 additions & 1 deletion TileStache/Goodies/ExternalConfigServer.py
Expand Up @@ -6,14 +6,15 @@
gunicorn --bind localhost:8888 "TileStache.Goodies.ExternalConfigServer:WSGIServer(url)"
"""

from urllib import urlopen
import logging

try:
from json import load as json_load
except ImportError:
from simplejson import load as json_load

from TileStache.py3_compat import urlopen

import TileStache

class DynamicLayers:
Expand Down
4 changes: 2 additions & 2 deletions TileStache/Goodies/VecTiles/mvt.py
Expand Up @@ -83,9 +83,9 @@ def encode(file, features):

parts.extend([_pack('>I', len(wkb)), wkb, _pack('>I', len(prop)), prop])

body = _compress(_pack('>I', len(features)) + ''.join(parts))
body = _compress(_pack('>I', len(features)) + b''.join(parts))

file.write('\x89MVT')
file.write(b'\x89MVT')
file.write(_pack('>I', len(body)))
file.write(body)

Expand Down

0 comments on commit 335d30e

Please sign in to comment.