Skip to Content
Bioinformatics with Python Cookbook - Second Edition
book

Bioinformatics with Python Cookbook - Second Edition

by Tiago Antao
November 2018
Intermediate to advanced
360 pages
9h 36m
English
Packt Publishing
Content preview from Bioinformatics with Python Cookbook - Second Edition

How to do it...

Let's take a look at the following steps:

  1. First, let's define a function to get a map tile (a PNG image of size 256 x 256) from OpenStreetMap. We will also define a function to convert geographical coordinate systems to tile indexes, as shown in the following code:
import mathimport requestsdef get_osm_tile(x, y, z):    url = 'http://tile.openstreetmap.org/%d/%d/%d.png' % (z, x, y)    req = requests.get(url)    if not req.ok:        req.raise_for_status()    return reqdef deg_xy(lat, lon, zoom):    lat_rad = math.radians(lat)    n = 2 ** zoom    x = int((lon + 180) / 360 * n)    y = int((1 - math.log(math.tan(lat_rad) + (1 /    math.cos(lat_rad))) / math.pi) / 2 * n)    return x, y

This code is responsible for getting a tile from the OpenStreetMap server, which ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Bioinformatics with Python Cookbook

Bioinformatics with Python Cookbook

Tiago Antao

Publisher Resources

ISBN: 9781789344691Supplemental Content