PageRenderTime 16ms CodeModel.GetById 13ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/django/contrib/gis/geos/factory.py

https://code.google.com/p/mango-py/
Python | 23 lines | 12 code | 4 blank | 7 comment | 3 complexity | fe3d754d0107433b902f566144db7c7f MD5 | raw file
 1from django.contrib.gis.geos.geometry import GEOSGeometry, wkt_regex, hex_regex
 2
 3def fromfile(file_h):
 4    """
 5    Given a string file name, returns a GEOSGeometry. The file may contain WKB,
 6    WKT, or HEX.
 7    """
 8    # If given a file name, get a real handle.
 9    if isinstance(file_h, basestring): 
10        file_h = open(file_h, 'rb')
11
12    # Reading in the file's contents,
13    buf = file_h.read()
14
15    # If we get WKB need to wrap in buffer(), so run through regexes.
16    if wkt_regex.match(buf) or hex_regex.match(buf):
17        return GEOSGeometry(buf)
18    else:
19        return GEOSGeometry(buffer(buf))
20
21def fromstr(string, **kwargs):
22    "Given a string value, returns a GEOSGeometry object."
23    return GEOSGeometry(string, **kwargs)