0

I got a shapefile from the The Italian National Institute of Statistics (CAMERA_PLURI_2017.shp within this zipfile here: https://www.istat.it/storage/COLLEGI_ELETTORALI_2017.zip)

I try to read the shp file itself. A number of maps appear be be nested in the shape object as 'variables'. How do I access each individually?

require(sf)
italia <- read_sf("CAMERA_PLURI_2017.shp")
plot(italia)

Thanks a lot

Jindra Lacko
  • 7,814
  • 3
  • 22
  • 44
MCS
  • 1,071
  • 9
  • 23
  • Look into GDAL & OGR. They are open source and allow you to work with/query shapefiles easily – Christian4423 Aug 30 '19 at 13:48
  • There is usually a wrapper for most languages to include GDAL. Python especially. But I’ve also used C# & nodeJS to call a bat file with a gdal command and get the response from that – Christian4423 Aug 30 '19 at 13:50

1 Answers1

0

As you seem to be using the R package {sf} there is no need to call GDAL & OGR directly; it is handled by the sf package behind the scenes.

What you do need is use standard R tools to select a variable (sf package uses a modified data.frame format, which is pretty standard in R).

There are a number of possibilities - either the $ notation, or the [ notation, but I suggest {tidyverse} approach, such as the following piece of code:

library(sf)
library(dplyr)

italia <- read_sf("CAMERA_PLURI_2017.shp")

popolazione <- italia %>% 
   select(POP_2011)

plot(popolazione)

enter image description here

Jindra Lacko
  • 7,814
  • 3
  • 22
  • 44