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

Get Country Code #131

Closed
mnaranjo opened this issue Apr 3, 2024 · 5 comments
Closed

Get Country Code #131

mnaranjo opened this issue Apr 3, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@mnaranjo
Copy link

mnaranjo commented Apr 3, 2024

Hello,

What would I have to do to obtain the 'country code' of a vessel?

Thank you in advance

@M0r13n
Copy link
Owner

M0r13n commented Apr 4, 2024

Hey @mnaranjo,

which country code are you referring to? As far as I know, there are two types of "country codes" in AIS messages:

Neither is currently implemented in pyais. Support for the MID could easily be added. The latter is a rather rare type of message that is very specific and almost never occurs in real world scenarios. Therefore, I am a bit hesitant to add support for this subtype.

@mnaranjo
Copy link
Author

mnaranjo commented Apr 4, 2024

Hi @M0r13n ,
I was referring to the possibility to know the flag of the ship, i.e. to know which country each ship belongs to when data is collected.

@M0r13n
Copy link
Owner

M0r13n commented Apr 4, 2024

@mnaranjo This can only be achieved by examining the first digits of the MMSI. These two articles explain how this works:

As of right now, pyais does not provide the functionality to extract the country/flag from the MMSI. However, I believe that I will add this feature in the near future

@M0r13n M0r13n added enhancement New feature or request question Further information is requested labels Apr 4, 2024
@M0r13n M0r13n self-assigned this Apr 4, 2024
@mnaranjo
Copy link
Author

mnaranjo commented Apr 4, 2024

Thank you very much for your help.

@M0r13n
Copy link
Owner

M0r13n commented Apr 5, 2024

Hey @mnaranjo,

with the newest version of pyais you can get the country code and name:

from pyais.util import get_country

# The first 3 digits of any MMSI number are indicative of the vessel's flag
country_code, country_name = get_country(249110000)
assert country_code, country_name == ('MT', 'Malta')

@M0r13n M0r13n closed this as completed Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants