Changeset 1087
- Timestamp:
- 04/27/08 21:01:30
- Files:
-
- Shapely/trunk/CHANGES.txt (modified) (1 diff)
- Shapely/trunk/shapely/geometry/geo.py (modified) (2 diffs)
- Shapely/trunk/shapely/geometry/__init__.py (modified) (1 diff)
- Shapely/trunk/tests/LineString.txt (modified) (1 diff)
- Shapely/trunk/tests/MultiPoint.txt (modified) (1 diff)
- Shapely/trunk/tests/Point.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
Shapely/trunk/CHANGES.txt
r1082 r1087 6 6 - Implement safe predicate shortcuts for objects identical in the Python sense 7 7 (#163). 8 - Add shape(), a factory that copies coordinates from a geo interface provider. 8 9 9 10 1.0.3 (2008-04-09) Shapely/trunk/shapely/geometry/geo.py
r873 r1087 1 """ 2 Geometry factories based on the geo interface. 3 """ 1 4 2 from point import Point Adapter3 from linestring import LineString Adapter4 from polygon import Polygon Adapter5 from multipoint import MultiPoint Adapter6 from multilinestring import MultiLineString Adapter7 from multipolygon import MultiPolygon Adapter5 from point import Point, asPoint 6 from linestring import LineString, asLineString 7 from polygon import Polygon, asPolygon 8 from multipoint import MultiPoint, asMultiPoint 9 from multilinestring import MultiLineString, asMultiLineString 10 from multipolygon import MultiPolygon, asMultiPolygon 8 11 12 13 def shape(context): 14 """Return a new, independent geometry with coordinates *copied* from the 15 context. 16 """ 17 if hasattr(context, "__geo_interface__"): 18 ob = context.__geo_interface__ 19 else: 20 ob = context 21 geom_type = ob.get("type").lower() 22 if geom_type == "point": 23 return Point(ob["coordinates"]) 24 elif geom_type == "linestring": 25 return LineString(ob["coordinates"]) 26 elif geom_type == "polygon": 27 return Polygon(ob["coordinates"][0], ob["coordinates"][1:]) 28 elif geom_type == "multipoint": 29 return MultiPoint(ob["coordinates"]) 30 elif geom_type == "multilinestring": 31 return MultiLineString(ob["coordinates"]) 32 elif geom_type == "multipolygon": 33 return MultiPolygon(ob["coordinates"]) 34 else: 35 raise ValueError, "Unknown geometry type: %s" % geom_type 9 36 10 37 def asShape(context): … … 20 47 21 48 if geom_type == "point": 22 return PointAdapter(ob["coordinates"])49 return asPoint(ob["coordinates"]) 23 50 elif geom_type == "linestring": 24 return LineStringAdapter(ob["coordinates"])51 return asLineString(ob["coordinates"]) 25 52 elif geom_type == "polygon": 26 return PolygonAdapter(ob["coordinates"][0], ob["coordinates"][1:])53 return asPolygon(ob["coordinates"][0], ob["coordinates"][1:]) 27 54 elif geom_type == "multipoint": 28 return MultiPointAdapter(ob["coordinates"])55 return asMultiPoint(ob["coordinates"]) 29 56 elif geom_type == "multilinestring": 30 return MultiLineStringAdapter(ob["coordinates"])57 return asMultiLineString(ob["coordinates"]) 31 58 elif geom_type == "multipolygon": 32 return MultiPolygonAdapter(ob["coordinates"])59 return asMultiPolygon(ob["coordinates"]) 33 60 else: 34 61 raise ValueError, "Unknown geometry type: %s" % geom_type 35 Shapely/trunk/shapely/geometry/__init__.py
r853 r1087 1 from geo import asShape1 from geo import shape, asShape 2 2 from point import Point, asPoint 3 3 from linestring import LineString, asLineString Shapely/trunk/tests/LineString.txt
r1046 r1087 98 98 >>> la.__array_interface__ == la.context.__array_interface__ 99 99 True 100 >>> as = asarray(la)101 >>> as100 >>> pas = asarray(la) 101 >>> pas 102 102 array([[ 1., 2.], 103 103 [ 3., 4.]]) Shapely/trunk/tests/MultiPoint.txt
r1001 r1087 72 72 True 73 73 >>> from numpy import asarray 74 >>> as = asarray(geoma)75 >>> as74 >>> pas = asarray(geoma) 75 >>> pas 76 76 array([[ 1., 2.], 77 77 [ 3., 4.]]) Shapely/trunk/tests/Point.txt
r1006 r1087 100 100 True 101 101 >>> from numpy import asarray 102 >>> as = asarray(pa)103 >>> as102 >>> pas = asarray(pa) 103 >>> pas 104 104 array([ 1., 2.]) 105 105 … … 124 124 125 125 >>> ai = pa.__array_interface__ 126 >>> as = asarray(pa)127 >>> as126 >>> pas = asarray(pa) 127 >>> pas 128 128 array([ 1., 4.]) 129 129
