kim1801
kim1801

Reputation: 129

Extracting point data from a large shape file in R

I'm having trouble extracting point data from a large shape file (916.2 Mb, 4618197 elements - from here: https://earthdata.nasa.gov/data/near-real-time-data/firms/active-fire-data) in R. I'm using readShapeSpatial in maptools to read in the shape file which takes a while but eventually works:

worldmap <- readShapeSpatial("shp_file_name") 

I then have a data.frame of coordinates that I want extract data for. However R is really struggling with this and either loses connection or freezes, even with just one set of coordinates!

pt <-data.frame(lat=-64,long=-13.5)
pt<-SpatialPoints(pt)
e<-over(pt,worldmap)

Could anyone advise me on a more efficient way of doing this?

Or is it the case that I need to run this script on something more powerful (currently using a mac mini with 2.3 GHz processor)?

Many thanks!

Upvotes: 1

Views: 2378

Answers (1)

Phil
Phil

Reputation: 4444

By 'point data' do you mean the longitude and latitude coordinates? If that's the case, you can obtain the data underlying the shapefile with:

worldmap@data

You can view this in the same way you would any other data frame, for example:

View(worldmap@data)

You can also access columns in this data frame in the same way you normally would, except you don't need the @data, e.g.:

worldmap$LATITUDE

Finally, it is recommended to use readOGR from the rgdal package rather than maptools::readShapeSpatial as the former reads in the CRS/projection information.

Upvotes: 1

Related Questions