Created
May 4, 2012 13:49
-
-
Save craigds/2594905 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import binascii | |
import json | |
import re | |
from osgeo import ogr | |
from django.contrib.gis.geos import Point | |
p = Point(1, 2, 3) | |
wkt = "POINT (1 2 3)" | |
tests = ( | |
# (label, value, expected), | |
("GEOSGeometry.wkt", p.wkt, wkt), | |
("GEOSGeometry.ewkt", p.ewkt, wkt), | |
("GEOSGeometry.hex", ogr.CreateGeometryFromWkb(binascii.a2b_hex(p.hex)).ExportToWkt(), wkt), | |
("GEOSGeometry.wkb", ogr.CreateGeometryFromWkb(str(p.wkb)).ExportToWkt(), wkt), | |
("GEOSGeometry.ewkb", ogr.CreateGeometryFromWkb(str(p.ewkb)).ExportToWkt(), wkt), | |
("GEOSGeometry.hexewkb", ogr.CreateGeometryFromWkb(binascii.a2b_hex(p.hexewkb)).ExportToWkt(), wkt), | |
("GEOSGeometry.json", repr(json.loads(p.json)['coordinates']), '[1, 2, 3]'), | |
("GEOSGeometry.geojson", repr(json.loads(p.geojson)['coordinates']), '[1, 2, 3]'), | |
("GEOSGeometry.kml", p.kml, '<Point><coordinates>1,2,3</coordinates></Point>'), | |
) | |
for label, value, expected in tests: | |
# ignore precision, we don't care. | |
value = re.sub("\.0+", "", value) | |
print label, repr(value) | |
print "\t%s" % ("OK" if value == expected else "FAIL - expected: %r" % expected) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! That was a really quick reply... :D
(this gist is re
https://groups.google.com/forum/#!msg/geodjango/XQkkeDmsCDI/ZBYq1XZ6SngJ , and my results are here: https://gist.github.com/2594926 )