Skip to content

Instantly share code, notes, and snippets.

View bmoregeo's full-sized avatar

Christopher Fricke bmoregeo

View GitHub Profile
@bmoregeo
bmoregeo / gist:8927619
Last active August 29, 2015 13:56
Install CartoDB on Ubuntu 11.10. Use https://github.com/lordlinus/cartodb as a template
# Install PostGIS
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" >> /etc/apt/sources.list'
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install Postgresql-9.3-postgis postgresql-contrib
sudo -u postgres psql
# > CREATE EXTENSION adminpack;
# > \q
@bmoregeo
bmoregeo / ConfigObjDemo1
Last active August 29, 2015 14:01
Python Config Files with ConfigObj
# Set values using the '='.
# Text will default to strings url = http://testing/arcgis/rest/awesometest/MapServer
# Unless it looks like an integer threads = 1
# or a floating point value = 510.128
# If you put brackets around something, that makes it
# a section. The text inside the bracket is the section header [data]
# To create a sub-section, just add another bracket.
# I like to tab these suckers out to make it legible.
name = "example"
@bmoregeo
bmoregeo / ConfigObjDemo2
Last active August 29, 2015 14:01
Python Config Files with ConfigObj
# Import the ConfigObj library
from configobj import ConfigObj
# Parse the configuration file using ConfigObj
config = ConfigObj(filename)
# The ConfigObj library parses the configuration file as a
# python dictionary. Super Cool!
# This means you can do things like this -
@bmoregeo
bmoregeo / gist:352b049757f161e98df9
Created May 25, 2014 19:11
MySQL spatial query in php
//Get Coordinates From Javascript Call
$latMin = $_GET["c1"];
$lonMin = $_GET["c2"];
$latMax = $_GET["c3"];
$lonMax = $_GET["c4"]; //Gather Coordinates Into a MySQL Polygon Geometry Type
$bounds = "GeomFromText('POLYGON((".$lonMin." ".$latMin.",".$lonMin."," .$latMax.",".$lonMax." ".$latMax.",".$lonMax." ".$latMin.",".$lonMin." ".$latMin."))')";
//Database Fields
@bmoregeo
bmoregeo / gist:e6a09a5e7f65b1f7a903
Created May 25, 2014 19:26
Choropleth MySQL PHP
// To call this from your php script, insert $kml_output .= getGeo($row['SHAPE']);
// or whatever the geometry field in your MYSQL DB table is
function getGeo($shape){
// Parse WKT style coordinates to KML style Coordinates
$shape = preg_replace("/([0-9.-]+) ([0-9.-]+),*/", "$1,$2,0 ", $shape);
// If the Geometry Type is a point parse the geometry type as a point
if (preg_match("/^POINT/", $shape)){
$shape = substr($shape, 6);
$shape = substr($shape, 0,-1);
@bmoregeo
bmoregeo / phpbreaks
Created May 25, 2014 19:27
php get breaks
function getBreaks($max, $min, $q){
$quant = ($max - $min) / $q;
for ($x = 0; $x <= $q; $x++){
$breakValue[$x] = $min+($quant*$x);
}
return $breakValue;
}
#!/usr/bin/env python
'''
This script creates an .sd from a .pyt
.. It assumes that all tools can be called with no parameters (i.e.,
all parameters are "optional". Not ideal for all services, but
works fine for services that arn't called from ArcMap anyway.
If you are calling your service from ArcMap, publish the traditional
way ..
def ExtractInt(string, start_position):
"""
Loop through string till the next + or - sign and convert the stuff in between from 32-> integer
"""
result = []
stop = False
position = start_position
while not stop:
@bmoregeo
bmoregeo / gist:9d46bb1d3a84e136b84a
Created August 25, 2014 20:07
Google Personal Location History to Shapefile
from xml.dom import minidom
import fiona
from shapely.geometry import mapping, Point
from dateutil.parser import parse
def xml_to_python(xml_file):
output = []
-- PG_Geometry Line feature class -> PG Routing
-- Add Required Fields
ALTER TABLE way ADD COLUMN "source" integer;
ALTER TABLE way ADD COLUMN "target" integer;
-- Build Topology (3D)
SELECT sde.pgr_createTopology3d('way', 0.01, 'shape', 'objectid')
-- Add Indices