o 3a@sTddlmZmZddlmZddlmZddlm Z ddl m Z GdddeZ dS) )byrefc_uint) prototypes) GEOSGeometry)GEOM_PTR) LinearRingcseZdZdZfddZddZddZedd Zd d Z d d Z d!ddZ ddZ ddZ ddZejZejZeddZddZddZeeeZeZeddZeZedd ZZS)"Polygoncs|stj|ddfi|dS|^}}t|}|dkrAt|dttfrA|ds0d}d}nt|ddtrA|d}t|}||d|g|}tj|fi|dS)a Initialize on an exterior ring and a sequence of holes (both instances may be either LinearRing instances, or a tuple/list that may be constructed into a LinearRing). Examples of initialization, where shell, hole1, and hole2 are valid LinearRing geometries: >>> from django.contrib.gis.geos import LinearRing, Polygon >>> shell = hole1 = hole2 = LinearRing() >>> poly = Polygon(shell, hole1, hole2) >>> poly = Polygon(shell, (hole1, hole2)) >>> # Example where a tuple parameters are used: >>> poly = Polygon(((0, 0), (0, 10), (10, 10), (0, 10), (0, 0)), ... ((4, 4), (4, 6), (6, 6), (6, 4), (4, 4))) rNr )super__init___create_polygonlen isinstancetuplelistr)selfargskwargsext_ring init_holesn_holespolygon __class__r A/usr/lib/python3/dist-packages/django/contrib/gis/geos/polygon.pyr szPolygon.__init__ccs"tt|D]}||VqdS)z&Iterate over each ring in the polygon.N)ranger)rir r r__iter__1s zPolygon.__iter__cCs |jdS)z+Return the number of rings in this Polygon.r )num_interior_ringsrr r r__len__6s zPolygon.__len__c Csn|\}}}}|D]}t|ttfs#td||||||||||f Sqt||f||f||f||f||ffS)z2Construct a Polygon from a bounding box (4-tuple).z,POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s)))rfloatintrr)clsbboxx0y0x1y1zr r r from_bbox:s  &zPolygon.from_bboxc s|stSg}|D]}t|tr||q ||q |d}|d}|r@t|fdd|D}t|}nd}t ||t |S)Nrr csg|]}|qSr )_clone).0rr r r Xsz+Polygon._create_polygon..) capicreate_empty_polygonrrappend_construct_ringr,poprcreate_polygonr) rlengthitemsringsr.shellrholes holes_paramr r rr Es   zPolygon._create_polygoncCs t|tr t|St|jSN)rrr0 geom_cloneptr)rgr r rr,_s   zPolygon._cloneYParameter must be a sequence of LinearRings or objects that can initialize to LinearRingscCs4t|tr|Szt|}|WStyt|w)z1Try to construct a ring from the given parameter.)rr TypeError)rparammsgringr r rr3es  zPolygon._construct_ringcCs2|j}|j}||||_|r||_t|dSr<)r>sridr r0 destroy_geom)rr6r7prev_ptrrEr r r _set_listps zPolygon._set_listcCs&|dkr t|jSt|j|dS)a7 Return the ring at the specified index. The first index, 0, will always return the exterior ring. Indices > 0 will return the interior ring at the given index (e.g., poly[1] and poly[2] would return the first and second interior ring, respectively). CAREFUL: Internal/External are not the same as Interior/Exterior! Return a pointer from the existing geometries for use internally by the object's methods. _get_single_external() returns a clone of the same geometry for use by external code. rr )r0 get_extringr> get_intringrindexr r r_get_single_internalzs zPolygon._get_single_internalcCstt|||jdS)N)rE)rr0r=rMrErKr r r_get_single_externalszPolygon._get_single_externalcCs t|jS)z$Return the number of interior rings.)r0 get_nringsr>r r r rrs zPolygon.num_interior_ringscCs|dS)z%Get the exterior ring of the Polygon.rr r r r r _get_ext_ringszPolygon._get_ext_ringcCs ||d<dS)z%Set the exterior ring of the Polygon.rNr )rrDr r r _set_ext_rings zPolygon._set_ext_ringcstfddttDS)z,Get the tuple for each ring in this Polygon.c3s|]}|jVqdSr<)rr-rr r r sz Polygon.tuple..)rrrr r r rrsz Polygon.tuplecs0dfddtjD}ddj|fS)z.Return the KML representation of this Polygon.c3s"|] }d|djVqdS)z%%sr N)kmlrRr r rrSs  zPolygon.kml..z:%s%sr)joinrrrU)r inner_kmlr r rrUsz Polygon.kml)r@)__name__ __module__ __qualname__ _minlengthr rr! classmethodr+r r,r3rHrMrNr_set_single_rebuild _set_single_assign_extended_slice_rebuild_assign_extended_slicepropertyrrPrQ exterior_ringr9rcoordsrU __classcell__r r rrr s6 %        rN) ctypesrrdjango.contrib.gis.geosrr0 django.contrib.gis.geos.geometryrdjango.contrib.gis.geos.libgeosr"django.contrib.gis.geos.linestringrrr r r rs