Geolocation of a tweet - python

I am using Tweepy (python) to access to Twitter Search API, and I am looking to extract the geo-coordinates of the tweet.
As you can see in the screenshot, I found geo and coordinates, and they are inverted.
I would like to know if I am in the good track first, then how can I distinguish between Latitude & Longitude ?

If it's not in Antarctica, the -80.xxxx is longitude. For longitude, the US is like ~79-80ish to ~120 something (I'm approximating). It seems like the first value in 'coordinates':{} is longitude, whereas the first value in 'geo':{} is latitude.

"coordinates" is the official field for this info while the "geo" field is deprecated. So ignore the geo field. For further details see this discussion http://bit.ly/1sM62oH

You would need four data points for a bounding box that can be found from OpenStreetMap. For example the coordinates for Madison is as follows:
twitterStream.filter(locations=[-89.566389,42.998071,-89.246452,43.171916]) #Madison, WI

Related

OSMNX geocoder returning incorrect coordinates

When using the osmnx geocoder module, it seems that the wrong Latitude and Longitude is returned. I have cross checked the coordinates returned with multiple websites and it is not correct. This is the only relevant code being used:
addressList[0] = "7720 N Silverbell Rd, Tucson, Arizona 85743"
address = ox.geocode(addressList[0])
print(address)
Which returns: (32.301701, -111.0487101), however when searching on latlong.net, the correct coordinates for this address are (32.347720, -111.096870).
Is there anyway to ensure osmnx returns the correct coordinates?
Is there anyway to ensure osmnx returns the correct coordinates?
OSMnx returns whatever the OpenStreetMap Nominatim geocoder resolves your query to. You can try to tweak your query or play around with the Nominatim geocoder on the web to see what different queries resolve to.
so the answer to your question might be because you are not projecting your Network. Take a look at this similar question I posted which was answered by the creator of the library: Node found is too far from my lat, lon coordinates (osmnx)

Python netCDF5 working with Longitude and Latitude and extracting Data

how are you doing?
I have been working on this for quite a while now, but I am not able to proceed any further.
I was given .nc Files with Cloud Based Altitudes (CBA are measurements to indicate the height of clods for a particular area).
For now I am not even able to extract Data for a single Coordinate. This Data contains the area shown in this picture, from the top left to the bottom right:
Here is a screenshot of the data I am working with:
Sorry that I can not provide more Data than that, but I don't want to get in trouble.
The cba value is the information I want to extract. So let's say I have a set of coordinates (longitude/latitude) of an area I am interested in, how would I be able to get the appropriate cba values?
I don't need a specific solution, but a direction so I can continue on my own.
For additional information this is how the .cba and .cba.values look:
I have been working with data like that before, but not this nested, so I have absolutely no idea how I can even approach that.
Is there a module/package in python which would allow me to easily handle this, so when I put in coordinates for an area it would directly give me the corresponding cba-values?
I hope that is enough information to go on and you can help me, I would really appreciate it.
Regards
The package you are using (xarray) is already perfectly suited for this task.
dObj is an xarray.Dataset object, each contained variable (such as dObj['cba']) is an xarray.DataArray object.
You can access the data at a given set of coordinates like this:
lat = ...
lon = ...
dObj['cbd'].sel(y=lat, x=lon, method='nearest')
method='nearest' is needed as your coordinate array is unlikely to contain the requested floating point values exactly.
If you instead want to select a range of latitudes and longitudes you can do that as follows:
lat_min, lat_max = (...)
lon_min, lon_max = (...)
dObj['cbd'].sel(y=slice(lat_min, lat_max), x=slice(lon_min, lon_max))
For more information about dealing with xarray objects, have a look at the very comprehensive documentation: http://xarray.pydata.org/en/stable/index.html

Standard GPS Coordinates to lat/long/zoom used by MapBox

