- Hands-On Geospatial Analysis with R and QGIS
- Shammunul Islam
- 189字
- 2021-06-10 18:44:27
Plotting point data
Location is a point characterized by its coordinates. Point data comprises attributes of a location or data collected on a parameter from different points. Shapefile is a popular data format for vector data. In R, the sp package loads shapefile as SpatialPoints and if it contains attributes, it is saved as SpatialPointsDataFrame. We can import a shapefile into R, using the readOGR() function of the sp package. We have to provide the path to the shapefile as the first parameter for the readOGR() function and the name of the shapefile is the second parameter. Here, we have to provide the name of the shapefile without the .shp extension. So, if we want to import a shapefile containing points, we can do so by writing the following:
# SpatialPoints
library(sp)
library(rgdal)
library(maptools)
map = readOGR("F:/Hands-on-Geospatial-Analysis-Using-R-and-QGIS/Chapter 02/Data","indicator")
plot(map)
We see the following map, which just shows point data as a plus point indicating different districts in Bangladesh:

Now, let's check the class of this data map:
class(map)
The class is SpatialPointsDataFrame.