shapely 1.0__py2.4.egg

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
shapely/wkb.py ADDED
@@ -0,0 +1,40 @@
1
+ """
2
+ Load/dump geometries using the well-known binary (WKB) format.
3
+ """
4
+
5
+ from ctypes import byref, c_int, c_size_t, c_char_p, string_at
6
+
7
+ from shapely.geos import lgeos, free, ReadingError
8
+ from shapely.geometry.base import geom_factory
9
+
10
+
11
+ # Pickle-like convenience functions
12
+
13
+ def loads(data):
14
+ """Load a geometry from a WKB string."""
15
+ geom = lgeos.GEOSGeomFromWKB_buf(c_char_p(data), c_size_t(len(data)));
16
+ if not geom:
17
+ raise ReadingError, \
18
+ "Could not create geometry because of errors while reading input."
19
+ return geom_factory(geom)
20
+
21
+ def load(fp):
22
+ """Load a geometry from an open file."""
23
+ data = fp.read()
24
+ return loads(data)
25
+
26
+ def dumps(ob):
27
+ """Dump a WKB representation of a geometry to a byte string."""
28
+ func = lgeos.GEOSGeomToWKB_buf
29
+ size = c_int()
30
+ def errcheck(result, func, argtuple):
31
+ retval = string_at(result, size.value)[:]
32
+ free(result)
33
+ return retval
34
+ func.errcheck = errcheck
35
+ return func(ob._geom, byref(size))
36
+
37
+ def dump(ob, fp):
38
+ """Dump a geometry to an open file."""
39
+ fp.write(dumps(ob))
40
+
shapely/wkb.pyc ADDED
Binary file
shapely/wkt.py ADDED
@@ -0,0 +1,40 @@
1
+ """
2
+ Load/dump geometries using the well-known text (WKT) format.
3
+ """
4
+
5
+ from ctypes import byref, c_int, c_size_t, c_char_p, string_at
6
+
7
+ from shapely.geos import lgeos, free, allocated_c_char_p, ReadingError
8
+ from shapely.geometry.base import geom_factory
9
+
10
+
11
+ # Pickle-like convenience functions
12
+
13
+ def loads(data):
14
+ """Load a geometry from a WKT string."""
15
+ geom = lgeos.GEOSGeomFromWKT(c_char_p(data))
16
+ if not geom:
17
+ raise ReadingError, \
18
+ "Could not create geometry because of errors while reading input."
19
+ return geom_factory(geom)
20
+
21
+ def load(fp):
22
+ """Load a geometry from an open file."""
23
+ data = fp.read()
24
+ return loads(data)
25
+
26
+ def dumps(ob):
27
+ """Dump a WKB representation of a geometry to a byte string."""
28
+ func = lgeos.GEOSGeomToWKT
29
+ def errcheck(result, func, argtuple):
30
+ retval = result.value
31
+ free(result)
32
+ return retval
33
+ func.restype = allocated_c_char_p
34
+ func.errcheck = errcheck
35
+ return lgeos.GEOSGeomToWKT(ob._geom)
36
+
37
+ def dump(ob, fp):
38
+ """Dump a geometry to an open file."""
39
+ fp.write(dumps(ob))
40
+
shapely/wkt.pyc ADDED
Binary file