Transform a data frame into a spatial data frame to be able to get an ESRI shapefile to open in QGIS (R programming)

80 Views Asked by At

I have a data frame in R (no2df) it looks like this:

    **> head(no2df)
                  id     latb     lonb      lat      lon        no2tc
        5028741 816834 32.95808 36.61589 33.00045 36.63499 3.276456e-05
        5028742 816834 32.98067 36.67716 33.00045 36.63499 3.276456e-05
        5028743 816834 33.04274 36.65399 33.00045 36.63499 3.276456e-05
        5028744 816834 33.02014 36.59268 33.00045 36.63499 3.276456e-05
        5028745 816835 32.98067 36.67716 33.02291 36.69604 2.578415e-05
        5028746 816835 33.00300 36.73795 33.02291 36.69604 2.578415e-05**

As the above matrix suggests every four points (that have the same id) form a polygon (or in my case a pixel or cell), the bounds of the cell are shown under columns "latb" and "lonb" and the center of the cell is repeated four times under columns "lat" and "lon" because it is the same center for each cell. Finally, most importantly, I have the variable NO2 depicted under column "no2tc" it follows the same reasoning as the lat and lon.

The question is the following:

What should I do (please give the steps) to convert or manipulate this data frame into a spatial data frame so finally I am able to export to an ESRI shapefile that contains the cells with the variable "no2tc" as the cell attribute, so I can view in QGIS?

0

There are 0 best solutions below