Skip to content

Instantly share code, notes, and snippets.

View bengolder's full-sized avatar

Ben Golder bengolder

  • Binti
  • Oakland, CA, USA
  • 19:14 (UTC -07:00)
View GitHub Profile
@bengolder
bengolder / gist:1099735
Created July 22, 2011 16:06
Google maps geocoding API
import urllib2 as url
import json
h = "http://maps.googleapis.com/maps/api/geocode/json?address=9341+Venice+Boulevard+Culver+City,+California&sensor=false"
f = url.urlopen(h) # open the connection
s = f.read() # read the results as a string
d = json.loads(s) # convert the json string to a python dictionary
print d
@bengolder
bengolder / gist:1112736
Created July 28, 2011 22:35
Grasshopper Boids Example
from Rhino.Geometry import Point3d, Vector3d, Curve
# inputs
# numBoids
# switch
# boundingBox
class Boid():
@bengolder
bengolder / gist:1121701
Created August 3, 2011 01:48
CookieBoids ARCH 124B section 002 example
from Rhino.Geometry import Point3d, Vector3d, Curve
# define our class
class RoboCookie:
def __init__(self, point):
self.flavor = "strawberry"
self.location = point
self.friends = None
self.direction = Vector3d( -point.X, -point.Y, -point.Z )
@bengolder
bengolder / gist:1121702
Created August 3, 2011 01:49
CakeBoids ARCH124B sec 001 example
from Rhino.Geometry import Vector3d, Point3d, Curve
class CakeBot:
def __init__(self, radius, center):
self.radius = radius
self.location = center
self.height = 0.5
self.icingFlavor = "vanilla"
self.numSlices = 8
@bengolder
bengolder / gist:1295730
Created October 18, 2011 15:35
getSiteJson example
import postsites
# select a folder to load data from and create a dict for db stuff
my_data_folder = 'C:/tampaGIS'
dbinfo = {'user':'postgres', 'dbname':'postgis', 'password':'postgrespass'}
### If you haven't yet made a config XLS file, execute this block:
f = postsites.makeXlsConfigurationFile(my_data_folder)
# it looks like loadFromXlsConfigurationFile returns a tuple, of the datasource
@bengolder
bengolder / gist:1295787
Created October 18, 2011 15:52
layer configuration dictionary example for postsites
sites = {
'proposed_sites':{ 'name': 'proposed_sites', 'cols':['ogc_fid', 'fid_1', 'fid_1_1', 'objectid', 'assrdata_m', 'perimeter', 'ain', 'phase', 'lot', 'unit', 'moved', 'tra', 'pcltype', 'subdtype', 'tract', 'usecode', 'block', 'udate', 'editorname', 'parcel_typ', 'unit_no', 'pm_ref', 'tot_units', 'shape_area', 'shape_len', 'has_bb', 'count_', 'sum_oid_', 'sum_latitu', 'sum_longit', 'sum_buff_d', 'count_1']},
}
micro = {
'parcel':{ 'name': 'parcel', 'cols':['ogc_fid', 'objectid', 'assrdata_m', 'perimeter', 'ain', 'phase', 'lot', 'unit', 'moved', 'tra', 'pcltype', 'subdtype', 'tract', 'usecode', 'block', 'udate', 'editorname', 'parcel_typ', 'unit_no', 'pm_ref', 'tot_units', 'shape_area', 'shape_len', 'has_bb']},
'streetlights':{ 'name': 'streetlights', 'cols':['ogc_fid', 'objectid', 'angle', 'icon_txt', 'icon_id', 'ls', 'pole_type', 'lum_abbr', 'lumen', 'watts', 'lgt_type', 'sup_dist', 'petition', 'project', 'clmd', 'cc_no', 'l_no', 'pm', 'tract', 'uud', 'dateenr', 'sce_dist', 'sce_acct', 'sce_pol_i', 'sh
@bengolder
bengolder / gist:1501888
Created December 20, 2011 15:10
make2ds
import random
import os
from rhinopythonscripts.LayerTools import *
from rhinopythonscripts.PickleTools import *
from rhinopythonscripts.IllustrationTools import *
from rhinopythonscripts.FileTools import *
from rhinopythonscripts.GeomTools import *
from scriptcontext import doc
@bengolder
bengolder / gist:1974640
Last active January 29, 2021 13:24
Make DataTree with Python in Grasshopper
import Rhino
import scriptcontext
# for accesssing GH classes
import clr
clr.AddReference("Grasshopper")
from Grasshopper.Kernel.Data import GH_Path
from Grasshopper import DataTree
@bengolder
bengolder / gist:2413148
Created April 18, 2012 12:08
EPSG to OGC WKT in Grasshopper
import urllib2
if EPSG:
url = 'http://spatialreference.org/ref/epsg/%s/ogcwkt/' % EPSG
f = urllib2.urlopen(url)
OGC_WKT = f.read()
@bengolder
bengolder / gist:2643722
Created May 9, 2012 10:58
RhinoPython: Convert Elevation Text Objects to 3d Points
import scriptcontext
import Rhino
def getLayerGeometry(layerName, typefilter=Rhino.DocObjects.TextObject):
'''uses doc.Objects.FindByLayer and returns the Geometry of the
resulting RhinoObjects. If nothing found, returns an empty list.'''
objs = scriptcontext.doc.Objects.FindByLayer(layerName)
out = []
for obj in objs:
if isinstance(obj, typefilter):