top of page

GIS y R Parte 1: Lectura de ESRI Shapefile (SHP) en R

En este conjunto de entradas vamos a cubrir lo básico al momento de leer y manipular archivos del tipo ESRI shapefile en R. R tiene algunas librerías muy útiles para trabajar con datos espaciales. En esta entrada utilizaremos la librería denominada rgdal. La documentación de la librería la puedes encontrar en el siguiente link.

En esta Parte 1 empezaremos leyendo los archivos shapefile a R .

 

# carga de paquetes a usar library(rgdal)

StartFragment# dsn es un objeto que apunta a la carpeta que contiene los archivos shapefile a cargar

> dsn <- setwd("./home/Database/shapefiles")

# ogrListLayers devuelve una lista de los shapefile ubicados en dsn (2)

> ogrListLayers(dsn)

[1] "GEO_SEC2014" "GEO_SECDIS2014"

[1] "ESRI Shapefile"

attr(,"nlayers") [1] 2

 

### sectores censales amanzanados

# ogrInfo devuelve la información general del shapefile GEO_SEC2014

> ogrInfo(dsn=dsn,layer="GEO_SEC2014")

Source:"./home/Database/shapefiles", layer: "GEO_SEC2014"

Driver: ESRI Shapefile; number of rows: 24740

Feature type: wkbPolygon with 2 dimensions

Extent: (-621618 9452554) - (1124813 10160169)

CRS: +proj=utm +zone=17 +south +datum=WGS84 +units=m +no_defs

LDID: 89

Number of fields: 9

name type length typeName

1 DPA_SECTOR 4 20 String

2 DPA_VALOR 0 4 Integer

3 DPA_ANIO 4 4 String

4 DPA_ZONA 4 9 String

5 FUENTE 4 25 String

6 Shape_Leng 2 19 Real

7 Shape_Le_1 2 19 Real

8 Shape_Area 2 19 Real

9 CIUDAD 4 6 String

# OGRSpatialRef devuelve la proyección del shapefile GEO_SEC2014

> OGRSpatialRef(dsn=dsn,layer="GEO_SEC2014")

[1] "+proj=utm +zone=17 +south +datum=WGS84 +units=m +no_defs "

# leemos el shapefile GEO_SEC2014 y lo asignamos al objeto aman

> aman <- readOGR(dsn=dsn,layer="GEO_SEC2014")

OGR data source with driver: ESRI Shapefile

Source: "./home/Database/shapefiles", layer: "GEO_SEC2014"

with 24740 features

It has 9 fields

 

El paquete rgdal integra varias funciones que nos permiten visualizar diferentes características de los shapefiles de interés sin necesidad de cargarlos a R o explorarlos utilizando un software GIS convencional, permitiendonos optimizar nuestro flujo de trabajo.


Ahora, repetimos el proceso para el shapefile "GEO_SECDIS2014" y lo asignamos al objeto dis.

 

### sectores censales dispersos

# ogrInfo devuelve la información general del shapefile GEO_SECDIS2014

> ogrInfo(dsn=dsn,layer="GEO_SECDIS2014")

Source:"./home/Database/shapefiles", layer: "GEO_SECDIS2014"

Driver: ESRI Shapefile; number of rows: 15941

Feature type: wkbPolygon with 2 dimensions

Extent: (-685716.9 9445263) - (1146853 10161184)

CRS: +proj=utm +zone=17 +south +datum=WGS84 +units=m +no_defs

LDID: 89

Number of fields: 10

name type length typeName

StartFragment

1 DPA_SECDIS 4 50 String

2 DPA_VALOR 2 19 Real

3 DPA_ANIO 4 4 String

4 DPA_ZONDIS 4 50 String

5 EMPATE 4 10 String

6 DPA_PARROQ 4 20 String

7 FUENTE 4 25 String

8 Shape_Leng 2 19 Real

9 Shape_Le_1 2 19 Real

10 Shape_Area 2 19 Real

# OGRSpatialRef devuelve la proyección del shapefile GEO_SEC2014

> OGRSpatialRef(dsn=dsn,layer="GEO_SECDIS2014")

[1] "+proj=utm +zone=17 +south +datum=WGS84 +units=m +no_defs "

# leemos el shapefile GEO_SEC2014 y lo asignamos al objeto aman

> dis <- readOGR(dsn=dsn,layer="GEO_SECDIS2014")

OGR data source with driver: ESRI Shapefile

Source: "./home/Database/shapefiles", layer: "GEO_SECDIS2014"

with 15941 features

It has 10 fields

 

Terminaremos esta entrada graficando los dos archivos shapefiles cargados. Para esto utilizamos la función plot.

 

> plot(aman)

> plot(dis)

Etiquetas:

Posts Destacados
Posts Recientes
Búsqueda por Tags
Conéctate
  • Google+ Long Shadow
  • Facebook Long Shadow
  • LinkedIn Long Shadow
  • Twitter Long Shadow

Contáctame 

Telf.: (+593) 9956 - 90532

  • Google+ Long Shadow
  • Facebook Long Shadow
  • LinkedIn Long Shadow
  • Twitter Long Shadow

© 2016 por Javier Núñez. Creado con Wix.com

¡Tus datos se enviaron con éxito!

bottom of page