Best strategy for a Firestore database for municipalities - firebase

Here in Italy the land is politically divided into regions, provinces and municipalities. For example I live in the city of Varazze, whose province is Savona, in the region of Liguria.
I created a Firestore database that accepts businesses whose addresses are composed like the example up here. Nothing difficult as I use an external service which give me consistent and correct geo data. The rest of the information for the business is entered by the user.
Now I need to search into this db of businesses by region and/or province and/or municipality. To set up the UI with the filter, I absolutely need to show only regions, provinces and municipalities that have a business into the db and not all those available (FYI: Italy has 21 regions, 107 provinces and ~8000 municipalities).
Looking down the internet and here on SO, I understand that the best strategy is to create a new collection to store distinct data about the location, separated from the businesses collection, in order to enable a quicker lookup. So every time I add or edit a business I check if it's region, province and municipality exists in the "search collection" (let's name this way) and if not, add it.
But how to structure this collection?
If I use the municipality as key, I'll have a quick lookup for the municipality itself (at top will be 8000 records), but if I need to search by a region or province the result is poor because firestore does not have any way to "distinct" the results (something like SELECT DISTINCT province FROM geocollection WHERE Region='Liguria' if you want to visualize it in SQL) and I have to do it on a server or at worst on the client (not an option this last one).
I don't know if staring with the region and keeping the structure region -> province -> municipality is the way to go. Or going for the province, being halfway between.
Another way could be to have separate collection for regions, provinces and municipalities.
What I'm asking here is what is the best solution, in terms of performance and data complexity.

A good way to go on this would be to have a collection Regions, then each Region has a Collection Provinces, and each province has a collection Municipalities.
And the documents have the name of the geografic region as ID, This will allow you to lookup by the ID on the corrisponding collections.

Related

Reverse geocode latitude/longitude coordinates to retrieve landuse data (eg. residential area, highway, etc.)

I would like to analyse the locations of electric vehicle charging stations for Germany, Italy and France. Those three countries, because they differ quite a lot in regard to their respective incentive programmes for public charging station infrastructure.
What I have so far are .csv exports from both OpenChargeMap and OpenStreetMap containing the location data (latitude and longitude) of all charging stations in those three countries along with a few other information that I can process in R.
What I would like to do now is some sort of reverse geocoding on those latitude and longitude coordinates to retrieve additional information on the surroundings. Especially, whether the respective charging station is located in a residential area in a city for example or at a rest stop on the highway. By knowing at what kind of locations the charging stations are placed in those three countries I am hoping to be able to draw conclusions regarding the incentive programmes. I'm not looking for specific addresses in this case, but rather an API or another way to process thousands of coordinates and retrieve information regarding for example population density or any other piece of data from which I could derive conclusions.
I have tried to get OpenStreetMap exports to work, but unfortunately I cannot seem to be able to query for the 'landuse' attribute through the Overpass Turbo API. This is my basic query that I'm using in this specific API, but as soon as I query for ["landuse" = "residential"] instead of ["landuse" = ""] I get prompted empty fields as result.
I found an API from Google which would offer lookup for various address components/types. Unfortunately, registering an API key at Google is not quite realistic for the scope of my work. Does somebody know of a (preferably FOSS) API that is able to do something like this? Or even how to make a 'landuse' query work in the Overpass Turbo API linked above?
Thank you in advance for your time.
Your Overpass API query is looking for elements that are tagged as amenity=charging_station and landuse. This is rather uncommon since charging stations and landuse are mapped as distinct objects. Instead you need to look around charging stations for landuse elements.
So instead of
area["ISO3166-1"="DE"]->.a;
nwr(area.a)["amenity"="charging_station"]["landuse"=""];
you will need a query like
area["ISO3166-1"="DE"]->.a;
nwr(area.a)["amenity"="charging_station"];
way(around:200)["landuse"];
This searches for ways with a landuse tag located within 200 meters of charging stations.
Note that this is a rather heavy query. You should probably use your own Overpass API server for it.

Dimension for Provinces of Spain

We have a report that is populated by different platforms (Salesforce, DB etc.) and now we are going to add Analytics data to that.
In our report for Spain, we use 'Province' values (Madrid, Barcelona, Málaga).
When I am getting data from Google Analytics, there are dimensions: Region and City but the problem is, values of Region are Autonomous Communities+Cities and values of City are Municipalities.
Is there any field/dimension I can use to group my data by Provinces?
There's no built-in dimension for that. All you can do is to build an almost 100% matching table using Google Ads geo targets table from here https://developers.google.com/adwords/api/docs/appendix/geotargeting
the underlying table
(consider checking for proper language version)

