a `eL@sddlZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl mZddlmZdd d Zdd d Zd dZddZddZddZdS)N)system)CRS) transformer) double_quote)ogr) get_originrrcCstj|st|dt|}t|}Wdn1s@0Y|d}ttj }|dD]r}|d|}| dddkrf|d|d} ttj } t |} | | d|d| d|d|| qf|d krdS|} | |} t| S) Nz does not exist.rshotsgps_dopi?Bcamerascamera)ospathisfileIOErroropenjsonloadrGeometry wkbMultiPointgetwkbPointr AddPoint_2D AddGeometryGetGeometryCount ConvexHullBuffer load_boundary ExportToJson)Zreconstruction_jsonbufferreconstruction_offsetfdatareconstructionmpZ shot_imageshotr poriginZ convexhullboundaryr+/code/opendm/boundary.pycompute_boundary_from_shots s&   (    $   r-cst|tst|}tt|dd}t |dkrJt dt ||dd}|ddkrrt d |d|d }t |dkrt d |d}t |dkrt d t |d|durt t tj|jt |fd d|D}|WdS1s 0YdS)Nzutf-8rr z/Boundary must have a single polygon (found: %s)rgeometrytypePolygonz0Boundary must have a polygon feature (found: %s) coordinateszBoundary geometry has no ringsz$Boundary geometry has no coordinatescsg|]}j|dqS)N)TransformPoint.0c dimensionstr+r, Ez!load_boundary..) isinstancestrrdumpsfionarioBytesIOencodelenrrr from_proj4crs to_string)Z boundary_jsonZreproject_to_proj4srcgeomZringscoordsr+r7r,r*s*        rcCs|dus|dur|Sg}t|d}|D]`}|dkr\||d|d|d|dfq(||d|d|d|d|dfq(|S)Nrr )rCappend)r*r"resdimsr6r+r+r,boundary_offsetIs (.rNcCs(|dur dSdddd|DdS)Nz POLYGON((z, cSsg|]}dtt|qS) )joinmapr=r4r+r+r,r:[r;zas_polygon..z)))rPr*r+r+r, as_polygonWsrScCsdtttt|S)Nz}{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[%s]}}]})r=listrQrRr+r+r, as_geojson]srUc Cst|d:}|tdddid|gddgdWdn1sJ0Ytj|rjt||t|t|d }t d j fi|dS) NwZFeatureCollectionboundsFeaturer1)r0r2)r0 propertiesr/)r0namefeatures)proj4inputoutputzrrrremoverrrunformat)r*r\Zbounds_json_fileZbounds_gpkg_filer#kwargsr+r+r,export_to_bounds_files`s$ (  rd)rr)N)r?Z fiona.crsrr@ropendmrpyprojrZopendm.locationr opendm.utilsrosgeorZ opendm.shotsrr-rrNrSrUrdr+r+r+r,s