r-使用几何体值塑造文件

  • 本文关键字:文件 几何体 r ggplot2
  • 更新时间 :
  • 英文 :


我有两个不同的文件,一个与印度各州有关,其中形状文件在以下值中提到了几何图形。这些我理解为Lat长期相关。

几何

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

tibble: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:-24510.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与第一个数据中的长度对齐?

我们可以使用sf::st_transform将坐标转换为不同的投影。例如,我们的poly_1NAD27中,而pt_1在lat-long中,因此我们将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)

创建于2021-07-14由reprex包(v2.0.0(

最新更新