How to broaden coordinates from a location query? - python

I have an application where the user can enter a location query such as :
Corinth
The application will add a postfix ",Greece" and calculate the latitude and longitude coordinates for the city. So, the query for the coordinates will be Corinth, Greece.
After, that the application returns the weather forecast for that location using DarkSkyApi. I want to only return forecasts for my country, which is Greece.
The problem is that if a user types : London. Then, the location will return the coordinates of some obscure location in Greece (eg. a cafe) and give a forecast for that location. I think this creates confusion, because it gives the impression of a bug and that the app can predict forecasts for other countries as well.
On the one hand, I want it to be specific enough to work for cities (eg. Athens), villages & neighborhoods (eg. Acropolis). On the other, not for minor locations (eg. cafes).
How can I go about fixing that? If somebody gives a very minor location or foreign city, I would like it to default to the capital city 'Athens', or somehow "broaden" the coordinates to the nearest city. Is there a way, to limit the coordinates somehow or filter the locations ? Is there a way to determine whether the coordinates are for a minor or large location ?

Related

Open source data of the world map that includes longitude and latitude information along with land and sea indicator

I've came across OpenStreetMap and it's too large with unnecessary data for my use case.
What I'm searching for is an exact replica of the world map tagged with longitude and latitude information along with an indicator showing whether it's a land or sea, with clear contours of land. I need to be able to draw objects on it and plot it using scripting language like Python. Longitude and latitude information are required for objects I'm plotting and clear contours of land to verify that my plot overlayed above my region of interest.
https://simplemaps.com/data/world-cities provides coordinates of countries and its cities but it'd be better to know how large each country is, hence the requirement of land contours. Any other representation of data is acceptable as long as it is able to indicate that there's land.
you might want to have a look at the NaturalEarth datasets...
https://www.naturalearthdata.com/downloads/
They provide land and ocean shapefiles (and much more) which should fit your purpose.

How to use Spatial Smoothing on relativities at postcode level in Python

I'm after some help with how I can use Spatial smoothing on my data which I have attached.
What I'd like is for neighboring postcodes to not have such a large difference in relativities.
Just to provide little more about these relativities - they are used in calculating the premium charged to a customer for home insurance.
I also have a postcode file which contains for all postcodes in the UK their longitude and latitude coordinates.
Please see attached a small subsection of my data for your reference.

Removing duplicate labels within a given radius

I have 500.000 data of house number (address) with longitude and latitude in a particular area, but I don't want there is the same house number within a 50m radius. Do you know how to detect the existence of the same adjacent numbers within a 50m radius?
is there any method in python, PostGIS, ArcGIS, QGIS, or another spatial tool to solve this?
Thank you.

Map of all points below a certain time of travel?

