Posts

Showing posts from April, 2018

Spatial join is very useful: project coordinate onto geological grid

Image
Projecting data onto geological grid using spatial join in R We have lots of observations and their coordinate (lat, long), and I want to group these observations by a manually designed grid. In the beginning, I wrote a for loop which is super slow (about  5 hours for 3.5 million observations). Then I was reminded that there is something called spatial join. In Python, it is done by  gpd.sjoin() .  as Xinyue told me. In R we can use over() from sp , which is a package that provides classes and methods for spatial data: points, lines, polygons, and grids. Spatial join toke fewer than  2 minutes . The  over()   function is not very easy to use, I found out one way to get it work by turning grid into Spatial Polygon object first. There are different approaches to do this.  The main dataset of our observations has recorded millions of trips: the longitudes and latitudes of the trip origin, and the counts of people on those trips by social eco...