I have tweets with coordinates. I'm trying to bucket the tweets by country using the coordinate information. I know that I can achieve this using some hosted web services but all of these have API limits that I am sure to run into.
I started writing this code learning from another resource about osgeo library.
import osgeo.ogr shapefile = osgeo.ogr.Open("geodata/worldborders/TM_WORLD_BORDERS-0.3.shp") layer = shapefile.GetLayer(0) for i in range(layer.GetFeatureCount()): feature = layer.GetFeature(i) countryCode = feature.GetField("ISO3") countryName = feature.GetField("NAME") print countryCode, countryName geometry = feature.GetGeometryRef()
The geometry variable has a member function called Contains that can take another Geometry and checks whether the other is contained inside itself.
I have a coordinate value from Twitter data in the following format: [45.29680725, -75.92681408]. However an example on osgeo showcases creation of a point like this:
point = osgeo.ogr.Geometry(osgeo.ogr.wkbPoint) point.SetPoint(0, 474595, 4429281)
How do I convert my coordinates into the above required format? If I do manage to convert, is this the right approach of mapping twitter coordinates to countries?