My question is very simple and can be understood in one line:
Is there a way, tool, etc. using Google Maps to get an overlay of all surface which is below a certain time of travel?
I hope the question is clear, but I coulnd't find anything related on the web.
If you have any information, I'll take it!
Here is what I mean illustrated by an example:
I search for a new place to live. I know the precise address of my office.
I would in this case be able to overlay on Google Maps the surface which is under a certain time of travel (let's say 30 minuts by car).
We would have a long surface colored around motorways (because you get faster), and colors around roads.
I think you are looking for something like Mapnificient: it shows you areas you can reach with public transportation in a given time (video).
A similar site with even more options is How Far Can I Travel. Here you can choose between inputting your speed of travel and a travel time OR a distance. Optionally, you can also specify how accurate you want the results to be.
Now, how to create such examples yourself? See this related question where the accepted answer explains step-by-step, how you can get travel time data from the Google Maps API.
Finally, for $8.75, you can buy the article Stata utilities for geocoding and generating travel time and travel distance information by Adam Ozimek and Daniel Miles that describes traveltime, a command that uses Google Maps to provide spatial information for data.
The traveltime command takes latitude and longitude information and
finds travel distances between points, as well as the time it would
take to travel that distance by either driving, walking, or using
public transportation.
Other than the ones in #BioGeek answer, here are some more:
Nokia Here Maps API can give you the exact shape of the output. They call it time-based isoline. See here: Requesting a time based isoline
For travel times under 10 minutes, Isoscope is available at this address.
Also this looks promising: Route360
Update:
Route360 can be used for free in the following places:
Africa
Austria
Australia and New Zealand
British Isles
British Columbia
Czech Republic
Denmark
France
Germany
Italy
Malaysia, Singapore, and Brunei
Mexico
Norway
Portugal
Spain
Sweden
Switzerland
USA
I think you are looking for the Google Distance Matrix API. It returns not routes, but duration and distance for each pair of origin and destination. It has a usage limit of 100 elements per 10 seconds.
So you can make an educated guess about the distance that matches the desired time of travel, choose six or eight equally distributed points on a circle of that radius, and query the corresponding durations. Then refine the distances according to the results and calculate intermediary points. This way you can get a (quite rough) map in a few iterations.
I don't think there is a simple way of doing this, but here's an idea:
You'd need to first get the long/lat coordinates of your start position. You will then need to work out say, 50 coordinates around that start position that are say, 1 kilometer away from it (the answer here can help). You'd then need to traverse around each of these points and ask for the driving time to get there from your start position using Google Driving Directions API.
You'd then need to traverse the points again to find the points that are below the time of travel allowed (e.g. 30 mins in your question), move these points another kilometer or so away (in the same direction that the point originally moved from the start position) and repeat the driving time request until all are above the time of travel allowed. Finally you end up with 50 coordinates which you can plot onto a Google Maps image as a polygon using the Google Javascript API for mapping polygons.
This method requires a lot of requests to Google so you'll need to think about Google's limit on the number of requests you can do a day.
You can use the GraphHopper Directions API - this API part is also open source.
As we've added public transit and this feature recently it currently does not work together. But this is planned and until then you can enjoy road network isochrones :)
Disclaimer: I'm one of the GraphHopper founders.
You can draw a circle around your current position and check for a road at an angle every X degrees.
Another idea is to use a contour plot and isolines.

GeoDjango distance search

I want to use GeoDjango to do basic location searches. Specifically I want to give the search function a ZIP code/city/county and find all the ZIP codes/cities/counties within 5mi, 10mi, 20mi, etc. I found the following paragraph in the documentation:
Using a geographic coordinate system may introduce complications for the developer later on. For example, PostGIS does not have the capability to perform distance calculations between non-point geometries using geographic coordinate systems, e.g., constructing a query to find all points within 5 miles of a county boundary stored as WGS84. [6]
What does this exactly mean if I want to use PostGIS and to be able to do the searches described above across the USA? The docs suggest using a projected coordinate system to cover only a specific region. I need to cover the whole country so this I suppose is not an option.
Basically in the end I want to be able to find neighbouring ZIP codes/cities/counties given a starting location and distance. I don't really care how this is done on a technical level.
Also where would I find a database that contains the geographic boundaries of ZIP codes/cities/counties in the USA that I can import into a GeoDjango model?
UPDATE
I found a database of that contains the latitude and longitude coordinates of all ZIP codes in the USA here. My plan is to import these points into a GeoDjango model and use PostGis to construct queries that can find other points within x miles from a given point. This gets around the issue raised in the documentation because all the ZIP codes are treated as points instead of as polygons. This is fine for my use case because perfect accuracy is not something I care about.
The good: the data file is free
The bad: this data is from the 2000 census so it is quite dated
The somewhat hopeful: the United States Census Bureau conducts a census every 10 years and it is almost 2010
The conclusion: it's good enough for me
To get around the limitation in the quote, you can just take the centroid of the zipcode region provided by the user, and then from that point find all zipcode regions that intersect a 5, 10 or whatever mile circle emanating from that point. I'm not sure how that would be achieved in geodjango, but with postgis it's definitely possible.
The limitation you quoted basically says you can't write a query that says "give me all points that are within 5 miles on the inside of the border of Ohio."
In [1]: o = Place.objects.get(pk=2463583) # Oakland, CA
In [2]: sf = Place.objects.get(pk=2487956) # San Francisco, CA
In [3]: o.coords.transform(3410) # use the NSIDC EASE-Grid Global projection
In [4]: sf.coords.transform(3410) # use the NSIDC EASE-Grid Global projection
In [5]: o.coords.distance(sf.coords) # find the distance between Oakland and San Francisco (in meters)
Out[5]: 14401.942808571299

Categories