Concur / Cognos Report Studio - Create Report of Travel Destination Countries

this question is very specific to the Concur implementation of the IBM Cognos Report Studio tool since it primarily focuses on the data model used therein.
It contains business travel expense information including the travel itineraries, which are the main source of this report:
Itinerary Example
My goal now is to create a report showing which destination countries the employees traveled to (all countries if more than one country was visited in a single itinerary), how many single business trips were taken to that destination country/countries, the average duration of the business trips to that destination country/countries and the number of all trips. If possible, duration of stay by country would be great, but i have no idea how to go about that. Mockup
Using a repeater based on the field [Arrival Country] from the itinerary, i managed to get something that looks what i am trying to achieve, but it somehow does not include the home country once i cut out the other identifying columns (Itinerary Key, Departure Country, Arrival Country).
I then did a count(distinct([Itinerary Key] for [Arrival Country Repeater] which gave me numbers, but i am not really sure they are correct in this case.
Repeater
Also, as soon as i add query calculations to include the average duration, the repeater fields go blank.
Is there another way to get the report i want to build?
Are there major flaws with my attempt?
Thanks a ton for any and all suggestions!

Drupal, Ubercart: is there a way to select all Europeans / Not-Europeans countries in the shipping settings?

I usually create conditional rules with shipping to assign different costs for:
national shipping (a specific country is selected)
and international shipping (the same country is selected but a NOT is added to the condition)
I have now to assign different shipping costs according to Europe / Not Europe. A solution would be to select all countries in Europe, but I was wondering if there is a faster way
thanks
For the sanity of your users just do it the way everybody else does!
Have a country pull down with a list of all supported countries in it. Defaulting to you "home" nation.
If you are sending stuff there are a lot more considerations than just shipping costs, you may need to fill in specific tax forms for some countries and depending on what your site is selling you may need special processing for some countries (try sending coffee to Thailand -- you need to obtain permission from thier ministry of agriculture!).
Create the different shipping methods at admin/store/settings/quotes (one for Europe, one for non-Europe).
Add a Rule by editing the new shipping method and adding a condition
or go to the Rules config at admin/workflow/rules
Use a text comparison condition with a order:delivery-address:country data selector
In the value field place the regular expression to match any of the desired country names, for example the list of EU member states below.
Maybe it could be done with postal codes too, but I do not know how they are structured. Everyone keeps their sanity.
(\W|^)(Austria|Belgium|Bulgaria|Croatia|Cyprus|Czech|Republic|Denmark|Estonia|Finland|France|Germany|Greece|Hungary|Ireland|Italy|Latvia|Lithuania|Luxembourg|Malta|Netherlands|Poland|Portugal|Romania|Slovakia|Slovenia|Spain|Sweden|United\sKingdom)(\W|$)

retrieving a updated list of countries states and cities in a website

I'm trying to create a User Registration page in ASP.NET and wondering what
is the best way to get the list of up-to-date Countries and Cities? Are
there any Web Services on the web that I can use to retrieve such
information? If not, what are the options?
Please, any suggestions and pointers will be very much appreciated
How about this? http://www.maxmind.com/app/web_services_country_usage
I have not tried it myself though.
You can check angrymonkeycloud.com/geography to get full list of countries and their states (subdivision).
You can even get countries primary language and currency to set it as your users default settings.
There are a lot of sources for the information on complete lists of countries and major cities. The United Nations Statistics Division's annual demographic yearbook has a list of major cities > 100K population in CSV format:
http://unstats.un.org/unsd/demographic/products/dyb/dyb2012/Table08.xls
The CIA World Factbook also has a list of major cities in the world at:
https://www.cia.gov/library/publications/the-world-factbook/fields/2219.html
They also keep a list of bitmap images for the corresponding country flags:
https://www.cia.gov/library/publications/the-world-factbook/docs/flagsoftheworld.html
I also keep a large links and copies of these types of datasets in our own custom CSV format at this URL:
http://www.opengeocode.org/cude1.1/index.php
Yes I worked for an organization that used this: http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm for countries; there are other sources too that are valid that I can't currently find. There are state code lists but I haven't seen city. I've not seen any web services offerings; the one listed below was news to me...
We typically attempted to standardize with these codes, loaded them into a database, and even had a central database with these values that other DB's referenced too.
HTH.

Resources