
    c0i9                        d Z ddlZddlZddlZddlmZ dej                  d<   ddlZddl	m
Z
 defdZed	k(  rI ej                  d
      Zej!                  dd       ej#                         Z eej&                         yy)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                    | j                         } t        j                         }|dz  | z  }||  dz  }||  dz  }|j                         s.t	        d|        t	        d       t        j                  d       t	        d|j                   d       	 t        j                  |d	
      }t	        dt        |      dd       t	        d|j                          t        |      }|j                  |k7  r:t	        d|j                          d       |j                  |      }t	        d       nt	        d       |j                  |dd       t	        d|j                          t	        d       |j                   D ]<  }|dk7  s	||   j#                         j%                         }t	        d| d|dd       > t	        d       t	        |j'                                t	        d       t	        d|        t	        d |j                          t	        d!|j                          t	        d"       y # t(        $ r-}	t	        d|	        t        j                  d       Y d }	~	d }	~	ww xY w)#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
             scripts/load_buildings.pyload_buildings_gpkgr.      sD   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 !*3!5!5!7!;!;!=3%r.!33CDE %
 	-/inn 

01	M)
%&	L)
*+	M+**+
,-	
XY  's+,s    C2H7 AH7 7	I- #I((I-__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$X$$SF &CDD

# rA   