Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: added map.points function #14

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pydwcviz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
__all__ = [
"taxon",
"stats",
"diversity"
"diversity",
"map",
]
5 changes: 5 additions & 0 deletions pydwcviz/map/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .map import points

__all__ = [
"points"
]
41 changes: 41 additions & 0 deletions pydwcviz/map/map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
maps: visualize DwC data easily on maps
"""
import matplotlib.pyplot as plt
import geopandas as gpd

def points(df, crs="epsg:4326", figsize=(20,10)):
"""
Generate a point map from DwC data

:param df: [DataFrame] A DwC data DataFrame with at least decimalLongitude, and decimalLatitude
as column labels
:param crs: [String] Define the CRS for the map
:param figsize: [Tuple] Define the figsize of the plot

:return: A Matplotlib Axes Object

Usage::

from pyobis import occurrences
from pydwcviz import map

ax = map.points(occurrences.search(scientificname = "Mola mola").execute())
plt.show()
"""
gdf = gpd.GeoDataFrame(
df,
geometry=gpd.points_from_xy(df.decimalLongitude, df.decimalLatitude),
crs = crs,
)

fig, ax = plt.subplots(figsize=figsize)

gdf.plot(ax=ax, markersize=5, zorder=10, legend=True)
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world = world.to_crs(gdf.crs)
world.plot(ax=ax, color='lightgrey', edgecolor='white', zorder=1)

ax.set_axis_off()

return ax