Skip to content

Commit

Permalink
Merge pull request #14 from ayushanand18/maps
Browse files Browse the repository at this point in the history
update: added map.points function
  • Loading branch information
7yl4r authored Jan 9, 2023
2 parents b06736e + 3a98686 commit 695f793
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
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

0 comments on commit 695f793

Please sign in to comment.