R:将Shapefile 1中的多边形与shapefile 2中的区域代码匹配

问题描述 投票:0回答:2

我被问到R是否可以使用shapefile - 我以前从未使用过shapefile,但我确信,其他人一定会遇到这样的问题!

我有两个shapefile:a)shapefile 1(PolygonSamples.shp)包含一个分布在德国各地的多边形列表(附件是一个样本)。多边形可能小于,等于或大于一个邮政编码多边形的多边形。

b)shapefile 2列出了德国邮政编码,可以从https://blog.oraylis.de/2010/05/german-map-spatial-data-for-plz-postal-code-regions/下载

现在的问题是:如何“匹配”两个shapefile以获得一个数据框,该数据框列出shapefile 1中哪个多边形匹配shapefile 2的哪些邮政编码。结果理想地看起来像

 Polygon ID (shapefile 1)     Postal Code (shapefile 2)
         1                                80995
         2                                80997
         2                                80999
         3                                81247

我发现的任何东西都不是我的问题。例如From a shapefile with polygons/areas, and points (lat,lon), figure out which polygon/area each point belongs to? In R似乎很接近,但我无法获得所需的数据帧(或数据表)输出。

library(maps)
library(maptools)

# Polygons
tmp_dir <- "C:/Users/.../"
polygons <- readShapeSpatial(sprintf('%s/polygons.shp', tmp_dir)
plot(polygons)


# Postal codes
dir <- "C:/Users/..../"
postcode <- readShapeSpatial(sprintf('%s/post_pl.shp', dir)
plot(postcode)

丢失的代码snipplet会读取类似的内容

    result_table <- match(polygons_ID, postcode, 
                      data1= polygon, data2 = postcode, 
                      by = "coordinates in the shapefile"

shapefile(.shp)中包含多边形的示例。可以发送其他空间文件(.dbf,.prj,.qpj,.shx)。

任何帮助真的非常感谢!

PS:R版本3.2.3,64位,Windows 7上的RStudio

r maps shapefile postal-code
2个回答
0
投票

不幸的是我没有在R中找到答案,但我可以弄清楚如何在QGIS中匹配两个独立的shapefile。

主要问题:自定义shapefile在.prj文件中使用地理编码Google Mercator(EPSG = 900913),而下载的邮政编码shapefile使用EPSG 4326。

QGIS不会自动将这些.prj文件识别为投影文件。一个人必须手工设置它们。

最重要的是:Google Mercator(EPSG = 900913)更改为EPSG = 3857.因此,我必须手动设置自定义shapefile! - CRS到WGS 84 /伪墨卡托EPSG = 3857。

现在我可以右键单击自定义形状图层 - >另存为....并将CRS更改为EPSG 4326.因此,新的自定义shapefile现在具有与下载的邮政编码shapefile相同的投影,并且它们可以按位置连接。

(PS:虽然我有手动进行转换的解决方案,但我很乐意在R中执行此操作,因为我需要生成的文件进行分析。)


0
投票

退房:https://gis.stackexchange.com/questions/140504/extracting-intersection-areas-in-r?newreg=033544fa0f5349bcb8167d78867c8073

它可以为您提供数据集B中的哪些shapefile与数据集A中的shapefile重叠,以及目标shapefile中每个B的shapefile中存在多少区域。

© www.soinside.com 2019 - 2024. All rights reserved.