更改人口普查数据的坐标参考系统 (CRS)
Changing the Coordinate Reference System (CRS) on Census Tract Data
如何更改人口普查数据的坐标参考系统 (CRS) 以匹配 UCLA 国会选区 Shapefile 的坐标参考系统 (CRS)?
我正在使用 sf
包和名为 Census_70.1
的人口普查数据。数据如下所示:
Simple feature collection with 73669 features and 15 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -7115208 ymin: -1685018 xmax: 3321632 ymax: 4591848
epsg (SRID): NA
proj4string: +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs
geometry
1 MULTIPOLYGON (((777980.6 -6...
2 MULTIPOLYGON (((797299.6 -6...
3 MULTIPOLYGON (((781590.6 -7...
4 MULTIPOLYGON (((788040.7 -7...
5 MULTIPOLYGON (((782468.1 -7...
6 MULTIPOLYGON (((783828.9 -7...
7 MULTIPOLYGON (((776624.7 -7...
8 MULTIPOLYGON (((775274.6 -7...
9 MULTIPOLYGON (((791123.2 -7...
10 MULTIPOLYGON (((797096.8 -7...
我需要更改 CRS 以匹配以下国会选区 shapefile:
Simple feature collection with 436 features and 19 fields (with 1 geometry empty)
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -179.1473 ymin: 18.91383 xmax: 179.7785 ymax: 71.35256
epsg (SRID): 4269
proj4string: +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs
我尝试使用以下代码重新设置 CRS:
Census_70.2 <- st_transform(st_set_crs(Census_70.1, "+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs"), crs = 4269, check = T)
但是,虽然 proj4string
在 Census_70.2
上发生了变化,但几何形状保持不变。
Simple feature collection with 34492 features and 9 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -7115713 ymin: -1295867 xmax: 2146924 ymax: 3476641
epsg (SRID): NA
proj4string: +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs
geometry
1 MULTIPOLYGON (((777980.6 -6...
2 MULTIPOLYGON (((797299.6 -6...
3 MULTIPOLYGON (((781590.6 -7...
4 MULTIPOLYGON (((788040.7 -7...
5 MULTIPOLYGON (((782468.1 -7...
6 MULTIPOLYGON (((783828.9 -7...
7 MULTIPOLYGON (((776624.7 -7...
8 MULTIPOLYGON (((775274.6 -7...
9 MULTIPOLYGON (((791123.2 -7...
10 MULTIPOLYGON (((797096.8 -7...
此外,通过 运行 转换代码,它扭曲了地图的原始格式 Census_70.1
对于Census_70.2
中的这种扭曲
我做错了什么?
据我了解
library(raster) #it will load also the sp library
destinationcrs <- "+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs"
Census_70.2 <- spTransform(Census_70.1,destinationcrs)
target_crs <- st_crs(congressional_district_data)
census_70.2 <- st_transform(census_70.1, target_crs)
我认为应该这样做,但您可以查看 Robin Lovelace 的这个不错的 site/book“使用 R 进行地理计算”,如果没有,或者只是为了更好地处理它。
我认为你有一个额外的 st_set_crs
你并不需要。据我了解,函数设置了对象字段 CRS(st_crs()
返回的内容,但实际上并没有重新投影任何内容。
https://geocompr.robinlovelace.net/reproj-geo-data.html#reproj-vec-geom
如何更改人口普查数据的坐标参考系统 (CRS) 以匹配 UCLA 国会选区 Shapefile 的坐标参考系统 (CRS)?
我正在使用 sf
包和名为 Census_70.1
的人口普查数据。数据如下所示:
Simple feature collection with 73669 features and 15 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -7115208 ymin: -1685018 xmax: 3321632 ymax: 4591848
epsg (SRID): NA
proj4string: +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs
geometry
1 MULTIPOLYGON (((777980.6 -6...
2 MULTIPOLYGON (((797299.6 -6...
3 MULTIPOLYGON (((781590.6 -7...
4 MULTIPOLYGON (((788040.7 -7...
5 MULTIPOLYGON (((782468.1 -7...
6 MULTIPOLYGON (((783828.9 -7...
7 MULTIPOLYGON (((776624.7 -7...
8 MULTIPOLYGON (((775274.6 -7...
9 MULTIPOLYGON (((791123.2 -7...
10 MULTIPOLYGON (((797096.8 -7...
我需要更改 CRS 以匹配以下国会选区 shapefile:
Simple feature collection with 436 features and 19 fields (with 1 geometry empty)
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -179.1473 ymin: 18.91383 xmax: 179.7785 ymax: 71.35256
epsg (SRID): 4269
proj4string: +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs
我尝试使用以下代码重新设置 CRS:
Census_70.2 <- st_transform(st_set_crs(Census_70.1, "+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs"), crs = 4269, check = T)
但是,虽然 proj4string
在 Census_70.2
上发生了变化,但几何形状保持不变。
Simple feature collection with 34492 features and 9 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -7115713 ymin: -1295867 xmax: 2146924 ymax: 3476641
epsg (SRID): NA
proj4string: +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs
geometry
1 MULTIPOLYGON (((777980.6 -6...
2 MULTIPOLYGON (((797299.6 -6...
3 MULTIPOLYGON (((781590.6 -7...
4 MULTIPOLYGON (((788040.7 -7...
5 MULTIPOLYGON (((782468.1 -7...
6 MULTIPOLYGON (((783828.9 -7...
7 MULTIPOLYGON (((776624.7 -7...
8 MULTIPOLYGON (((775274.6 -7...
9 MULTIPOLYGON (((791123.2 -7...
10 MULTIPOLYGON (((797096.8 -7...
此外,通过 运行 转换代码,它扭曲了地图的原始格式 Census_70.1
对于Census_70.2
中的这种扭曲
我做错了什么?
据我了解
library(raster) #it will load also the sp library
destinationcrs <- "+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs"
Census_70.2 <- spTransform(Census_70.1,destinationcrs)
target_crs <- st_crs(congressional_district_data)
census_70.2 <- st_transform(census_70.1, target_crs)
我认为应该这样做,但您可以查看 Robin Lovelace 的这个不错的 site/book“使用 R 进行地理计算”,如果没有,或者只是为了更好地处理它。
我认为你有一个额外的 st_set_crs
你并不需要。据我了解,函数设置了对象字段 CRS(st_crs()
返回的内容,但实际上并没有重新投影任何内容。
https://geocompr.robinlovelace.net/reproj-geo-data.html#reproj-vec-geom