Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

from pathlib import Path

import folium
import galah
import geopandas as gpd

galah.galah_config(
    email="ala.italics539@simplelogin.com",
    atlas="Australia",
)
tasmania = gpd.read_file(Path.cwd().parent / "data/vector/tasmania_boundary.geojson")
aoi = gpd.read_file(Path.cwd().parent / "data/vector/proposed_study_sites.geojson")

target_species = [
    "Lagarostrobos franklinii",
    "Athrotaxis cupressoides",
    "Athrotaxis selaginoides",
    "Athrotaxus laxifolia",
    "Nothofagus gunnii",
    "Nothofagus cunninghamii",
    "Diselma archeri",
]
occurrences = galah.atlas_occurrences(
    taxa=target_species,
)
occurrences = occurrences.dropna(subset=["decimalLongitude", "decimalLatitude"])

occurrences_gdf = gpd.GeoDataFrame(
    occurrences,
    geometry=gpd.points_from_xy(
        occurrences["decimalLongitude"], occurrences["decimalLatitude"]
    ),
    crs="EPSG:4326",
)
occurrences_gdf = occurrences_gdf.to_crs("EPSG:7855")
# Display 10 random records from the dataframe

occurrences_gdf.sample(10)[
    ["eventDate", "scientificName", "dataResourceName", "occurrenceStatus"]
]
Loading...
if tasmania.crs != occurrences_gdf.crs:
    tasmania = tasmania.to_crs(occurrences_gdf.crs)

tas_occurrences = gpd.sjoin(
    occurrences_gdf, tasmania, how="inner", predicate="intersects"
)

tas_occurrences.to_file(
    Path.cwd().parent / "data/vector/ala_occurences.geojson", driver="GeoJSON"
)
m = folium.Map(
    location=[-42.0, 147.0],
    zoom_start=7,
    tiles="OpenStreetMap",
)
for idx, row in aoi.to_crs("EPSG:4326").iterrows():
    folium.GeoJson(
        row["geometry"],
        style_function=lambda x: {
            "fillColor": "none",
            "color": "red",
            "weight": 2,
            "fillOpacity": 0,
        },
    ).add_to(m)

species_colors = {
    "Lagarostrobos franklinii": "red",
    "Athrotaxis cupressoides": "blue",
    "Athrotaxis selaginoides": "green",
    "Athrotaxus laxifolia": "purple",
    "Nothofagus gunnii": "orange",
    "Nothofagus cunninghamii": "darkred",
    "Diselma archeri": "pink",
}

for idx, row in tas_occurrences.to_crs("EPSG:4326").iterrows():
    species = row["scientificName"]
    color = species_colors.get(species, "gray")

    folium.CircleMarker(
        location=[row.geometry.y, row.geometry.x],
        radius=2,
        popup=f"{row['scientificName']}",
        stroke=True,
        fill=True,
        fillColor=color,
        color=color,
        fillOpacity=1,
        tooltip=row["scientificName"],
    ).add_to(m)

legend_html = """
<div style="position: fixed;
            bottom: 25px; right: 25px; width: 150px; height: 175px;
            background-color: white; border:1px solid grey; z-index:9999;
            font-size:8px; padding: 4px">
"""
for species, color in species_colors.items():
    legend_html += (
        f'<p><i class="fa fa-circle" style="color:{color}"></i> <i>{species}</i></p>'
    )
legend_html += "</div>"

m.get_root().html.add_child(folium.Element(legend_html))

m
Loading...