PageRenderTime 26ms CodeModel.GetById 21ms RepoModel.GetById 0ms 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 | 4 complexity | fe3d754d0107433b902f566144db7c7f MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from django.contrib.gis.geos.geometry import GEOSGeometry, wkt_regex, hex_regex
  2. def fromfile(file_h):
  3. """
  4. Given a string file name, returns a GEOSGeometry. The file may contain WKB,
  5. WKT, or HEX.
  6. """
  7. # If given a file name, get a real handle.
  8. if isinstance(file_h, basestring):
  9. file_h = open(file_h, 'rb')
  10. # Reading in the file's contents,
  11. buf = file_h.read()
  12. # If we get WKB need to wrap in buffer(), so run through regexes.
  13. if wkt_regex.match(buf) or hex_regex.match(buf):
  14. return GEOSGeometry(buf)
  15. else:
  16. return GEOSGeometry(buffer(buf))
  17. def fromstr(string, **kwargs):
  18. "Given a string value, returns a GEOSGeometry object."
  19. return GEOSGeometry(string, **kwargs)