
    h                       % S r SSKJr  SSKJrJrJrJrJrJ	r	J
r
JrJr  SSKJrJr  SSKrSSKrSSKrSSKrSSKJrJrJrJrJr  SSKJrJrJr  SSKJrJ r J!r!J"r"J#r#  SS	K$J%r%  SS
K&J'r'  SSKJ(r(  / SQr)Sr*Sr+Sr,Sr-Sr.Sr/Sr0Sr1Sr2Sr3Sr4Sr5Sr6Sr7Sr8Sr91 Skr:\\;\4   r<S\=S'   \\\</S4   r>S\=S '    " S! S"\R~                  5      r@\9S#4       SFS% jjrA\@R                  S4SS&.     SGS' jjjrCSHS( jrD\\/\4   rES\=S)'    " S* S$5      rFSIS+ jrGSJS, jrHSKS- jrISLS. jrJSMSNS/ jjrK\9S#4       SOS0 jjrLSPS1 jrM        SQS2 jrNS3 rO\9S#4       SRS4 jjrPSSS5 jrQSTS6 jrRSUSVS7 jjrSSWS8 jrTSXS9 jrUSXS: jrVS;rWS<rX\R                  " S=\XS>-  \WS>-  -  -
  5      rZ\R                  S?-  r\\R                  S?-  r^\R                  S@-  r_SYSA jr`SZS[SB jjraS\S]SC jjrbS^SD jrcS_SE jrdg)`aQ  
Implementation of the `__geo_interface__`: https://gist.github.com/sgillies/2217756

Which is also supported by Shapely: https://pypi.org/project/Shapely/

Type definitions see GeoJson Standard: https://tools.ietf.org/html/rfc7946
and examples : https://tools.ietf.org/html/rfc7946#appendix-A

GeoJSON Linter: https://geojsonlint.com/

    )annotations)	IterableIteratorUnioncastCallableSequenceOptionalAnyMutableMapping)	TypeAliasSelfN)Vec3has_clockwise_orientationMatrix44world_mercator_to_gpsgps_to_world_mercator)	make_pathfrom_hatch_boundary_pathmake_polygon_structure)
DXFGraphic
LWPolylinePointPolylineLine)
DXFPolygon)const)factory)proxydxf_entitiesgfilterGeoProxyPolygonConversiontypecoordinatesr   
MultiPoint
LineStringMultiLineStringPolygonMultiPolygonGeometryCollection
geometriesgeometryfeaturesFeature
propertiesFeatureCollectiong?>   ARCLINEHATCHPOINTSOLIDTRACE3DFACECIRCLESPLINEELLIPSEMPOLYGONPOLYLINE
LWPOLYLINEr   
GeoMappingPostProcessFuncc                  (    \ rS rSrSrSrSrSrSrSr	g)	r#   S   z{Polygon conversion types as :class:`IntEnum`.

Attributes:
    HATCH:
    POLYLINE:
    HATCH_AND_POLYLINE:
    MPOLYGON:

             N)
__name__
__module____qualname____firstlineno____doc__r4   r=   HATCH_AND_POLYLINEr<   __static_attributes__rG       B/var/www/html/env/lib/python3.13/site-packages/ezdxf/addons/geo.pyr#   r#   S   s     EHHrO   r#   Fr"   c                .    [         R                  XU5      $ )a  Returns a :class:`GeoProxy` object.

Args:
    entity: a single DXF entity or iterable of DXF entities
    distance: maximum flattening distance for curve approximations
    force_line_string: by default this function returns Polygon objects for
        closed geometries like CIRCLE, SOLID, closed POLYLINE and so on,
        by setting argument `force_line_string` to ``True``, this entities
        will be returned as LineString objects.

)r"   from_dxf_entities)entitydistanceforce_line_strings      rP   r   r   d   s      %%f8IJJrO   post_processc               H    [         R                  U 5      R                  XUS9$ )a  Returns ``__geo_interface__`` mappings as DXF entities.

The enum `polygon` determines the method to convert polygons,
use :attr:`PolygonConversion.HATCH` for :class:`~ezdxf.entities.Hatch` entity,
:attr:`PolygonConversion.POLYLINE` for :class:`~ezdxf.entities.LWPolyline` or
:attr:`PolygonConversion.HATCH_AND_POLYLINE` for both.
Option :attr:`PolygonConversion.POLYLINE` returns for the exterior path and each hole
a separated :class:`LWPolyline` entity. The :class:`Hatch` entity supports holes,
but has no explicit borderline.

Yields :class:`Hatch` always before :class:`LWPolyline` entities.

:attr:`PolygonConversion.MPOLYGON` support was added in v0.16.6, which is
like a :class:`~ezdxf.entities.Hatch` entity  with additional borderlines,
but the MPOLYGON entity is not a core DXF entity and DXF viewers,
applications and libraries my not support this entity. The DXF attribute
`color` defines the borderline color and `fill_color` the color of the
solid filling.

The returned DXF entities can be added to a layout by the
:meth:`Layout.add_entity` method.

Args:
    geo_mapping: ``__geo__interface__`` mapping as :class:`dict` or a Python
        object with a :attr:`__geo__interface__` property
    polygon: see :class:`PolygonConversion`
    dxfattribs: dict with additional DXF attributes
    post_process: post process function of type :class:`PostProcessFunc` that get the
        created DXF entity and the geo mapping as input, see reference implementation
        :func:`assign_layers`

rV   )r"   parseto_dxf_entities)geo_mappingpolygon
dxfattribsrW   s       rP   r    r    w   s+    N >>+&66, 7  rO   c              #     #    U  H`  n[        U[        5      (       a*  UR                  (       d  UR                  (       a  Uv   M@  MB  UR	                  5       [
        ;   d  M\  Uv   Mb     g7f)zmFilter DXF entities from iterable `entities`, which are incompatible to
the ``__geo_reference__`` interface.
N)
isinstancer   is_2d_polylineis_3d_polylinedxftypeSUPPORTED_DXF_TYPES)entitieses     rP   r!   r!      sM      a""1#3#3 $4YY[//G s   AA*!	A*TFuncc                  ,   \ rS rSrSrSSS jjr\SS j5       r\SS j5       r	\S 5       r
SS jr\r\SS j5       rSS	 jrSS
 jrSSS jjrSSS jjrSS jrSS jrS S jr\\S4       S!S jj5       r\R0                  S4SS.   S"S jjjrSrg)#r"      a[  Stores the ``__geo_interface__`` mapping in a parsed and compiled form.

Stores coordinates as :class:`Vec3` objects and represents "Polygon"
always as tuple (exterior, holes) even without holes.

The GeoJSON specification recommends 6 decimal places for latitude and
longitude which equates to roughly 10cm of precision. You may need
slightly more for certain applications, 9 decimal places would be
sufficient for professional survey-grade GPS coordinates.

Args:
    geo_mapping: parsed and compiled ``__geo_interface__`` mapping
    places: decimal places to round for ``__geo_interface__`` export

c                    Xl         X l        g N_rootplaces)selfr[   rm   s      rP   __init__GeoProxy.__init__   s     
rO   c                ^    [        US5      (       a  UR                  nU " [        U5      5      $ )a  Parse and compile a ``__geo_interface__`` mapping as :class:`dict`
or a Python object with a ``__geo_interface__`` property, does some
basic syntax checks, converts all coordinates into :class:`Vec3`
objects, represents "Polygon" always as tuple (exterior, holes) even
without holes.

__geo_interface__)hasattrrr   rY   )clsr[   s     rP   rY   GeoProxy.parse   s-     ; 344%77K5%&&rO   c                    U R                   $ rj   rl   rn   s    rP   rootGeoProxy.root   s    zzrO   c                8    U R                   R                  S5      $ )z7Property returns the top level entity type or ``None``.r$   )rl   getrx   s    rP   geotypeGeoProxy.geotype   s     zz~~f%%rO   c                .    [         R                  " U 5      $ )zReturns a deep copy.)copydeepcopyrx   s    rP   __copy__GeoProxy.__copy__   s    }}T""rO   c                B    [        U R                  U R                  5      $ )zGReturns the ``__geo_interface__`` compatible mapping as
:class:`dict`.
)_rebuildrl   rm   rx   s    rP   rr   GeoProxy.__geo_interface__   s    
 

DKK00rO   c              #  V   ^#    SU4S jjmT" U R                   5       Sh  vN   g N7f)a  Iterate over all geometry entities.

Yields only "Point", "LineString", "Polygon", "MultiPoint",
"MultiLineString" and "MultiPolygon" objects, returns the content of
"GeometryCollection", "FeatureCollection" and "Feature" as geometry
objects ("Point", ...).

c              3  T  >#    U [            nU[        :X  a!  U [            H  nT" U5       S h  vN   M     g U[        :X  a!  U [            H  nT" U5       S h  vN   M     g U[
        :X  a0  U [           nU[            [        :X  a  T" U5       S h  vN   g Uv   g U v   g  Ns NJ N7frj   TYPEFEATURE_COLLECTIONFEATURESGEOMETRY_COLLECTION
GEOMETRIESFEATUREGEOMETRY)nodetype_featurer-   _iters       rP   r    GeoProxy.__iter__.<locals>._iter   s     JE**#H~G$W~--  .-- $Z 0H$X.. !1'!>D>%88$X.."N
 . / /s3   +B(B"*B(B$8B(B&B($B(&B(N)r   r?   returnIterator[GeoMapping]rw   )rn   r   s    @rP   __iter__GeoProxy.__iter__   s     	" $$$s   )')c                l   ^^^ SU4S jjmSUUU4S jjmT" U R                   5      (       d  0 U l         gg)zRemoves all mappings for which `func()` returns ``False``.
The function only has to handle Point, LineString and Polygon entities,
other entities like MultiPolygon are divided into separate entities
also any collection.

c           	        > / nU [             H8  nT" [        [        U[         U05      5      (       d  M'  UR                  U5        M:     X [         '   [	        [        U5      5      $ rj   )COORDINATESr"   r   appendboollen)ry   r   r%   rS   funcs       rP   multi_entity%GeoProxy.filter.<locals>.multi_entity  sX    K{+${F!CDEE&&v. , !,K())rO   c                  > U [            nU[        :X  aK  U [            Vs/ s H  nT" U5      (       d  M  UPM     snU [        '   [        [	        U [           5      5      $ U[
        :X  aK  U [            Vs/ s H  nT" U5      (       d  M  UPM     snU [        '   [        [	        U [           5      5      $ U[        :X  a8  T" U [           5      (       a	  U [           O0 U [        '   [        U [           5      $ U[        :X  a  T" U [        5      $ U[        :X  a  T" U [        5      $ U[        :X  a  T" U [        5      $ T" [        U 5      5      $ s  snf s  snf rj   )r   r   r   r   r   r   r   r   r   MULTI_POINTr5   MULTI_LINE_STRINGLINE_STRINGMULTI_POLYGONPOLYGONr"   )ry   r   r   r-   checkr   r   s       rP   r   GeoProxy.filter.<locals>.check  s)   JE**+/>"+9U7^G>"X CX/00---1*-=$-=xH-=$Z  CZ 0122'!38h3H3HhbXDN+++%#D%00++#D+66-'#D'22HTN++'"
$s   EE5E
EN)r   r   rw   )rn   r   r   r   s    `@@rP   filterGeoProxy.filter  s/    	*	, 	,0 TZZ  DJ !rO   Nc                8    Uc  [         nU R                  U5        g)aB  Transform all coordinates recursive from globe representation
in longitude and latitude in decimal degrees into 2D map representation
in meters.

Default is WGS84 `EPSG:4326 <https://epsg.io/4326>`_ (GPS) to WGS84
`EPSG:3395 <https://epsg.io/3395>`_ World Mercator function
:func:`wgs84_4326_to_3395`.

Use the `pyproj <https://pypi.org/project/pyproj/>`_ package to write
a custom projection function as needed.

Args:
    func: custom transformation function, which takes one
        :class:`Vec3` object as argument and returns the result as
        a :class:`Vec3` object.

N)wgs84_4326_to_3395applyrn   r   s     rP   globe_to_mapGeoProxy.globe_to_map2      $ <%D

4rO   c                8    Uc  [         nU R                  U5        g)a@  Transform all coordinates recursive from 2D map representation in
meters into globe representation as longitude and latitude in decimal
degrees.

Default is WGS84 `EPSG:3395 <https://epsg.io/3395>`_ World Mercator
to WGS84 `EPSG:4326 <https://epsg.io/4326>`_ GPS function
:func:`wgs84_3395_to_4326`.

Use the `pyproj <https://pypi.org/project/pyproj/>`_ package to write
a custom projection function as needed.

Args:
    func: custom transformation function, which takes one
        :class:`Vec3` object as argument and returns the result as
        a :class:`Vec3` object.

N)wgs84_3395_to_4326r   r   s     rP   map_to_globeGeoProxy.map_to_globeH  r   rO   c                :    U R                  UR                  5        g)zTransform all coordinates recursive from CRS into
:ref:`WCS` coordinates by transformation matrix `crs` inplace,
see also :meth:`GeoProxy.wcs_to_crs`.

Args:
    crs: transformation matrix of type :class:`~ezdxf.math.Matrix44`

N)r   ucs_vertex_from_wcsrn   crss     rP   
crs_to_wcsGeoProxy.crs_to_wcs^  s     	

3**+rO   c                :    U R                  UR                  5        g)a\  Transform all coordinates recursive from :ref:`WCS` coordinates into
Coordinate Reference System (CRS) by transformation matrix `crs`
inplace.

The CRS is defined by the :class:`~ezdxf.entities.GeoData` entity,
get the :class:`GeoData` entity from the modelspace by method
:meth:`~ezdxf.layouts.Modelspace.get_geodata`.
The CRS transformation matrix can be acquired form the :class:`GeoData`
object by :meth:`~ezdxf.entities.GeoData.get_crs_transformation` method:

.. code:: Python

    doc = ezdxf.readfile('file.dxf')
    msp = doc.modelspace()
    geodata = msp.get_geodata()
    if geodata:
        matrix, axis_ordering = geodata.get_crs_transformation()

If `axis_ordering` is ``False`` the CRS is not compatible with the
``__geo_interface__`` or GeoJSON (see chapter 3.1.1).

Args:
    crs: transformation matrix of type :class:`~ezdxf.math.Matrix44`

N)r   	transformr   s     rP   
wcs_to_crsGeoProxy.wcs_to_crsi  s    6 	

3==!rO   c                T   ^ SU4S jjnU R                  5        H  nU" U5        M     g)zApply the transformation function `func` recursive to all
coordinates.

Args:
    func: transformation function as Callable[[Vec3], Vec3]

c                B   >^ UU4S jmT" U [            5      U [         '   g )Nc                z   > [        U [        5      (       a  T" U 5      $ U  Vs/ s H  nT" U5      PM     sn$ s  snf rj   )r_   r   )coordscr   r   s     rP   r   2GeoProxy.apply.<locals>.process.<locals>.transform  s6    fd++<'289&QIaL&999s   8)r   )rS   r   r   s    @rP   processGeoProxy.apply.<locals>.process  s    : #,F;,?"@F;rO   N)rS   r?   )r   )rn   r   r   rS   s    `  rP   r   GeoProxy.apply  s"    	A mmoFFO &rO   Fc                n    [        U[        5      (       a  [        XU5      nO[        XU5      nU " U5      $ )a  Constructor from a single DXF entity or an iterable of DXF entities.

Args:
    entity: DXF entity or entities
    distance: maximum flattening distance for curve approximations
    force_line_string: by default this function returns Polygon objects for
        closed geometries like CIRCLE, SOLID, closed POLYLINE and so on,
        by setting argument `force_line_string` to ``True``, this entities
        will be returned as LineString objects.

)r_   r   mapping
collection)rt   rS   rT   rU   ms        rP   rR   GeoProxy.from_dxf_entities  s4    $ fj))*;<A6->?A1vrO   rV   c             #    ^^^	^
^^^^#    SU4S jjmSU4S jjmSU
UUU4S jjm        SU4S jjm	SU	4S jjm
SU	4S jjmSUUU4S jjnTS:  d  TS	:  a  [        S
T 35      e[        T=(       d    0 5      m[        U R                  5       HO  u  pVUR	                  [
        5      nU" XvR	                  [        5      5       H  nU(       a  U" X5        Uv   M     MQ     g7f)a  Returns stored ``__geo_interface__`` mappings as DXF entities.

The `polygon` argument determines the method to convert polygons,
use 1 for :class:`~ezdxf.entities.Hatch` entity, 2 for
:class:`~ezdxf.entities.LWPolyline` or 3 for both.
Option 2 returns for the exterior path and each hole a separated
:class:`LWPolyline` entity. The :class:`Hatch` entity supports holes,
but has no explicit borderline.

Yields :class:`Hatch` always before :class:`LWPolyline` entities.

:class:`~ezdxf.entities.MPolygon` support was added in v0.16.6, which is
like a :class:`~ezdxf.entities.Hatch` entity  with additional borderlines,
but the MPOLYGON entity is not a core DXF entity and DXF viewers,
applications and libraries my not support this entity. The DXF attribute
`color` defines the borderline color and `fill_color` the color of the
solid filling.

The returned DXF entities can be added to a layout by the
:meth:`Layout.add_entity` method.

Args:
    polygon: see :class:`PolygonConversion`
    dxfattribs: dict with additional DXF attributes
    post_process: post process function of type :class:`PostProcesFunc` that get the
        created DXF entity and the geo mapping as input, see reference implementation
        :func:`assign_layers`

c                n   > [        [        [        R                  " STS95      nXR                  l        U$ )Nr5   r]   )r   r   r   newdxflocation)vertexpointr]   s     rP   r   'GeoProxy.to_dxf_entities.<locals>.point  s)    G
 KLE!'IILrO   c                n   > [        [        [        R                  " STS95      nUR	                  U SS9  U$ )Nr>   r   xy)format)r   r   r   r   append_points)verticespolyliner]   s     rP   
lwpolyline,GeoProxy.to_dxf_entities.<locals>.lwpolyline  s7    GKKLH ""8D"9OrO   c              3     >#    T[         R                  :X  a  T" X5      v   g T[         R                  -  (       a
  T" X5      v   T[         R                  -  (       a  U /U-    H  nT" U5      v   M     g g 7frj   )r#   r<   r4   r=   )exteriorholespathhatch_r   	mpolygon_r\   s      rP   polygon_*GeoProxy.to_dxf_entities.<locals>.polygon_  so     +44400 *000X--*333%J.D$T** / 4s   A3A6c                >  > [        [        [        R                  " U TS95      n[        R
                  UR                  l        UR                  R                  U[        R                  S9  U H+  nUR                  R                  U[        R                  S9  M-     U$ )Nr   )flags)r   r   r   r   r   HATCH_STYLE_OUTERMOSTr   hatch_stylepathsadd_polyline_pathBOUNDARY_PATH_EXTERNALBOUNDARY_PATH_OUTERMOST)rb   r   r   dxf_polygonholer]   s        rP   dxf_polygon_.GeoProxy.to_dxf_entities.<locals>.dxf_polygon_  s     z7;;w:+VWK*/*E*EKOO'// < < 0  !!33 = = 4   rO   c                   > T" SX5      $ )Nr4   rG   r   r   r   s     rP   r   (GeoProxy.to_dxf_entities.<locals>.hatch_  s    99rO   c                   > T" SX5      $ )Nr<   rG   r   s     rP   r   +GeoProxy.to_dxf_entities.<locals>.mpolygon_  s    
H<<rO   c              3  p  >#    U [         :X  a  T" U5      v   g U [        :X  a  T" U5      v   g U [        :X  a  Uu  p#T" X#5       S h  vN   g U [        :X  a  U H  nT" U5      v   M     g U [        :X  a  U H  nT" U5      v   M     g U [
        :X  a  U H  nUu  p#T" X#5       S h  vN   M     g g  Nj N7frj   )r5   r   r   r   r   r   )r   r%   r   r   datar   r   r   s        rP   rS   (GeoProxy.to_dxf_entities.<locals>.entity  s     ~K((+% --'!"-#H444+%'D+% (++'D$T** (-''D&*OH'888 ( ( 5 9s%   AB6B2AB6'B4(B64B6rC   rF   zinvalid value for polygon: N)r   r	   r   r   )r   r	   r   r   )r   listr   r   r   Iterator[DXFGraphic])rb   strr   r	   r   r	   r   r   )r   r	   r   r	   r   r   )r   r   )
ValueErrordictiter_featuresrl   r|   r   r   )rn   r\   r]   rW   rS   r   r-   r   re   r   r   r   r   r   r   s    ``      @@@@@@rP   rZ   GeoProxy.to_dxf_entities  s     J	
	
	+ 
	+		$,	5=			:	=	9 	9& Q;'A+:7)DEE**+
!.tzz!:GLL&EE<<#<= , > ";s   CC'rk      )r[   r?   rm   int)r[   r?   r   r   )r   r?   )r   r"   )r   r   )r   zCallable[[GeoProxy], bool]r   Nonerj   )r   zOptional[TFunc]r   r  )r   r   r   r  )r   rf   r   r  rS   z'Union[DXFGraphic, Iterable[DXFGraphic]]rT   floatrU   r   r   r"   )rW   Optional[PostProcessFunc]r   r   )rH   rI   rJ   rK   rL   ro   classmethodrY   propertyry   r}   r   r   rr   r   r   r   r   r   r   r   MAX_FLATTENING_DISTANCErR   r#   r4   rZ   rN   rG   rO   rP   r"   r"      s     
' 
'   & &# D1 1%:)V,,	,":*  2"'	7   	
 
 2 "''m
 37m
 0m 
m mrO   c              #  J   ^^#    0 mSUU4S jjmT" U 5       Sh  vN   g N7f)a  Yields all geometries of a ``__geo_mapping__`` as (`feature`, `geometry`) tuples.

If no feature is defined the `feature` value is an empty ``dict``. When a `feature`
contains `GeometryCollections`, the function yields for each sub-geometry a separate
(`feature`, `geometry`) tuple.

c              3  `  >#    U [            nU[        :X  a!  U [            H  nT" U5       S h  vN   M     g U[        :X  a!  U [            H  nT" U5       S h  vN   M     g U[
        :X  a4  U mU [           nU[            [        :X  a  T" U5       S h  vN   g TU4v   g TU 4v   g  Ny NP N7frj   r   )r   r   r   r-   current_featurer.   s       rP   r.   iter_features.<locals>.features-  s      T
&&>#G,,, *)) ,#H--- -g"OH~H~!44#H---%x//!4'' - .
 .s3   +B.B(*B.B*:B.B,B.*B.,B.N)r   r?   r   'Iterator[tuple[GeoMapping, GeoMapping]]rG   )r[   r  r.   s    @@rP   r  r  #  s'      #%O( (( $$$s   #!#c                   [         R                  " U 5      n U R                  [        5      nUc  [	        S[         S35      eU[
        :X  aT  U R                  [        5      nU(       a%  U Vs/ s H  n[        U5      PM     snU [        '   U $ [	        S[         S35      eU[        :X  aT  U R                  [        5      nU(       a%  U Vs/ s H  n[        U5      PM     snU [        '   U $ [	        S[         S35      eU[        :X  aO  [        U ;   a2  U R                  [        5      nU(       a  [        U5      OSU [        '   U $ [	        S[         S35      eU[        [        [        [        [         ["        1;   a  U R                  [$        5      nUc  [	        S[$         SU S	35      eU[        :X  a  ['        U5      nOU[        [        4;   a  [&        R(                  " U5      nOlU[        :X  a  [+        U5      nOVU[         :X  a'  U Vs/ s H  n[&        R(                  " U5      PM     nnO%U["        :X  a  U Vs/ s H  n[+        U5      PM     nnXp[$        '   U $ [-        S
U S35      es  snf s  snf s  snf s  snf )zParse ``__geo_interface__`` convert all coordinates into
:class:`Vec3` objects, Polygon['coordinates'] is always a
tuple (exterior, holes), holes maybe an empty list.

NzRequired key "z" not found.zMissing key "z" in FeatureCollection.z" in GeometryCollection.z" in Feature.z" in .zInvalid type "z".)r   r   r|   r   r   r   r   rY   r   r   r   r   r5   r   r   r   r   r   r   r   r   _parse_polygon	TypeError)	r[   r   r.   fr,   gr-   r%   vs	            rP   rY   rY   D  sI    --,KOOD!E}>$|<==""??8,7?$@x!U1Xx$@K!T Q }XJ6MNOO	%	% __Z0
9C&DAuQx&DK
#F C }ZL8PQRR	'	 {""x0H7?E(OTK!6 3 }XJmDEE	 
 "ook2}[MugQGHHE>{+K{K00))K0Kg(5K''1<=A499Q<K=Km#6ABk>!,kKB#.K   .r233S %A 'E: >Bs   ,I+
I0
 I5;I:c                    [        U [        5      (       d  [        S5      e[        U 5      S:X  a  [        S5      eU S   n[        U5      S:X  a  [        S5      e[        US   [        R
                  5      $ )zReturns ``True`` for a sequence of coordinates like [(0, 0), (1, 0)]
and ``False`` for a sequence of sequences:
[[(0, 0), (1, 0)], [(2, 0), (3, 0)]]
zInvalid coordinate sequence.r   )r_   r	   r   r   numbersReal)r%   
first_items     rP   _is_coordinate_sequencer    sl    
 k8,,788
;1788QJ
:!788jmW\\22rO   c                    [        U 5      (       a  U n/ nO
U S   nU SS n[        R                  " U5      U Vs/ s H  n[        R                  " U5      PM     sn4$ s  snf )z8Returns polygon definition as tuple (exterior, [holes]).r   rC   N)r  r   r   )r%   r   r   hs       rP   r  r    sY    {++q>AB99Xu =u!1u === =s    Ac           	       ^^ SU4S jjmU4S jn[        U 5      nU[           nU[        :X  a,  U[            Vs/ s H  n[	        U5      PM     snU[        '   U$ U[
        :X  a,  U[            Vs/ s H  n[	        U5      PM     snU[        '   U$ U[        :X  a  [	        U[           5      U[        '   U$ U[        :X  a  U[           nT" U5      U[        '   U$ U[        [        4;   a+  U[           nU Vs/ s H  nT" U5      PM     snU[        '   U$ U[        :X  aD  / nU[            H+  n	UR                  U	 Vs/ s H  nT" U5      PM     sn5        M-     X[        '   U$ U[        :X  a  U" U[           6 U[        '   U$ U[         :X  a+  U[            V
Vs/ s H  u  pU" X5      PM     snn
U[        '   U$ s  snf s  snf s  snf s  snf s  snn
f )zjReturns ``__geo_interface__`` compatible mapping as :class:`dict` from
compiled internal representation.

c                \   > [        U R                  T5      [        U R                  T5      4$ rj   )roundxy)r  rm   s    rP   pnt_rebuild.<locals>.pnt  s$    QSS&!5f#555rO   c           
     x   > U /U-    VVs/ s H  o" Vs/ s H  nT" U5      PM     snPM     snn$ s  snf s  snnf rj   rG   )r   r   ringr  r&  s       rP   _polygon_rebuild.<locals>._polygon  s<     5=:3EF3E4&AQ&3EFF&Fs   	6166)r  r   r   ztuple[float, float])r  r   r   r   r   r   r   r   r   r5   r   r   r   r   r   r   r   )r[   rm   r*  geo_interfacer   r  r  r  r%   liner   r   r&  s    `          @rP   r   r     s   6G
 %M$E""8Eh8O"P8O18A;8O"Ph, + 
%	%:G
:S$T:SQXa[:S$Tj!( ' 
'	"*=+B"Ch$ # 
%+&%(Vk"  
;,	,#K06A%Bkc!fk%Bk"  
#	#!+.D51A56 /%0k"  
'	%-}[/I%Jk"
 	 
-	=J;=W&
=W/(HX%=W&
k" - #Q$T &C  6
&
s   F90F>7G<G
Gc                   U R                  5       n[        U [        5      (       a&  [        [        [
        U R                  R                  0$ [        U [        5      (       a5  [        U R                  R                  U R                  R                  /5      $ [        U [        5      (       a]  U R                  (       d  U R                  (       a0  [        U 5      n[!        UR#                  U5      5      n[%        XR5      $ ['        S5      e[        U [(        5      (       a0  [        U 5      n[!        UR#                  U5      5      n[%        XR5      $ US;   a$  [%        [!        U R#                  U5      5      U5      $ US;   a  [%        U R+                  SS9U5      $ [        U [,        5      (       a  [/        XU5      $ ['        U5      e)a  Create the compiled ``__geo_interface__`` mapping as :class:`dict`
for the given DXF `entity`, all coordinates are :class:`Vec3` objects and
represents "Polygon" always as tuple (exterior, holes) even without holes.


Internal API - result is **not** a valid ``_geo_interface__`` mapping!

Args:
    entity: DXF entity
    distance: maximum flattening distance for curve approximations
    force_line_string: by default this function returns Polygon objects for
        closed geometries like CIRCLE, SOLID, closed POLYLINE and so on,
        by setting argument `force_line_string` to ``True``, this entities
        will be returned as LineString objects.

z$Polymesh and Polyface not supported.>   r2   r9   r:   r;   >   r6   r7   r8   T)close)rb   r_   r   r   r5   r   r   r   r   line_string_mappingstartendr   ra   r`   r   r   
flattening_line_string_or_polygon_mappingr  r   wcs_verticesr   _hatch_as_polygon)rS   rT   rU   rb   r   pointss         rP   r   r     sl   , nnG&%  e[&***=*=>>	FD	!	!"FJJ$4$4fjjnn#EFF	FH	%	%  F$9$9V$D$//(34F26MMBCC	FJ	'	' dooh/0.vII	:	:.""8,-/@
 	
 
0	0.d+->
 	
 
FJ	'	' 3DEE  rO   c                    [        U 5      nUS:  a  [        S5      eUS:X  d  U(       a  [        U 5      $ [        U 5      (       a  [	        U / 5      $ [        U 5      $ )NrD   zInvalid vertex count.)r   r   r0  is_linear_ringpolygon_mapping)r7  rU   len_s      rP   r4  r4    sV    v;Dax011qy%"6**&!!"62..&v..rO   c                R  ^^^^ SUUU4S jjnSU4S jjmU R                   R                  R                  mU R                  5       mU R                   R                  n[        U R                  R                  U5      5      n[        U5      nUS:X  a  [        U R                  5        S35      eUS   nUS:X  d  U[        R                  :X  a  U" U5      n[        X5      $ U(       aM  U" U5      n[        X5      /n	USS   H%  n
U" U
5      nU	R                  [        X5      5        M'     [        U	5      $ / n[!        UTT5       H>  u  p|T" U5      nUR                  [#        X V
s/ s H  n
T" U
5      PM     sn
5      5        M@     [        U5      S:  a  [        U5      $ US   $ s  sn
f )Nc                .   > [        U TT5      nT" U5      $ rj   r   )boundaryr   	elevationocspath_to_verticess     rP   boundary_to_vertices/_hatch_as_polygon.<locals>.boundary_to_vertices
  s    '#yA%%rO   c                X   > U R                  5         [        U R                  T5      5      $ rj   )r/  r   r3  )r   rT   s    rP   rB  +_hatch_as_polygon.<locals>.path_to_vertices  s     

DOOH-..rO   r   z without any boundary path.rC   )r   
list[Vec3])r   r@  zrA  r   r   r   rendering_pathsr   r   rb   r   HATCH_STYLE_IGNOREr4  r   join_multi_single_type_mappings_boundaries_to_polygonsr:  )hatchrT   rU   rC  r   
boundariescountr   r7  r,   r   polygonsr   r@  rA  rB  s    `           @@@rP   r6  r6    s   & &/ 		##%%I
))+C))''K ekk11+>?J
OEzEMMO,,GHII!}Hz[E$<$<<%h/.vII)(3F9&TUJ"12-d3!!3FN '
 3:>> H#::sI#V)(3#FPU,VPU-=d-CPU,VW $W
 8}q 6x@@A;	 -Ws   $F$c              #     ^^#    UU4S jU  5       n[        U5       H#  nUS   nXTSS   Vs/ s H  ofS   PM	     sn4v   M%     g s  snf 7f)Nc              3  >   >#    U  H  n[        UTT5      v   M     g 7frj   r>  ).0r?  r@  rA  s     rP   	<genexpr>*_boundaries_to_polygons.<locals>.<genexpr>>  s!      KUx 3	:::s   r   rC   )r   )rN  rA  r@  r   r\   r   r   s    ``    rP   rL  rL  =  sT     KUE *%01:QR[9[Ta[999 1 :s   (A
AA
c                    U  Vs/ s H  n[        X1U5      PM     nn[        S U 5       5      n[        U5      S:  a  [        U5      $ [	        U5      $ s  snf )a  Create the ``__geo_interface__`` mapping as :class:`dict` for the
given DXF `entities`, see https://gist.github.com/sgillies/2217756

Returns a "MultiPoint", "MultiLineString" or "MultiPolygon" collection if
all entities return the same GeoJSON type ("Point", "LineString", "Polygon")
else a "GeometryCollection".

Internal API - result is **not** a valid ``_geo_interface__`` mapping!

Args:
    entities: iterable of DXF entities
    distance: maximum flattening distance for curve approximations
    force_line_string: by default this function returns "Polygon" objects for
        closed geometries like CIRCLE, SOLID, closed POLYLINE and so on,
        by setting argument `force_line_string` to ``True``, this entities
        will be returned as "LineString" objects.
c              3  2   #    U  H  o[            v   M     g 7frj   )r   )rS  r  s     rP   rT  collection.<locals>.<genexpr>^  s     #A$s   rC   )r   setr   geometry_collection_mappingrK  )rd   rT   rU   re   r   typess         rP   r   r   G  sX    , ;CC(Q/	0(AC###E
5zA~*1--.q11 	Ds   Ac                &    [         [        [        U 0$ )zReturns a "LineString" mapping.

.. code::

    {
        "type": "LineString",
        "coordinates": [
            (100.0, 0.0),
            (101.0, 1.0)
        ]
    }
)r   r   r   r7  s    rP   r0  r0  e  s     +{F33rO   c                0    U S   R                  U S   5      $ )Nr   )iscloser]  s    rP   r9  r9  v  s    !9VBZ((rO   c                2   [        U 5      S:  a  [        S[        U 5       35      eU S   R                  U S   5      (       d  U R                  U S   5        [	        U 5      (       a  U(       a  U R                  5         U $ U(       d  U R                  5         U $ )zReturn `points` as linear ring (last vertex == first vertex),
argument `ccw` defines the winding orientation, ``True`` for counter-clock
wise and ``False`` for clock wise.

rE   zInvalid vertex count: r   r_  )r   r   r`  r   r   reverse)r7  ccws     rP   linear_ringrd  }  s     6{Q1#f+?@@!9VBZ((fQi  ((NN
 M NNMrO   c                    [        U SS9nU(       a  U Vs/ s H  n[        USS9PM     nnX!4nOU/ 4n[        [        [        U0$ s  snf )a  Returns a "Polygon" mapping.

.. code::

    {
        "type": "Polygon",
        "coordinates": [
             [
                 (100.0, 0.0),
                 (101.0, 0.0),
                 (101.0, 1.0),
                 (100.0, 1.0),
                 (100.0, 0.0)
             ],
             [
                 (100.8, 0.8),
                 (100.8, 0.2),
                 (100.2, 0.2),
                 (100.2, 0.8),
                 (100.8, 0.8)
             ]
        ]
    }
T)rc  F)rd  r   r   r   )r7  r   r   r   ringss        rP   r:  r:    sX    4 6t,H:?@%$Tu-%@"gU 	 As   Ac                T   [        5       n[        5       nU  H3  nUR                  U[           5        UR	                  U[
           5        M5     [        U5      S:  a  [        S[        U5       35      e[        U5      S:X  a
  [        5       $ [        S[        U5      S   -   [
        U0$ )z\Returns multiple geometries as a "MultiPoint", "MultiLineString" or
"MultiPolygon" mapping.
rC   zType mismatch: r   Multi)rY  r   addr   r   r   r   r  r   r  tuple)r,   r[  r   r  s       rP   rK  rK    s     EE6D		!D'AkN#  5zA~/#e*677	UqvgeQ/dCCrO   c                8    [         [        [        [        U 5      0$ )z>Returns multiple geometries as a "GeometryCollection" mapping.)r   r   r   r   )r,   s    rP   rZ  rZ    s    %z4
3CDDrO   iRa gQ?XAg      ?rD   g       @g      @c                T    [        [        U R                  U R                  5      5      $ )a  Transform WGS84 `EPSG:4326 <https://epsg.io/4326>`_ location given as
latitude and longitude in decimal degrees as used by GPS into World Mercator
cartesian 2D coordinates in meters `EPSG:3395 <https://epsg.io/3395>`_.

Args:
    location: :class:`Vec3` object, x-attribute represents the longitude
        value (East-West) in decimal degrees and the y-attribute
        represents the latitude value (North-South) in decimal degrees.
)r   r   r$  r%  )r   s    rP   r   r     s     %hjj(**=>>rO   c                V    [        [        U R                  U R                  U5      5      $ )aO  Transform WGS84 World Mercator `EPSG:3395 <https://epsg.io/3395>`_
location given as cartesian 2D coordinates x, y in meters into WGS84 decimal
degrees as longitude and latitude `EPSG:4326 <https://epsg.io/4326>`_ as
used by GPS.

Args:
    location: :class:`Vec3` object, z-axis is ignored
    tol: accuracy for latitude calculation

)r   r   r$  r%  )r   tols     rP   r   r     s!     %hjj(**cBCCrO   c                F    U [        U5      S-  -   [        U5      S-  -   nU$ )z6Convert degree, minutes, seconds into decimal degrees.<     )r	  )dr   sdds       rP   dms2ddru    s&    	
U1X]	U1X_	,BIrO   c                H    [        U S-  S5      u  p[        US5      u  p1X1U4$ )z6Convert decimal degrees into degree, minutes, seconds.rq  rp  )divmod)rt  r   rs  rr  s       rP   dd2dmsrx    s*    "t)R DA!R=DA7NrO   c                    UR                  [        5      nUc  gUR                  S5      nU(       a  X0R                  l        gg)zgReference implementation for a :func:`post_process` function.

.. seealso::

    :func:`dxf_entities`

Nlayer)r|   
PROPERTIESr   rz  )rS   r   r0   rz  s       rP   assign_layersr|    s;     Z(JNN7#E 

 rO   r  )r[   r?   rW   r
  r   r   )rd   Iterable[DXFGraphic]r   r   )r[   r?   r   r  )r[   r?   r   r?   )r%   r	   r   r   )r%   r	   r   r	   r  )r[   r?   rm   r  r   r?   )rS   r   rT   r	  rU   r   r   r?   )r7  rG  rU   r   )rM  r   rT   r	  rU   r   r   r?   )rd   r}  rT   r	  rU   r   r   r?   )r7  rG  r   r?   )r7  rG  )T)r7  rG  r   rG  )r7  rG  r   zlist[list[Vec3]]r   r?   )r,   zIterable[GeoMapping]r   r?   )r   r   r   r   )gư>)r   r   rn  r	  r   r   )r   r   )rr  r	  r   r	  rs  r	  r   r	  )rt  r	  r   ztuple[float, float, float])rS   r   r   r?   r   r  )erL   
__future__r   typingr   r   r   r   r   r	   r
   r   r   typing_extensionsr   r   r  r   mathenum
ezdxf.mathr   r   r   r   r   
ezdxf.pathr   r   r   ezdxf.entitiesr   r   r   r   r   ezdxf.entities.polygonr   ezdxf.lldxfr   r   __all__r   r   r5   r   r   r   r   r   r   r   r   r   r   r{  r   r  rc   r   r?   __annotations__r@   IntEnumr#   r   r4   r    r!   rf   r"   r  rY   r  r  r   r   r4  r6  rL  r   r0  r9  rd  r:  rK  rZ  WGS84_SEMI_MAJOR_AXISWGS84_SEMI_MINOR_AXISsqrtWGS84_ELLIPSOID_ECCENTRICre   CONST_E2pi
CONST_PI_2
CONST_PI_4r   r   ru  rx  r|  rG   rO   rP   <module>r     s  
 #
 
 
 .      S R H H -  " P% 
* 


(     'sCx0
I 0%z:&>&DE E & .#K3KK K 	K* ##)
 /3))
 ,) )X	 TFDL)y )n nb%B9x3>'X .#3!3!3! 3! 	3!l
/33!&3;?33l: .#2"22 2 	2<4")*#LD$E   $  II

"%:A%=
==  66C<WWs]
WWs]

?D!rO   