Git Product home page Git Product logo

django-gheat's People

Contributors

robertrv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

django-gheat's Issues

Adding management command to pre-generate tiles

This management command can be used to pre-generate tiles for a given bounding box in order to save CPU when running the app later on...

Must be given a bounding box by using options -s and -e (start and end)

Example usage:

python manage.py generate_tiles -s 60,6 -e 66,8 -z 10 -c firetrans -v serve_tile

Requires the globalmaptiles.py file. Get it from
http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/globalmaptiles.py

Note: This command will NOT create tiles if they are empty. In order to do so, change
the gheat generate_tile view so that it creates empty tiles for each request given
x and y and zoom. This way you wan't have "holes" in the tile overlay if using
the static tiles instead of the usual django url/view.

###############################################################################
#Management command to generate tiles using gheat.
#
#Must be given a bounding box by using options -s and -e (start and end)
#
#Example usage:
#>>> python manage.py generate_tiles -s 60,6 -e 66,8 -z 10 -c firetrans -v serve_tile
#
#Requires the globalmaptiles.py file. Get it from
#http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/globalmaptiles.py
#
#Note: This command will NOT create tiles if they are empty. In order to do so, change
#the gheat generate_tile view so that it creates empty tiles for each request given
#x and y and zoom. This way you wan't have "holes" in the tile overlay if using
#the static tiles instead of the usual django url/view.
#
#Author: Anders Eriksen
###############################################################################



from django.core.management.base import BaseCommand
from optparse import OptionParser, make_option
from django.core.urlresolvers import reverse
from django.test.client import Client
from gheat.globalmaptiles import *


class Command(BaseCommand):

    option_list = BaseCommand.option_list + (
        make_option("-v", "--tileview", dest="viewname", default="serve_tile"),
        make_option("-z", "--zoom", dest="zoomlevel", default=1),
        make_option("-s", "--start", dest="start", default="60,6"),
        make_option("-e", "--end", dest="end", default="62,6"),
        make_option("-c", "--colorscheme", dest="color", default="fire"),
    )

    def handle(self, *args, **options):

        profile = 'mercator'
        zoomlevel = None
        lat, lon, latmax, lonmax, baseurl = None, None, None, None, None
        boundingbox = False

        start = options['start'].split(',')
        end = options['end'].split(',')
        viewname = options['viewname']
        colorscheme = str(options['color'])

        #create bounding box from start latlon and end latlon
        boundingbox = (float(start[0]), float(start[1]), float(end[0]), float(end[1]))

        tz = int(options['zoomlevel'])
        mercator = GlobalMercator()

        #calculate start tiles
        mx, my = mercator.LatLonToMeters(float(start[0]), float(start[1]))
        tminx, tminy = mercator.MetersToTile(mx, my, tz)

        #calculate end tiles
        mx, my = mercator.LatLonToMeters(float(end[0]), float(end[1]))
        tmaxx, tmaxy = mercator.MetersToTile(mx, my, tz)

        #initialize browser client
        c = Client()

        #loop through each tile and generate a request to the serve_tile view using Client
        for ty in range(tminy, tmaxy+1):
            for tx in range(tminx, tmaxx+1):

                tileurl = reverse(viewname, kwargs={'color_scheme': colorscheme, 'zoom':tz, 'x':tx, 'y':ty})

                generate_response = c.get(tileurl)

                #lousy error handling. Should check why status 200 not returned... I.e. wrong colorscheme
                if generate_response.status_code == 200:
                    print "Generated tile " + tileurl
                else:
                    print "Failed generating tile " + tileurl

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.