I am fresh as a baby’s bottom with coding. Have been learning the last two months and I need help. I am trying to match NASA algorithmic fire growth data to final perimeter data measured on the ground to see if deployed pods are efficient in fire mitigation over time. The fire grows over a 12-hour incremental time in row “t” for as many days as it burns. I can’t just load the data into ArcGIS and do a merge and clip because all the outside pieces of the perimeters get assigned to the last day instead of aligning with the actual day they burned on. I wrote the following code to go over each row, buffer, and clip to the perimeter if it is close enough, if not just leave as is. When I plot this data, I am getting the exact polygons I need in the first code i wrote, but it is giving me a CRS error. I was also told to use for “i in range(len(cameron_peak_sorted))” instead by a supervisor, but when I do that, I doesn’t plot at all. I have both pieces that I wrote below. I know what the majority of this stuff does, but I am brand new to this stuff. Help please! I can only get so far with chat GPT and google haha!
CODE I Wrote:
cameron_peak_sorted = cameron_peak_data_Nasa.sort_values(by='t')
# Convert the first row to a GeoSeries
meters = 100
degrees = meters / 111000 # conversion factor from meters to degrees
cpnasa = cameron_peak_sorted.iloc
for i in cpnasa:
# Convert the first row to a GeoSeries
current_day_row_nasa = gpd.GeoSeries(i['geometry'])
# Convert OneDay_row_NASA to a GeoDataFrame
current_day_row_nasa_gdf = gpd.GeoDataFrame(geometry=gpd.GeoSeries(current_day_row_nasa))
buffered_cameron_peak = cameron_peak_data_NIFC.buffer(degrees)
# Create a unary union of the buffered geometries to handle multiple polygons
buffered_union = buffered_cameron_peak.unary_union
# Check for intersections and adjust geometries
current_day_row_nasa_gdf['adjusted_geometry'] = current_day_row_nasa_gdf.apply(
lambda row: row['geometry'].intersection(buffered_union) if row['geometry'].intersects(buffered_union) else row['geometry'],
axis=1
)
# You must now remove the negative buffer
current_day_row_nasa_gdf['Removebuffered_adjusted_geometry'] = current_day_row_nasa_gdf['adjusted_geometry'].buffer(-degrees)
current_day_nasa_poly = current_day_row_nasa_gdf['Removebuffered_adjusted_geometry']
clipped_data = current_day_nasa_poly.intersection(cameron_peak_data_NIFC.unary_union)
clipped_data.plot()
plt.plot([],[]," ", label = "Report for " + i.t)
plt.legend()
plt.show()
Error:
C:UserselktifAppDataLocalTempipykernel_186242526076382.py:12: UserWarning: Geometry is in a geographic CRS. Results from ‘buffer’ are likely incorrect. Use ‘GeoSeries.to_crs()’ to re-project geometries to a projected CRS before this operation.
CODE I tried to write to meet recommendation by supervisor:
cameron_peak_data_NIFC = cameron_peak_data_NIFC.to_crs("EPSG:4326")
cameron_peak_sorted = cameron_peak_data_Nasa.sort_values(by='t')
meters = 100
degrees = meters / 111000 # conversion factor from meters to degrees
all_clipped_gdfs = []
for i in range(len(cameron_peak_sorted)):
current_row = cameron_peak_sorted.iloc[i]
current_day_row_nasa = gpd.GeoSeries(current_row['geometry'])
current_day_row_nasa_gdf = gpd.GeoDataFrame(geometry=gpd.GeoSeries(current_day_row_nasa))
buffered_cameron_peak = cameron_peak_data_NIFC.buffer(degrees)
buffered_union = buffered_cameron_peak.unary_union
current_day_row_nasa_gdf['adjusted_geometry'] = current_day_row_nasa_gdf.apply(
lambda row: row['geometry'].intersection(buffered_union) if row['geometry'].intersects(buffered_union) else row['geometry'],
axis=1
)
current_day_row_nasa_gdf['Removebuffered_adjusted_geometry'] = current_day_row_nasa_gdf['adjusted_geometry'].buffer(-degrees)
current_day_nasa_poly = current_day_row_nasa_gdf['Removebuffered_adjusted_geometry']
clipped_data = current_day_nasa_poly.intersection(cameron_peak_data_NIFC.unary_union)
clipped_gdf = gpd.GeoDataFrame(geometry=gpd.GeoSeries(clipped_data))
all_clipped_gdfs.append(clipped_gdf)
# Concatenate all GeoDataFrames in the list into one GeoDataFrame
all_clipped_gdf = gpd.GeoDataFrame(pd.concat(all_clipped_gdfs, ignore_index=True))
all_clipped_gdf = all_clipped_gdf.to_crs("EPSG:4326")
# Plot the concatenated GeoDataFrame
all_clipped_gdf.plot()
plt.title("Report for " + str(current_row['t'])) # Assuming 't' is a timestamp column in your DataFrame
plt.show()
Final Cameron Peak Fire Perimeter
NASA Algorithmic Fire Growth
Second 12-hour measurement Buffer with final perimeter
Second 12-hour measurement buffer and clip (Final product)
First 2 12-hour measurements final product with CRS Error
Tiffany Elkins is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.