-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbinascii_hex.txt
47 lines (37 loc) · 1.39 KB
/
binascii_hex.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Round-tripping geometries through hex-encoded binary
====================================================
Hex-encoded binary is the PostGIS geometry representation, and so this is a
test of the ability to store Shapely geometries in PostGIS.
Point
-----
>>> from shapely.geometry import Point
>>> point = Point(0.0, 0.0)
>>> from binascii import a2b_hex, b2a_hex
>>> x = b2a_hex(point.wkb)
>>> from shapely import wkb
>>> shape = wkb.loads(a2b_hex(x))
>>> shape # doctest: +ELLIPSIS
<shapely.geometry.point.Point object at ...>
LineString
----------
>>> from shapely.geometry import LineString
>>> line = LineString(((0.0, 0.0), (1.0, 1.0)))
>>> x = b2a_hex(line.wkb)
>>> shape = wkb.loads(a2b_hex(x))
>>> shape # doctest: +ELLIPSIS
<shapely.geometry.linestring.LineString object at ...>
Polygon
----------
>>> from shapely.geometry import Polygon
>>> polygon = Polygon(((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)))
>>> x = b2a_hex(polygon.wkb)
>>> shape = wkb.loads(a2b_hex(x))
>>> shape # doctest: +ELLIPSIS
<shapely.geometry.polygon.Polygon object at ...>
Polygon with hole
-----------------
>>> polygon = Polygon(((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)), [((0.1,0.1), (0.1,0.2), (0.2,0.2), (0.2,0.1))])
>>> x = b2a_hex(polygon.wkb)
>>> shape = wkb.loads(a2b_hex(x))
>>> shape # doctest: +ELLIPSIS
<shapely.geometry.polygon.Polygon object at ...>