Skip to content

Instantly share code, notes, and snippets.

View DenisCarriere's full-sized avatar
🎯
Focusing

Denis DenisCarriere

🎯
Focusing
View GitHub Profile
# pip install geocoder
# param: short_name (Default is True)
# param: method (Default is 'Geocode')
> import geocoder
> g = geocoder.google('41.34168 -8.71202', method='reverse', short_name=False)
'<[OK] Google - Reverse [IC1, 4480, Portugal]>'
> g.latlng
[41.344931, -8.7123075]
> g.country
'Portugal'
@DenisCarriere
DenisCarriere / ottawa_geocode.py
Created January 11, 2015 00:04
City of Ottawa Geocode
import requests
url = 'http://maps.ottawa.ca/ArcGIS/rest/services/compositeLocator/GeocodeServer/findAddressCandidates'
params = {
'SingleLine': '190 Forward Avenue',
'f': 'json',
'outSR': 4326,
}
r = requests.get(url, params=params)
@DenisCarriere
DenisCarriere / Read_CSV.py
Created February 18, 2015 12:59
Reading CSV file
import csv
"""
filename.csv
============
first,second
hello,world
"""
# Standard CSV Reading
@DenisCarriere
DenisCarriere / gist:ae18f7a6ce1400902dfb
Last active August 29, 2015 14:24
Using Geonames
# Geocoding with Geonames in Python
>>> import geocoder
>>> g = geocoder.geonames("Museo Nacional de Antropología")
>>> g.json
{'address': 'Museo Nacional de Antropologia - INAH',
'code': 'MUS',
'country': 'Mexico',
'description': 'museum',
@DenisCarriere
DenisCarriere / starts_with_number.py
Last active October 13, 2015 22:45
QGIS Field Calculator - Starts with number?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
QGIS Field Calculator - Starts with number?
QGIS Version: 1.8.3
Created by: Denis Carriere
Function Editor
@DenisCarriere
DenisCarriere / Read_Shapefile.py
Last active October 16, 2015 02:55
Read attributes as Dictionary
#!/usr/bin/python
# coding: utf8
import shapefile
# pip install pyshp
def process(infile):
shp = shapefile.Reader(infile)
# Get rid of extra garbage in field list
@DenisCarriere
DenisCarriere / cli.py
Last active October 16, 2015 15:32
How to start your first Command Line Interface with Python
#!/usr/bin/python
# encoding: utf8
import click
import logging
@click.command()
@click.argument('infile', nargs=-1)
@click.option('--out', '-o')
@DenisCarriere
DenisCarriere / esri_map.js
Last active October 27, 2015 15:00
WMS with Javascript API for ESRI
var wmsAddress = "http://some.server.com/wms";
var map, srs, extent;
require(["esri/map",
"esri/layers/WMSLayer",
"esri/layers/WMSLayerInfo",
"esri/geometry/Extent",
"esri/geometry/Point",
"esri/SpatialReference",
"dojo/domReady!"],
@DenisCarriere
DenisCarriere / cache.py
Created October 27, 2015 22:31
Future feature in Geocoder Caching
#!/usr/bin/python
# coding: utf8
import json
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, String, Integer, Float, Boolean, Sequence
from sqlalchemy.orm import sessionmaker
Base = declarative_base()
@DenisCarriere
DenisCarriere / bad_shapefile.md
Last active March 20, 2017 21:12
Bad things with Shapefiles

Bad Shapefiles

Here's a list of bad things that are related to shapefiles

  • There is a 2 GB size limit for any shapefile component file, which translates to a maximum of roughly 70 million point features.
  • Shapefiles do not contain an XY tolerance.
  • A shapefile may take up three to five times as much space as a file geodatabase or SDE because of shape compression methods.
  • Field names cannot be longer than 10 characters.
  • The maximum number of fields is 255