Changeset 1087

Show
Ignore:
Timestamp:
04/27/08 21:01:30
Author:
seang
Message:

Most users should use shape() instead of asShape()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Shapely/trunk/CHANGES.txt

    r1082 r1087  
    66- Implement safe predicate shortcuts for objects identical in the Python sense 
    77  (#163). 
     8- Add shape(), a factory that copies coordinates from a geo interface provider. 
    89 
    9101.0.3 (2008-04-09) 
  • Shapely/trunk/shapely/geometry/geo.py

    r873 r1087  
     1""" 
     2Geometry factories based on the geo interface. 
     3""" 
    14 
    2 from point import PointAdapter 
    3 from linestring import LineStringAdapter 
    4 from polygon import PolygonAdapter 
    5 from multipoint import MultiPointAdapter 
    6 from multilinestring import MultiLineStringAdapter 
    7 from multipolygon import MultiPolygonAdapter 
     5from point import Point, asPoint 
     6from linestring import LineString, asLineString 
     7from polygon import Polygon, asPolygon 
     8from multipoint import MultiPoint, asMultiPoint 
     9from multilinestring import MultiLineString, asMultiLineString 
     10from multipolygon import MultiPolygon, asMultiPolygon 
    811 
     12 
     13def 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 
    936 
    1037def asShape(context): 
     
    2047 
    2148    if geom_type == "point": 
    22         return PointAdapter(ob["coordinates"]) 
     49        return asPoint(ob["coordinates"]) 
    2350    elif geom_type == "linestring": 
    24         return LineStringAdapter(ob["coordinates"]) 
     51        return asLineString(ob["coordinates"]) 
    2552    elif geom_type == "polygon": 
    26         return PolygonAdapter(ob["coordinates"][0], ob["coordinates"][1:]) 
     53        return asPolygon(ob["coordinates"][0], ob["coordinates"][1:]) 
    2754    elif geom_type == "multipoint": 
    28         return MultiPointAdapter(ob["coordinates"]) 
     55        return asMultiPoint(ob["coordinates"]) 
    2956    elif geom_type == "multilinestring": 
    30         return MultiLineStringAdapter(ob["coordinates"]) 
     57        return asMultiLineString(ob["coordinates"]) 
    3158    elif geom_type == "multipolygon": 
    32         return MultiPolygonAdapter(ob["coordinates"]) 
     59        return asMultiPolygon(ob["coordinates"]) 
    3360    else: 
    3461        raise ValueError, "Unknown geometry type: %s" % geom_type 
    35  
  • Shapely/trunk/shapely/geometry/__init__.py

    r853 r1087  
    1 from geo import asShape 
     1from geo import shape, asShape 
    22from point import Point, asPoint 
    33from linestring import LineString, asLineString 
  • Shapely/trunk/tests/LineString.txt

    r1046 r1087  
    9898    >>> la.__array_interface__ == la.context.__array_interface__ 
    9999    True 
    100     >>> as = asarray(la) 
    101     >>> as 
     100    >>> pas = asarray(la) 
     101    >>> pas 
    102102    array([[ 1.,  2.], 
    103103           [ 3.,  4.]]) 
  • Shapely/trunk/tests/MultiPoint.txt

    r1001 r1087  
    7272  True 
    7373  >>> from numpy import asarray 
    74   >>> as = asarray(geoma) 
    75   >>> as 
     74  >>> pas = asarray(geoma) 
     75  >>> pas 
    7676  array([[ 1.,  2.], 
    7777         [ 3.,  4.]]) 
  • Shapely/trunk/tests/Point.txt

    r1006 r1087  
    100100  True 
    101101  >>> from numpy import asarray 
    102   >>> as = asarray(pa) 
    103   >>> as 
     102  >>> pas = asarray(pa) 
     103  >>> pas 
    104104  array([ 1.,  2.]) 
    105105 
     
    124124   
    125125  >>> ai = pa.__array_interface__ 
    126   >>> as = asarray(pa) 
    127   >>> as 
     126  >>> pas = asarray(pa) 
     127  >>> pas 
    128128  array([ 1.,  4.]) 
    129129