
    c0i9                         S r SSKrSSKrSSKrSSKJr  S\R                  S'   SSKrSSK	J
r
  S\4S jr\S	:X  aC  \R                  " S
S9r\R!                  SSS9  \R#                  5       r\" \R&                  5        gg)a#  
Loads extracted buildings GeoPackage and reprojects to a local UTM CRS for analysis.

This script complements load_gpkg.py by handling buildings data specifically.
It reprojects buildings from WGS84 to a meter-based UTM coordinate system
suitable for spatial analysis and grid aggregation.
    N)Path0
USE_PYGEOS)determine_utm_crsstatec                    U R                  5       n [        R                  " 5       nUS-  U -  nX  S3-  nX  S3-  nUR                  5       (       d/  [	        SU 35        [	        S5        [
        R                  " S5        [	        SUR                   S35         [        R                  " US	S
9n[	        S[        U5      S S35        [	        SUR                   35        [        U5      nUR                  U:w  a:  [	        SUR                  5        S35        UR                  U5      n[	        S5        O[	        S5        UR                  USSS9  [	        SUR                   35        [	        S5        UR                    H>  nUS:w  d  M  XW   R#                  5       R%                  5       n[	        SU SUS S35        M@     [	        S5        [	        UR'                  5       5        [	        S5        [	        SU 35        [	        S UR                   35        [	        S!UR                   35        [	        S"5        g ! [(         a.  n	[	        SU	 35        [
        R                  " S5         S n	A	NS n	A	ff = f)#Noutputz_buildings.gpkgz_buildings_projected.gpkgu   ❌ Buildings file not found: z=   Run extract_state_buildings.py first to extract buildings.   u!   📦 Loading buildings data from z...	buildings)layeru   ✅ Loaded ,z
 buildingsu   📋 Current CRS: u    🔄 Reprojecting to local UTM (z)...u   ✅ Reprojection completeu#   ✅ Buildings already in target CRSbuildings_projectedGPKG)r   driveru#   💾 Saved projected buildings to: u$   
📋 Building attributes available:geometryz  z: z non-null valuesu   
🔍 Sample buildings data:u   ❌ Processing failed: u#   
✅ Buildings processing complete!u   📁 Folder: u   📥 Input: u   💾 Output: uL   🔄 Next: Run visualize_all_attribute_grid.py to generate building heatmaps)lowerr   cwdexistsprintsysexitnamegpd	read_filelencrsr   	to_stringto_crsto_filecolumnsnotnasumhead	Exception)
r   base_dir	state_dir
input_pathoutput_pathr   
target_crscolnon_null_countes
             (/data2/heatmap/scripts/load_buildings.pyload_buildings_gpkgr.      sA   KKMExxzH8#e+Iwo66J'@AAK.zl;<MN	-joo->c
BCMM*K@	C	N1-Z89"9==/23&y1
==J&4Z5I5I5K4LDQR!((4I-.78 	+-B6R3K4D4D3EFG 	57$$Cj !*!5!5!7!;!;!=3%r.!33CDE %
 	-/inn 

01	M)
%&	L)
*+	M+**+
,-	
XY  's+,s    C-H; AH; ;
I3$I..I3__main__z=Load and reproject extracted building footprints for a state.)descriptionzState name (e.g., alabama).)help)__doc__argparser   ospathlibr   environ	geopandasr   scripts.crs_utilsr   strr.   __name__ArgumentParserparseradd_argument
parse_argsargsr        r-   <module>rB      s     
 	  

<   /3Zs 3Zl z$$SF &CDD

# rA   