如何对 shapefile 进行子集化 [英] How to subset a shapefile

查看:37
本文介绍了如何对 shapefile 进行子集化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

shapefileProperty1A"的数据集为:

The data set of shapefile "Property1A" is:

 df
#      suburb        area asst
# 0     Te Aro   14.541780 R076
# 1     Te Aro    7.655428 R076
# 2     Te Aro 3189.976134 <NA>
# 3     Te Aro  242.173386 0132
# 4     Karori  537.697290 R003
# 5    Pipitea 1116.954993 R105
# 6    Mt Cook  106.099900 R151
# 7     Te Aro   83.307421 R057
# 8 Aro Valley  544.665788 R105
# 9 Aro Valley   59.726882 R110

当我尝试对郊区Te Aro"的 shapefile 进行子集化时,我使用的代码是:

When I try to subset the shapefile for suburb "Te Aro", the code I use is:

TeAro <- subset(Property1A, suburb == "Te Aro") 

但是有一个错误:

TeAro <- subset(Property1A, suburb == "Te Aro")
# Error in eval(expr, envir, enclos) : object 'suburb' not found

为什么会出现错误?

推荐答案

subset 与名称应该工作.如果您使用 readOGR 读入,则不需要 shapefiles 包:

subset with names should work. You don't need the shapefiles package if you are reading in with readOGR:

> require(rgdal)
Loading required package: rgdal
Loading required package: sp
rgdal: version: 0.8-14, (SVN revision 496)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.9.0, released 2011/12/29
Path to GDAL shared files: /usr/share/gdal/1.9
Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 470]
Path to PROJ.4 shared files: (autodetected)

将印度各州的 169 个多边形变成一个空间对象:

Get the 169 polygons of Indian states into a spatial object:

> India = readOGR(".","india_state")
OGR data source with driver: ESRI Shapefile 
Source: ".", layer: "india_state"
with 169 features and 3 fields
Feature type: wkbPolygon with 2 dimensions

现在按名称子集:

> Gujarat = subset(India, NAME=="Gujarat")
> dim(Gujarat)
[1] 12  3
> dim(India)
[1] 169   3

我可以绘制这些对象,它们映射得很好:

I can plot these objects, they map nicely:

> plot(Gujarat)

如果没有您的数据或不知道 R 的版本和您拥有的软件包,就无法知道为什么这会失败.

Without your data or knowing what version of R and the packages you have, there is no way of knowing why this fails for you.

包:rgdal版本:0.8-14

Package: rgdal Version: 0.8-14

包装:sp版本:1.0-14

Package: sp Version: 1.0-14

R 版本 3.0.2....

R version 3.0.2....

这篇关于如何对 shapefile 进行子集化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