I'm brand new to MapBox, but like the images it produces, and want to be able to use their API to render some GPS points nicely.
Given a Standard GPS point (and a MapBox zoom level), how can I find the Lon/Lat values for a suitable MapBox 'tile' ?
The actual code that I'm trying to use is the Python code at:
https://github.com/mapbox/mapbox-sdk-py/blob/master/docs/static.md#static-maps
And my starting GPS point is in Auckland New Zealand -36.8,174.7.
https://www.google.co.nz/maps/place/36°48'00.0"S+174°42'00.0"E/
I have naively tried entering "standard" GPS coordinates:
from mapbox import Static
service = Static()
response = service.image('mapbox.satellite', lon=-36.8, lat=174.7, z=10)
but this results in the error message:
mapbox.errors.InvalidCoordError: Latitude must be between -85.0511 and 85.0511
Searching for this error message led me to this:
https://en.wikipedia.org/wiki/Tiled_web_map
But I still have no idea how to determine the long/lat values of a suitable tile. Any help would be appreciated.
Thanks in Advance
Patrick
The error message indeed right: mapbox.errors.InvalidCoordError: Latitude must be between -85.0511 and 85.0511
You got your coordinates reversed. The following coordinates -36.8, 174.7 stand for Latitude and Longitude, and not the other way around. So your code should be: service.image('mapbox.satellite', lon=174.7 lat=-36.8, z=10)
This can be seen from your Google Maps link: https://www.google.co.nz/maps/place/36°48'00.0"S+174°42'00.0"E/. Latitude guides you from South (negative) to North (positive). Longitude guides you from East (positive) to West (negative). Pay attention the Google link says: 36°48'00.0"S +174°42'00.0"E`. More information available here https://en.wikipedia.org/wiki/Geographic_coordinate_system
Searching for this error message led me to this:
https://en.wikipedia.org/wiki/Tiled_web_map
But I still have no idea how to determine the long/lat values of a
suitable tile. Any help would be appreciated.
Thanks in Advance
You don't need to. Mapbox's API abstracts that away for you.
Take a look here: https://www.mapbox.com/api-documentation/#retrieve-a-static-map-from-a-style

Use Tweepy to gather Tweets with hashtags from Egypt

I am using Tweepy and Python to gather tweets from Egypt.
The tweets must contain hashtags.
I am using these co-ordinates for Egypt:
25.13671875, 22.0245456012, 35.3759765625, 31.3723991049
The code is not a problem, but I am finding that I am only getting one or two tweets every few seconds, yet when I change the location to UK I get loaddsssss.
Anyone know whats going on please? Are my coordinates wrong?
Some people may say RTFM... :-)
because according to the last tweepy documentation:
The parameter value is specified by “latitude,longitude,radius”
But in your example you set twice a GPS coordinates ...
So it explain the result you got, because in my opinion tweeter API understand your request like :
"I would search all tweets, in a radius of 35.37mil (by default) near: 25.13671875, 22.0245456012"
So you may swich your coordinate request to :
25.13671875,22.0245456012,1000mil #mil or km as you prefer
then It will be OK !
*To explain the diff.: latitude of England is around 50.85300: so the same request applied to England coord give you all tweets in a radius of 51mil near the central point you choose...
Best regards

Google geocoding: points of interest within a specified radius

After searching around it appears that many people already have the lat/long data of the geographic points of interest they are interested in reverse-geocoding.
In my scenario I know a starting location and would like to find all points of interest (mainly residences within a neighborhood) that lie within a specific radius (say, 1 mile).
The first step is simply specifying a starting point and a radius to search within but I can't seem to figure out how to do this using the the Google Geocoding API (I'm not tied to Google... just figured I'd start there).
I am currently working in python (geopy and pygeocoder) but will eventually port it to iOS.
Any pointers would be much appreciated.
I think you may be going down the wrong path with the Google Geocoding API. What you probably want to use is Google Places API.
One (simplified) way to think about is geocoding takes in a point and returns a point. What it sounds like you want to do is pass in an area, defined by a central point and a radius, and receive a collection of points contained within that area. It looks like the Google Places API can help you with that.
Have you considered using OpenStreetMap for your task? With the help of the Overpass API you can query for all data within a given bounding box. For example this query returns all data within the current view. It uses the overpass turbo for visualization and the Overpass API only in the background but of course you can also use the Overpass API directly for returning raw data as XML or JSON.
You can even specify which exact data categories to return, for example all shops selling clothes. Take a look at commonly used tags and the Overpass API language guide for more information.
In case you haven't already, check out Radar Search & Nearby Search
https://developers.google.com/places/documentation/search#RadarSearchRequests

Categories