Changeset 1120

Show
Ignore:
Timestamp:
07/09/08 13:50:57
Author:
seang
Message:

Multipolygon bug fix and notes about 1.0.6

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Shapely/trunk/setup.py

    r1106 r1120  
    1212 
    1313setup(name          = 'Shapely', 
    14       version       = '1.0.5', 
     14      version       = '1.0.6', 
    1515      description   = 'Geospatial geometries, predicates, and operations', 
    1616      license       = 'BSD', 
  • Shapely/trunk/setup_windows.py

    r1106 r1120  
    1212 
    1313setup(name          = 'Shapely', 
    14       version       = '1.0.5', 
     14      version       = '1.0.6', 
    1515      description   = 'Geospatial geometries, predicates, and operations', 
    1616      license       = 'BSD', 
  • Shapely/trunk/shapely/geometry/geo.py

    r1108 r1120  
    88from multipoint import MultiPoint, asMultiPoint 
    99from multilinestring import MultiLineString, asMultiLineString 
    10 from multipolygon import MultiPolygon, asMultiPolygon 
     10from multipolygon import MultiPolygon, MultiPolygonAdapter, asMultiPolygon 
    1111 
    1212 
     
    3131        return MultiLineString(ob["coordinates"]) 
    3232    elif geom_type == "multipolygon": 
    33         return MultiPolygon(ob["coordinates"]
     33        return MultiPolygon(ob["coordinates"], context_type='geojson'
    3434    else: 
    3535        raise ValueError, "Unknown geometry type: %s" % geom_type 
     
    6060        return asMultiLineString(ob["coordinates"]) 
    6161    elif geom_type == "multipolygon": 
    62         return asMultiPolygon(ob["coordinates"]
     62        return MultiPolygonAdapter(ob["coordinates"], context_type='geojson'
    6363    else: 
    6464        raise ValueError, "Unknown geometry type: %s" % geom_type 
  • Shapely/trunk/shapely/geometry/multipolygon.py

    r1089 r1120  
    1212 
    1313def geos_multipolygon_from_py(ob): 
     14    """ob must provide Python geo interface coordinates.""" 
     15    L = len(ob) 
     16    N = len(ob[0][0][0]) 
     17    assert L >= 1 
     18    assert N == 2 or N == 3 
     19 
     20    subs = (c_void_p * L)() 
     21    for l in xrange(L): 
     22        geom, ndims = geos_polygon_from_py(ob[l][0], ob[l][1:]) 
     23        subs[l] = cast(geom, c_void_p) 
     24             
     25    return (lgeos.GEOSGeom_createCollection(6, subs, L), N) 
     26 
     27def geos_multipolygon_from_polygons(ob): 
    1428    """ob must be either a sequence or array of sequences or arrays.""" 
    1529    L = len(ob) 
     
    2640 
    2741 
     42 
    2843class MultiPolygon(BaseGeometry): 
    2944 
     
    3146    """ 
    3247 
    33     def __init__(self, polygons=None): 
     48    def __init__(self, polygons=None, context_type='polygons'): 
    3449        """Initialize. 
    3550 
     
    5671            # allow creation of null collections, to support unpickling 
    5772            pass 
    58         else: 
     73        elif context_type == 'polygons': 
     74            self._geom, self._ndim = geos_multipolygon_from_polygons(polygons) 
     75        elif context_type == 'geojson': 
    5976            self._geom, self._ndim = geos_multipolygon_from_py(polygons) 
    6077 
     
    112129    _owned = False 
    113130 
    114     def __init__(self, context): 
     131    def __init__(self, context, context_type='polygons'): 
    115132        self.context = context 
    116         self.factory = geos_multipolygon_from_py 
     133        if context_type == 'geojson': 
     134            self.factory = geos_multipolygon_from_py 
     135        elif context_type == 'polygons': 
     136            self.factory = geos_multipolygon_from_polygons 
    117137 
    118138    @property 
  • Shapely/trunk/tests/GeoInterface.txt

    r863 r1120  
    6262  multi polygon 
    6363 
    64   >>> shape = asShape({'type': 'MultiPolygon', 'coordinates': [(((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)), [((0.10000000000000001, 0.10000000000000001), (0.10000000000000001, 0.20000000000000001), (0.20000000000000001, 0.20000000000000001), (0.20000000000000001, 0.10000000000000001), (0.10000000000000001, 0.10000000000000001))])]}) 
     64  >>> shape = asShape({'type': 'MultiPolygon', 'coordinates': [(((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)), ((0.10000000000000001, 0.10000000000000001), (0.10000000000000001, 0.20000000000000001), (0.20000000000000001, 0.20000000000000001), (0.20000000000000001, 0.10000000000000001), (0.10000000000000001, 0.10000000000000001)))]}) 
    6565  >>> shape # doctest: +ELLIPSIS 
    6666  <shapely.geometry.multipolygon.MultiPolygonAdapter object at ...>