×

To be able to write in the forum you need to authenticate. Meanwhile it's read-only.

Re: Request for GetNumberOfCountiesInRegion and similar

Request for GetNumberOfCountiesInRegion and similar
June 28, 2017 04:41AM
I'd like to request three new functions to be created:
GetNumberOfCountiesInRegion
GetNumberOfRegionsInCountry and
GetNumberOfCountiesInCountry

This is to allow scripts to calculate the percentage of counties in a region a user has found and similar. The scripts would want to check for the return value being zero, as I assume that would be the result of calling the function on a country/region without the specified level divisions.
Re: Request for GetNumberOfCountiesInRegion and similar
June 28, 2017 11:30PM
My assumption is tha t this would be based on map data so that areas without caches would still be counted.
Re: Request for GetNumberOfCountiesInRegion and similar
June 28, 2017 11:59PM
Only if it doesn't show up the spurious entries, like "Tasmania" region in United States.
Re: Request for GetNumberOfCountiesInRegion and similar
June 29, 2017 10:37AM
Is there a current need for all three? The reason that I ask is that GetNumberOfCountiesInRegion is currently technically impossible to do right.

Project-GC doesn't keep any connections between regions and counties. It has several polygons, it also knows which country it belongs to, but it does not know if a specific county belongs to a specific region.

When implemented from the start, many years ago now, we did not know if that was how it worked in all countries, or a "county" could exist in two "regions". I have not yet seen an example of that, so it probably can't though. But still, we don't keep any relations between them.

In the cases you see relations on Project-GC, like when filtering on country, region, county, it's calculated using geocaches. From a country/region we get X number of caches, we then check which counties they are in.

There are several flaws with that, not the least that a county needs to have geocaches in it to be found/connected. There are also temporary issues where a cache can belong to the wrong region.

Example:
A geocache belongs region A (according to the cache owner). We add it in the database with that region. Afterwards we calculate that it belongs to region B instead, and update it. We also calculate it to being in county C. As a post processing after that we might see that county C has 95% of its caches in region C. The geocache will now be moved to region C instead.

That was two issues in one, both usually related to the geocache being close to a border. It's not always county polygons have a perfect match with region polygons either. Normally they should share borders ("ways" in OSM), but that definitely isn't always the case. OSM isn't consistently our source either. Sometimes region data is from one source and county from another.

While it would be interesting to fix Project-GC to actually keep relations, it's probably quite a lot of work. We would probably use the following approach:
After importing new polygons, we would see which region a county has the most overlap with, and save that as it's "parent". It doesn't sound like a lot of work and probably isn't. That's pretty much all that's required to fix the above API call, and some code to get that data. Using those relations in the rest of Project-GC is trickier though, might be many places to dig into.
Re: Request for GetNumberOfCountiesInRegion and similar
June 29, 2017 10:48AM
PGC_GetNumberOfRegionsInCountry and PGC_GetNumberOfCountiesInCountry has been implemented. A release will be made in a few minutes, and documentation updated. Though it's simple. One parameter, the country. Returns an int (>0) or false.
Re: Request for GetNumberOfCountiesInRegion and similar
June 29, 2017 01:31PM
The specific challenge which brought this suggestion up had a sub-challenge of finding all counties in a state. I thought that having functions would make future challenges easier to code (not to mention not requiring me to hard-code 50 counts).

Thanks for the two functions you have provided. I guess I'll just make do with hard-coding for now...
Re: Request for GetNumberOfCountiesInRegion and similar
June 29, 2017 01:41PM
sumbloke Wrote:
-------------------------------------------------------
> The specific challenge which brought this
> suggestion up had a sub-challenge of finding all
> counties in a state. I thought that having
> functions would make future challenges easier to
> code (not to mention not requiring me to hard-code
> 50 counts).
>
> Thanks for the two functions you have provided. I
> guess I'll just make do with hard-coding for
> now...

I am actually working on implementing the third one as well. But there are some technical issues I have to solve first. For some countries there are issues with the polygons which makes it hard. Self-intersections and such.

I am currently stuck at solving those parts. We'll see if there is any success of it. Each test takes quite a lot of times since the polygon data is quite heavy. Currently trying to cleanup Australia. From what I can see, there are issues with six different countries.

Even when I am done, it will probably take at least a day to do the calculations.
Re: Request for GetNumberOfCountiesInRegion and similar
June 30, 2017 02:36PM
It's progressing slowly. It seems like all new code to calculate the relations are in place now. The next step is to actually let the servers do the calculation, expected to take at least 24 hours. If there are any issues found on the way that will interrupt that process and add some more bug hunting.

After that the API method needs to be implemented, though that part should only takes ten minutes or so.
Re: Request for GetNumberOfCountiesInRegion and similar
June 30, 2017 09:55PM
Thank you very much. I'll look at updating my script (s) on Monday
Re: Request for GetNumberOfCountiesInRegion and similar
July 03, 2017 09:14AM
Releasing PGC_GetNumberOfCountiesInRegion(country, region) in a few minutes.
Re: Request for GetNumberOfCountiesInRegion and similar
July 04, 2017 04:18AM
Thank you very much.
Sorry, you do not have permission to post/reply in this forum.