Skip to content

Instantly share code, notes, and snippets.

View bmoregeo's full-sized avatar

Christopher Fricke bmoregeo

View GitHub Profile
@bmoregeo
bmoregeo / php_mysql_extent
Created September 3, 2013 23:29
Query MYSQL based on extent
//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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bmoregeo
bmoregeo / csv2shp.py
Created October 15, 2014 13:50
Batch convert CSV to Shapefile with arcpy
import arcpy
import os
def csv2shp(csv_file, field_x, field_y, shape_file):
"""
Convert a CSV file with x/y fields into a Shapefile
"""
table_view = 'csv_file_as_view'
layer = 'xy_event_layer'
-- 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
@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 = []
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:
#!/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 ..
@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: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);