I have a database of records with latitude and longitude information (imagine this is a CSV file containing tweets and their geo-coordinates). I also have shapefiles of U.S. states. I want to add another column which indicates the U.S. state where a tweet was generated.

In R, this would be very simple: just use the over function in the rgdal package, which is really simple and doesn't require the use of any for loops.

However, I'm less sure about how to do this in Python. It looks easy to check whether any point lies within any U.S. state, (though you won't be able to tell which state) and one can adapt the code to loop over each U.S. states.

However, I'm wondering if there's a simple function which wouldn't require the use of a for loop? If not, would someone be willing to demonstrate a relatively easy way to do this in Python?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.