Package madrona :: Package common :: Module utils
[hide private]

Module utils

source code

Classes [hide private]
  KMZUtil
Recursively adds a directory to a zipfile modified from http://stackoverflow.com/questions/458436/adding-folders-to-a-zip-file-using-python
Functions [hide private]
 
get_logger(caller_name=None) source code
 
KmlWrap(string) source code
 
LookAtKml(geometry) source code
 
LargestPolyFromMulti(geom)
takes a polygon or a multipolygon geometry and returns only the largest polygon geometry
source code
 
LargestLineFromMulti(geom)
takes a line or a multiline geometry and returns only the longest line geometry
source code
 
angle(pnt1, pnt2, pnt3)
Return the angle in radians between line(pnt2,pnt1) and line(pnt2,pnt3)
source code
 
angle_degrees(pnt1, pnt2, pnt3)
Return the angle in degrees between line(pnt2,pnt1) and line(pnt2,pnt3)
source code
 
spike_ring_indecies(line_ring, threshold=0.01)
Returns a list of point indexes if ring contains spikes (angles of less than threshold degrees).
source code
 
remove_spikes(poly, threshold=0.01)
Looks for spikes (angles < threshold degrees) in the polygons exterior ring.
source code
 
clean_geometry(geom)
Send a geometry to the cleanGeometry stored procedure and get the cleaned geom back.
source code
 
ensure_clean(geo, srid) source code
 
ComputeLookAt(geometry) source code
 
get_class(path) source code
 
kml_errors(kmlstring) source code
 
hex8_to_rgba(hex8)
Takes an 8 digit hex color string (used by Google Earth) and converts it to RGBA colorspace * 8-digit hex codes use AABBGGRR (R - red, G - green, B - blue, A - alpha transparency)
source code
 
load_session(request, session_key) source code
 
valid_browser(ua)
Returns boolean depending on whether we support their browser based on their HTTP_USER_AGENT
source code
 
isCCW(ring)
Determines if a LinearRing is oriented counter-clockwise or not
source code
 
forceRHR(polygon)
reverses rings so that polygon follows the Right-hand rule exterior ring = clockwise interior rings = counter-clockwise
source code
 
forceLHR(polygon)
reverses rings so that geometry complies with the LEFT-hand rule Google Earth KML requires this oddity exterior ring = counter-clockwise interior rings = clockwise
source code
 
asKml(input_geom, altitudeMode=None, uid='')
Performs three critical functions for creating suitable KML geometries:
source code
 
enable_sharing(group=None)
Give group permission to share models Permissions are attached to models but we want this perm to be 'global' Fake it by attaching the perm to the Group model (from the auth app) We check for this perm like: user1.has_perm("auth.can_share_features")
source code
 
fetch_resources(uri, rel) source code
 
get_params_from_uri(uri) source code
 
is_text(s)
Tests a string to see if it's binary borrowed from http://code.activestate.com/recipes/173220-test-if-a-file-or-string-is-text-or-binary/
source code
 
cachemethod(cache_key, timeout=3600)
http://djangosnippets.org/snippets/1130/ Cacheable class method decorator from madrona.common.utils import cachemethod @cachemethod("SomeClass_get_some_result_%(id)s")
source code
Variables [hide private]
  log = get_logger()
Function Details [hide private]

spike_ring_indecies(line_ring, threshold=0.01)

source code 

Returns a list of point indexes if ring contains spikes (angles of less than threshold degrees). Otherwise, an empty list.

remove_spikes(poly, threshold=0.01)

source code 

Looks for spikes (angles < threshold degrees) in the polygons exterior ring. If there are spikes, they will be removed and a polygon (without spikes) will be returned. If no spikes are found, method will return original geometry.

NOTE: This method does not examine or fix interior rings. So far those haven't seemed to have been a problem.

valid_browser(ua)

source code 

Returns boolean depending on whether we support their browser based on their HTTP_USER_AGENT

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-us) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0b7) Gecko/20100101 Firefox/4.0b7

asKml(input_geom, altitudeMode=None, uid='')

source code 

Performs three critical functions for creating suitable KML geometries:

  • simplifies the geoms (lines, polygons only)
  • forces left-hand rule orientation
  • sets the altitudeMode shape (usually one of: absolute, clampToGround, relativeToGround)