Skip to content

Instantly share code, notes, and snippets.

@craigds
Created May 4, 2012 13:49
Show Gist options
  • Save craigds/2594905 to your computer and use it in GitHub Desktop.
Save craigds/2594905 to your computer and use it in GitHub Desktop.
#!/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)
@springmeyer
Copy link

@craigds
Copy link
Author

craigds commented May 4, 2012

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 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment