a `§»eQ$ã@sTddlZddlZddlmZddlmZddlmZGdd„dƒZGdd„dƒZdS) éN)Úlog)Úlocation)ÚCRSc@szeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z ddd„Z d dd„Zd!dd„ZdS)"ÚGCPFilecCs$||_g|_d|_d|_| ¡dS)NÚ)Úgcp_pathÚentriesÚraw_srsÚsrsÚread)Úselfr©r ú/code/opendm/gcp.pyÚ__init__s zGCPFile.__init__cCsØ| ¡rÔt|jdƒ}| ¡ ¡}Wdƒn1s60Y| dd¡}tttj|  d¡ƒƒ}|rÔ|d|_ t   |j ¡|_ |dd…D]H}|dkrŠ|ddkrŠ|  ¡}t|ƒdkrÄ|j |¡qŠt d |¡qŠdS) NÚrurÚ réú#ézMalformed GCP line: %s)ÚexistsÚopenrr ÚstripÚreplaceÚlistÚmapÚstrÚsplitr rÚparse_srs_headerr ÚlenrÚappendrÚ ODM_WARNING)r ÚfÚcontentsÚlinesÚlineÚpartsr r rr s*   z GCPFile.readccs|jD]}| |¡VqdS©N)rÚ parse_entry)r Úentryr r rÚ iter_entries$s zGCPFile.iter_entriescCs"i}i}d}| ¡D]>}| ¡}| |d¡d||<||vrDg||<|| |¡q|D]z}||dkrX||dkrxdnd}||D]}t t|ƒ¡q„t d||f¡t dd||¡t d ¡|d7}qXt|ƒdkr t d dt|ƒ¡t d ¡|d7}|dkrt d ¡dS) NrrééZ insufficientz not idealzrrÚ isinstancerrrGr5) r rHÚ filenamesÚrejected_entriesÚinclude_extrasrJÚ target_srsrUr(r!r r rÚcreate_utm_copyus         2zGCPFile.create_utm_copyr*c CsØ| ¡rtj |¡sdStj |¡r.t |¡tttjjt tj |d¡¡ƒƒ}|j g}d}|  ¡D]$}|j |vrd|  t |ƒ¡|d7}qd||krÔt|dƒ$}| d |¡d¡Wdƒn1sÆ0Y|SdS)aA Creates a new GCP file from an existing GCP file includes only the points that reference images existing in the images_dir directory. If less than min_images images are referenced, no GCP copy is created. :return gcp_file_output if successful, None if no output file was created. NÚ*rrrFr)rrDrErTrrÚbasenameÚglobr5r r)r=rrrrG) r rHZ images_dirZ min_imagesÚfilesrJZ files_foundr(r!r r rÚmake_filtered_copy‘s  "    2zGCPFile.make_filtered_copyrc CsÚtj |¡std |¡ƒ‚t|tƒs6t|tƒs6tdƒ‚t|tƒsRt|tƒsRtdƒ‚tj  |d¡}tj  |d¡}tj  |¡r„t  |¡tj  |¡ršt  |¡|durª|  ¡}t  |¡}t  |j|¡}i} | ¡D]P} | | j| j| j¡\} } } d | | | ¡}|| vr| g| |<qÎ| | | ¡qÎt|dƒ–}t|dƒj}d }| D]P}| d  ||||¡¡| |D]"} | d  || j| j| j¡¡qb|d 7}q@Wdƒn1s¨0YWdƒn1sÈ0Y||fS) a Convert this GCP file in a format compatible with MicMac. :param output_dir directory where to save the two MicMac GCP files. The directory must exist. :param utm_zone UTM zone to use for output coordinates (UTM string, PROJ4 or EPSG definition). If one is not specified, the nearest UTM zone will be selected. :param precisionxy horizontal precision of GCP measurements in meters. :param precisionz vertical precision of GCP measurements in meters. z{} does not exist.zprecisionxy must be a numberzprecisionz must be a numberz 3d_gcp.txtz 2d_gcp.txtNú{} {} {}rFrzGCP{} {} {} {} )rDrEÚisdirÚIOErrorÚformatrWr7ÚintÚAssertionErrorr5rrTrSrrrUr r)rVr8r9r:rrrGr=r;r<)r Z output_dirZ precisionxyZ precisionzrQZ gcp_3d_fileZ gcp_2d_filer[rUr/r(Zutm_xZutm_yZutm_zr1Zf3Úf2Zgcp_nr r rÚmake_micmac_copy®s@             LzGCPFile.make_micmac_copy)NNT)r*)rrN)Ú__name__Ú __module__Ú __qualname__rr r)r3r'rAr?rrKrSr\rarir r r rrs  rc@s&eZdZd dd„Zdd„Zdd„ZdS) r6rcCs.||_||_||_||_||_||_||_dSr&)r8r9r:r;r<r=r>)r r8r9r:r;r<r=r>r r rräszGCPEntry.__init__cCsd |j|j|j¡S)Nrb)rer8r9r:rBr r rr,íszGCPEntry.coords_keyc Cs(d |j|j|j|j|j|j|j¡ ¡S)Nz{} {} {} {} {} {} {}) rer8r9r:r;r<r=r>ÚrstriprBr r rÚ__str__ðs ýzGCPEntry.__str__N)r)rjrkrlrr,rnr r r rr6ãs r6) r_rDÚopendmrrÚpyprojrrr6r r r rÚs   ]