Skip to content

Instantly share code, notes, and snippets.


Thomas Gratier ThomasG77

View GitHub Profile
ThomasG77 /
Created Jan 25, 2012 — forked from andrewharvey/
Given a WGS84 bounding box and an OSM tile zoom range calculates a total number of tiles.
# This script should be considered CC0 licensed
# the deg2num function is from
import math
def deg2num(lat_deg, lon_deg, zoom):
lat_rad = math.radians(lat_deg)
n = 2.0 ** zoom
xtile = int((lon_deg + 180.0) / 360.0 * n)
ThomasG77 / dict_zip
Last active Jan 22, 2020
Javascript equivalent to python dict(zip(['AB', 'CD', 'EF', 'GH'],[1, 2, 3, 4])) - 2 js arrays to one js object
View dict_zip
var keys = ['AB', 'CD', 'EF', 'GH'];
var values = [1, 2, 3, 4];
// Equivalent to python dict(zip(['AB', 'CD', 'EF', 'GH'],[1, 2, 3, 4])) in javascript
function dictZip(key_array, val_array) {
if (key_array.length === val_array.length) {
return key_array.reduce((acc, curr, index) => {
acc[curr] = val_array[index];
return acc;
}, {});
ThomasG77 /
Created Apr 4, 2012
Orthophotos nantes telecahrgement et decompression
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import requests, re, os
def download_file(url, fileName=None):
def getFileName(url, req):
h = req.headers
file = None;
if h.has_key("content-disposition") and h.get("content-disposition")!= None and 'filename=' in h.get("content-disposition"):
ThomasG77 / liste_ortho_nantes_2005.txt
Created Apr 4, 2012
Liste fichiers orthophotos nantes 2005
View liste_ortho_nantes_2005.txt
ThomasG77 / postgis_geojson.php
Created Sep 21, 2012 — forked from bmcbride/postgis_geojson.php
View postgis_geojson.php
header('Content-Type: application/json; charset=UTF-8');
* PostGIS to GeoJSON
* Query a PostGIS table or view and return the results in GeoJSON format, suitable for use in OpenLayers, Leaflet, etc.
* @param string $geotable The PostGIS layer name *REQUIRED*
* @param string $geomfield The PostGIS geometry field *REQUIRED*
* @param string $srid The SRID of the returned GeoJSON *OPTIONAL (If omitted, EPSG: 4326 will be used)*
* @param string $fields Fields to be returned *OPTIONAL (If omitted, all fields will be returned)* NOTE- Uppercase field names should be wrapped in double quotes
ThomasG77 / index.html
Last active Dec 18, 2015
OpenLayers zoom level display
View index.html
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>OpenLayers Basic OSM Example with zoom level display</title>
<link rel="stylesheet" href="" type="text/css">
<link rel="stylesheet" href="" type="text/css">
ThomasG77 /
Last active Dec 19, 2015
How to deal with renaming invalid UTF8 characters in directories or files
## Reminder to deal with renaming invalid UTF8 characters (if you are using latin-1 also called iso-8859-1)
## Sources:
## To use it, do a chmod +x; and after do ./ your_dir_where_you_want_to_scan_and_rename
# First command to add
grep-invalid-utf8 () {
perl -l -ne '/^([\000-\177]|[\300-\337][\200-\277]|[\340-\357][\200-\277]{2}|[\360-\367][\200-\277]{3}|[\370-\373][\200-\277]{4}|[\374-\375][\200-\277]{5})*$/ or print'
ThomasG77 / dem_eu
Created Nov 30, 2013
Get each individual EU-DEM tiles from with a batch. You need wget (apt-get install wget for Ubuntu/Debian or on Windows go to for installing) After, just do in command-line wget -c -i dem_eu.txt
View dem_eu
ThomasG77 / index.html
Last active Jul 27, 2016
Proj4js conversion using Lambert 93 and the new proj4js API (v2.x)Open your JavaScript console to see the result
View index.html
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>proj4js v2 example </title>
<script src="//" type="text/javascript"></script>
View shapely_benchmarks.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
You can’t perform that action at this time.