-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from ayushanand18/maps
update: added map.points function
- Loading branch information
Showing
3 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,6 @@ | |
__all__ = [ | ||
"taxon", | ||
"stats", | ||
"diversity" | ||
"diversity", | ||
"map", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .map import points | ||
|
||
__all__ = [ | ||
"points" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |