Nino Walker wrote: > Hi List, > > I am looking into the Shapely library, it's great. I do need to, however, > access other functionality from libgeos, and have been flailing around trying > coerce ctypes and GEOS to work together. I was about to post a question... > but found the/a solution, so I'm posting it here for posterity. > > For it to work, shapely/geometry/__init__.py must include the following: > > from base import geom_factory > > ---------------- test_polygonize.py -------------------- > import shapely > from shapely.geometry import LineString, geom_factory > from shapely.wkt import loads > from shapely.geos import lgeos > from ctypes import byref, c_void_p, c_double > > def Polygonize(linestr_array): > """ > Finds all valid polygons defined by an array of LineString objects. > """ > geom_array_type = c_void_p * len(linestr_array) > geom_array = geom_array_type() > > for i,l in enumerate(linestr_array): > geom_array[i] = l._geom > #a = c_double() > #lgeos.GEOSLength(l._geom, byref(a)) > #print l._geom, a > > product = lgeos.GEOSPolygonize(byref(geom_array), len(linestr_array)) > return geom_factory(product) > > def _test(): > lines = [LineString([[0, 0], [1, 1]]), > LineString([[0, 0], [0, 1]]), > LineString([[0, 1], [1, 1]]), > LineString([[1, 1], [1, 0]]), > LineString([[1, 0], [0, 0]])] > print Polygonize(lines) > > if __name__ == "__main__": > _test() > --------------------------------------------------- > > > Cheers, > > Nino > > > Nino Walker :: Urban Mapping, Inc. > 690 Fifth Street Suite 200 :: San Francisco CA 94107 > www.urbanmapping.com >
Hi Nino, Thanks for the code. I committed something very much like it to the trunk along with enhancements to the GeometryCollection class that will let you access the polygons produced by the operation: http://trac.gispython.org/projects/PCL/changeset/1105 Cheers, Sean _______________________________________________ Community mailing list [email protected] http://lists.gispython.org/mailman/listinfo/community
