mammaldiversity / mammaldiversity.github.io

(work in progress) Mammal Diversity Database website
MIT License
5 stars 9 forks source link

add way to visualize geographic range by 'countryDistribution' column #13

Open n8upham opened 4 years ago

n8upham commented 4 years ago

The idea would be to display a very rough world map with the country highlighted would be an interesting output -- possibly via Google tools to make it a zoom-able map

n8upham commented 2 years ago

@jdhan39 Let's start here -- some ideas for features:

n8upham commented 2 years ago

@jdhan39 Here is the parsed list of 238 countries: MDD_countryList.txt

jhpoelen commented 7 months ago

hey @n8upham - I took some steps towards map integration.

Roughly three parts -

  1. render a map with a given polygon
  2. lookup country code for a country name
  3. lookup a polygon for a country code

for 1. I've used leafletjs.org and gadm.org to create sample page at https://www.mammaldiversity.org/map

Note the polygon for boundary of the Netherlands (iso 3166-1 alpha-3 code "NLD")

image

For 2. I've used wikidata to populate a lookup table https://github.com/mammaldiversity/mammaldiversity.github.io/blob/master/_data/countryCodes.csv via https://github.com/mammaldiversity/mammaldiversity.github.io/blob/master/_data/countryCodes.sh .

Following, I've generated some dynamic javascript (generated javascript) to help lookup the country codes for countries listed in countryDistributions.

Screenshot from 2024-01-29 19-13-19

So, next up would be to put 1. and 2. together and embed the map widget into the species info page.

n8upham commented 7 months ago

Hey @jhpoelen -- this is fantastic. Thank you for putting these initial steps mapping together and thinking through this. You are 100% on the right track from what I can see.

Questions: (1) Are you imagining that an expanded range map of Netherlands + Germany would == the two polygons side-by-side? That makes sense to me.
(2) Would it be possible to enable downloads of those per country maps? I see that the whole set is available here (https://datahub.io/core/geo-countries) so maybe best to just link to that

There is an aspect of this similar to the iNaturalist "Atlas" pages, which creates a political boundary background to the point occurrence and range map data -- see: https://www.inaturalist.org/pages/atlases -- I just mention that in case it gives more inspiration.

jhpoelen commented 7 months ago

Hey @n8upham -

I implemented a first pass at the distribution map visualization. See attached for rendering of https://www.mammaldiversity.org/explore.html#genus=Tachyglossus&species=aculeatus&id=1000002

Curious to hear your thoughts.

Some notes:

  1. matching to resolve country codes is using a lookup table derived from wikidata and https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3 . Some mappings are problematic because mdd uses the non-standard common country names (e.g., Ireland), not the standard codes (e.g., IRL). This leads to funny situations with "Republic of Ireland" (the country) vs. "Ireland" (the country and island). Note that country name in the distributions text that do not have following country code in parenthesis (e.g., Canada (CAN)) may need some TLC to be included on the distribution map.

  2. map library leafletjs.org is used in combination with openstreet maps. These are commonly used tools, and can be configured as desired. I've taken the fastest route to implementation, so I am sure there's way to improve the user experience. . .

Screenshot from 2024-01-30 16-53-02

JelleZijlstra commented 7 months ago

Very nice! A few thoughts:

jhpoelen commented 7 months ago

Happy to help with standardizing country names used in MDD geographical data so that they're all easy to process.

I'd say it'd be nice to use country codes instead of names . . . but @n8upham probably has some ideas on this too.

Country borders are obviously not very granular; in your example it's unfortunate that all of Indonesia is outlined when echidnas of course only occur in a small part of the country. Maybe we should show some disclaimer text stating that the true distribution may be much smaller.

please note that GADM has polygons for subdivisions also.

e.g., see attached screenshots from their Indonesia shapes, with and without subdivisions https://gadm.org/maps/IDN.html

Screenshot from 2024-01-30 17-49-23 Screenshot from 2024-01-30 17-49-18

n8upham commented 7 months ago

Amazing work @jhpoelen ! I have this working on my side via Firefox and Chrome, but I had two complaints earlier today that the Search function was not working for folks. Maybe the install of the new javascript libraries is causing conflict?

It could be a separate issue, but the same folks are complaining that they need to add "www" to the URL where they used to be able to just use "mammaldiversity.org" -- mentioning that here in case its also relevant. Any thoughts?

Aside from that technical issue, I think you accomplished this task in record time Jorrit.

Adding subdivisions of the countries would be a great next step -- we actually have a 'subregionDistribution' field in the CSV, but it is only populated for certain countries + the USA. Could you implement this for the USA states with an option for it to populate as we curate additional data in the column?

Thanks much

n8upham commented 7 months ago

I just noticed that no species in the USA are showing up currently -- e.g., https://www.mammaldiversity.org/explore.html#genus=Peromyscus&species=maniculatus&id=1002307 -- I think because of the country code not being there for "United States (USA)"?

jhpoelen commented 7 months ago

I think because of the country code not being there for "United States (USA)"?

United States of America would map to ISO 3166-1 alpha-3 country code USA.

https://github.com/mammaldiversity/mammaldiversity.github.io/blob/542e81a6c879f195fe26364b6aaf81e3ffd48cd7/_data/countryCodes.csv#L12

n8upham commented 7 months ago

Ah okay, then one (some hacky) way to fix this would be to add a row for: USA,United States,http://www.wikidata.org/entity/Q30 But I wouldn't want to break this by doing that. Better would be for us to amend the CSV of the MDD taxonomy to standardize the name of "United States" to "United States of America"

n8upham commented 7 months ago

Okay, turns out the MDD has "United States" in a consistent way throughout (not "United States of America") so the easier thing indeed was to change the entry in the countryCodes.csv lookup table.

I needed to make a spelling change to one species, so I did that change + this countryCode one in the v1.12.1 version update. USA maps appear to be working now!

jhpoelen commented 7 months ago

Great to see you improvised to help align country names with the polygons published by GADM. Curious to see how MDD will end up standardizing their country names (and other terms . . . ).

image

jhpoelen commented 7 months ago

re: I had two complaints earlier today that the Search function was not working for folks. Maybe the install of the new javascript libraries is causing conflict?

I am not quite sure what it means that "the search function was not working for folks." Can you provide an example?

jhpoelen commented 7 months ago

It could be a separate issue, but the same folks are complaining that they need to add "www" to the URL where they used to be able to just use "mammaldiversity.org" -- mentioning that here in case its also relevant. Any thoughts?

Yeah, I noticed that too. Probably a DNS related issue.

n8upham commented 7 months ago

I am not quite sure what it means that "the search function was not working for folks." Can you provide an example?

Yeah no worries about this one actually -- it was a vague complaint that I couldn't replicate either.

jhpoelen commented 7 months ago

@JelleZijlstra @n8upham Just checking in on the recently added country distribution feature. Is the feature working as expected?

What new issues can we open related to this? I can think of some (e.g., use standardized country codes in addition to vernacular country names to help facilitate linking to gazetteers like GADM).