具有几何值的形状文件
Posted
技术标签:
【中文标题】具有几何值的形状文件【英文标题】:Shape file with geometry values 【发布时间】:2021-09-23 09:28:16 【问题描述】:我有 2 个与印度各州相关的不同文件,其中形状文件在以下值中提到了几何形状。这些我理解为 Lat long 相关。
几何
Simple feature collection with 36 features and 0 fields Geometry type: MULTIPOLYGON Dimension: XY Bounding box: xmin: 68.09348 ymin: 6.754368 xmax: 97.4115 ymax: 37.07761 Geodetic CRS: WGS 84
一个小标题:36 x 1
geometry <MULTIPOLYGON [°]>
1 (((96.08866 29.45997, 96.09428 29.45477, 96.1026 29.44361, 96.1145~
2 (((95.97166 27.96254, 95.97174 27.96227, 95.97153 27.96173, 95.971~
3 (((76.77175 30.79498, 76.77231 30.7942, 76.77285 30.79342, 76.7728~
4 (((77.32647 18.45884, 77.32648 18.45803, 77.32652 18.45755, 77.326~
5 (((94.57315 25.69156, 94.57522 25.69094, 94.57661 25.6907, 94.5786~
6 (((91.82534 26.1195, 91.8261 26.11935, 91.82721 26.11924, 91.82856~
7 (((92.7635 24.52122, 92.76374 24.52108, 92.76412 24.51977, 92.7651~
8 (((95.19346 27.03584, 95.19336 27.0356, 95.19334 27.03533, 95.1934~
9 (((75.83873 32.5127, 75.84163 32.51123, 75.84378 32.50913, 75.8452~
10 (((73.97324 30.12272, 73.97508 30.12008, 73.97512 30.12002, 73.972~
# ... with 26 more rows
但是,我在 shape 文件中有村庄级别的数据,其中的数据看起来不像 lat long
具有 1307 个特征和 0 个特征的简单特征集合 领域几何 类型:多边形尺寸:XY 边界框:xmin:-245100.1 ymin: 1548629 xmax:-135036.5 ymax:1727614 预计 CRS:WGS 84 / UTM 区域 44N 前 10 个功能:
geometry 1 POLYGON ((-222187.3 1727256... 2 POLYGON ((-216756.5
1726619... 3 POLYGON ((-222378.9 1726630... 4 POLYGON ((-210733.2 1722837... 5 POLYGON ((-219001.3 1723337... 6 POLYGON ((-221767.5 1723233... 7 POLYGON ((-210455.5 1722706... 8 POLYGON ((-223128.3 1720088... 9 POLYGON ((-206946.5 1719800... 10 POLYGON ((-222531.3 1718161...
如何在第一个数据中对齐这个 w.r.t lat long?
【问题讨论】:
【参考方案1】:我们可以使用sf::st_transform
将坐标转换为不同的投影。例如,我们的poly_1
是NAD27
,而我们的pt_1
是经纬度,所以我们将pt_1
转换为匹配:
library(sf)
poly_1 <- st_read(system.file("shape/nc.shp", package="sf"))
#> Reading layer `nc' from data source `/Library/Frameworks/R.framework/Versions/4.0/Resources/library/sf/shape/nc.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS: NAD27
crs_1 <- st_crs(poly_1)
pt_1 <- st_as_sf(data.frame(x=-78.63888473552387,y= 35.78967742040873),
coords = c('x','y'), crs=4326)
pt_1
#> Simple feature collection with 1 feature and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: -78.63888 ymin: 35.78968 xmax: -78.63888 ymax: 35.78968
#> Geodetic CRS: WGS 84
#> geometry
#> 1 POINT (-78.63888 35.78968)
# convert pt_1 to same crs as our poly_1
pt_1 <- st_transform(pt_1, crs_1)
pt_1
#> Simple feature collection with 1 feature and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: -78.63915 ymin: 35.78959 xmax: -78.63915 ymax: 35.78959
#> Geodetic CRS: NAD27
#> geometry
#> 1 POINT (-78.63915 35.78959)
由reprex package (v2.0.0) 于 2021 年 7 月 14 日创建
【讨论】:
以上是关于具有几何值的形状文件的主要内容,如果未能解决你的问题,请参考以下文章