How-to check if your station is in a polygon-defined area

Solution: a small PHP-function script.
It will get two items
→ the latitude-longitude of the weather-station
→ the polygon-array (latitude,longitudes) of the warning-area
It should
→ do some basic checking on the two items.
→ return “true” if the station latitude-longitude is in the polygon area, “false” if not.


Seems a simple-to-do request, probably it is already programmed a few times.
Who can point me to such a script?


Background:
Sweden and Switzerland are the first countries two pwsWD users noticed were switching to the “new” warning area’s Meteoalarm.org is now implementing.
For more info → topic:

MeteoAlarm seems to be moving from fixed warning-areas to “polygon” defined areas.
In the past: “Skagerrak”
Now: “58.761,10.59018 58.7192,…0.60116 58.761,10.59018”

Also they dropped the use of 1 fixed code for a certain area for descriptive texts
F.i. the fixed code SE803 was used for the area South Sea of Bothnia
That SE803 type code we use to get the warning for our station area or areas.

The “standard” area descriptions seems also to used more free formatted / descriptive
In the past: South Sea of Bothnia
Now: Southern Sea of Bothnia or “Parts of Norrbotten”


For now, most weather-stations can select the warning area they want to use with a simple are-code. But probably other countries will be moving from fixed areas to polygon areas and free text area descriptions.

The last two weeks I was checking the data for Sweden and Switzerland to find a new item to quickly select warnings for 1 station.

There is none, the “area descriptions” (1 for each language used) change based on the warning type and or polygon area.

I was wondering if either I myself have to write and test this function, or if someone has that code or want to write it.

Wim

P.S.
A polygon for one area in Sweden looks like a long string of lat,lon values.
To make it readable I added linefeeds

65.671856,21.473649 65.476508,21.616544 65.36222794789064,22.068724629403548 65.37781,22.14964 65.37979,22.24471 
65.37979,22.29938 65.36095,22.36355 65.34408,22.42535 65.34507,22.47526 65.37285,22.52993 65.40357,22.54894 
65.42733,22.56558 65.44217,22.60836 65.45206,22.66065 65.45898,22.70581 65.47084,22.75573 65.48861,22.79375 
65.5192,22.82703 65.54225,22.82981 65.55861,22.83178 65.61271,22.81752 65.63137,22.85555 65.63628,22.93636 
65.63137,22.98865 65.63387,23.00983 65.64118,23.07184 65.65786,23.117 65.68348,23.16217 65.69915,23.36658 
65.70403,23.67069 65.69706,23.74447 65.70294,23.78013 65.71687,23.80832 65.72643,23.82766 65.74403,23.86331 
65.75673,23.90847 65.76162,23.95839 65.75966,23.99404 65.75907,23.99571 65.74696,24.02969 65.74012,24.0487 
65.74012,24.09862 65.74598,24.13665 65.77822,24.12714 65.80327,24.11939 65.9114,24.11001 66.07057,23.97638 
66.1687,23.87252 66.18634,23.77621 66.22172,23.70744 66.27485,23.66621 66.33973,23.6467 66.41636,23.64889 
66.48035,23.70186 66.48155582303544,23.704297256887497 66.596312,23.325789 66.64209,22.886111 66.526392,22.358499 
66.396961,22.094693 66.213739,21.633032 65.926313,21.479145 65.671856,21.473649

This code looks like it would work to find if point is in a polygon:

The first tested version of the adapted meteoalarm scripts are available, but only for

  • those users who really need them
  • those users who have a separate test-website and want to help testing

Check here the list of updated scripts after October 31, 2023
One needs a support token to download the scripts.

I will work on improving the “inside-outside the polygon” part of the script and upload a new version next week.

Wim