Cloud Confusing

Explaining hosting, AWS, Wordpress, static sites, and all manner of cloud solutions.

The United Nations location code identifier system (UN/LOCODE) has an interesting system for noting the function of a specific location. Basically there is an 8-digit “classifier” which changes based on the function of the space. While logically interesting, it’ll require some custom work to parse this classifier and get written values from it.

UN/LOCODE Function Examples

For example, a location that is a:

The explanation is fairly straightforward:

It’s essentially a binary, where each part of the string the on or off, but instead of using a 1 or 0 you get the numeral for that part (with the exception of border crossings).

Parsing The Function Code

This wasn’t hugely difficult to work with, but it wasn’t exactly as straightforward as most data types you’d see when working with location data.

The code I used looked something like (with site-specific elements changed for clarity):


$check = PAGE_SPECIFIC_LOCODE;
$matches2 = ["Unknown","Port","Rail","Road","Airport","Postal Exchange Office", "Multi-use Location","Fixed Transport","Border Crossing"];
for ($i = 0; $i <= 9; $i++) {
if (str_contains($check, $i)) {
$matches[] = $i;
}
}
foreach ($matches as $m) {
$matches3[] = $matches2[$m];
}
echo implode(', ', $matches3);
}

I’m sure there is an endless number of ways to go through this, but basically this code will:

  • Loop through the LOCODE string and look for the elements in the string (1, 2, etc.)
  • Create an array of these
  • Check the array for items in another array (matches2) that are in the same position
  • Create another array of those terms
  • Print those terms with commas between them.

This will turn “-23–6–” into “Rail, Road, Multi-use Location” as you’d see above, in the example of USZJI, a location at Alpine, Los Angeles, which has a stop of the Southern Pacific Railroad (among other things).

Some of the choices here were made for specific requirements I had on the page, so it’s not a full explanation. I removed some error checks as well, which made this example overall confusing.

That said this should be enough to get you started or simply as a way to learn about this interesting classifier.

You can see it in action at this location data site.

September 16th, 2022

Posted In: Web Development

Tags:


© Cloudconfusing.com 2022 | Privacy Policy | About | UTM Creator | CVE Reporting