CoolFace
Apppublic

forestaiUs/treeextraction-ndvi

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
advanced_extraction.cpython-310.pyc21 linesDownload Raw Back to __pycache__
1o

2 �Qh��@s:ddlZddlZddlZddlZddlmZddd�ZdS)�N)�transform_bounds�treesc"3Cs��z)t�d|�d|���t�|��i}|jdkrH|�d��t�}|�d��t�}|jdkr5|�d��t�n|}t�	||||d�}|dk}n
|�d�}	|	t�4|	d	�k}|j}5|jrnt
|jd6|7j|8j|9j|10j�\}}}
}nd\}}}
}Wd�n1s~wYg}|j\}}td
t||�d�}d}td||�D]�}td||�D]~}||||�|||�f}t�|�||dk�r"||}||}|||
|}||||}t|||d�}t|||d�}|||
|}||||}||g||g||g||g||gg}d||dd�d|gd�d�} |�| �|d7}q�q�d||d�WSt�yL}!zt�dt|!����dgd�WYd}!~!Sd}!~!ww)z(Simple feature extraction for HF Spaces.zExtracting z from ����g�����|�=g�������?�<z	EPSG:4326)gfffff�R�g�����LD@g�����yR�gffffffD@N�11�2rg333333�?g�?ZFeatureg�������?)�feature_typeZ12confidenceZPolygon)�typeZcoordinates)r�idZ13propertiesZgeometryZFeatureCollection)r�featuresrzError extracting features: )rr)�logging�info�rasterio�open�count�readZastype�float�npZdivideZ14percentile�boundsZcrsr�leftZbottom�right�top�shape�max�min�range�sum�append�	Exception�error�str)"Z15image_pathZ
output_folderrZsrcZredZgreenZnirZndviZmaskZbandrZwestZsouthZeastZnorthrZheight�widthZ	grid_sizeZ16feature_id�y�xZcellZx_ratioZy_ratioZlon1Zlat1Zx2_ratioZy2_ratioZlon2Zlat2Zpolygon_coordsZfeature�e�r(�V/Users/dynamicpacific/Dropbox/DEV/ForestAI-TreeExtraction/utils/advanced_extraction.py�extract_features_from_geotiffsx171819���20����21
��%���r*)r)�osrZnumpyrrZ
rasterio.warprr*r(r(r(r)�<module>s