根据R中的投影将矩阵转换为点

时间:2018-07-11 13:59:30

标签: r geospatial point projection

我有一个SpatialPolygonsDataFrame,我想用作igraph图的底图。我已经成功创建了igraph网络,并在centroids中使用SpatialPolygonsDataFrame合并了位置。我想以matrix格式转换布局坐标,以便可以在我的基础地图上绘制它。

我正在使用此代码,但布局不正确。

long_lat <- SpatialPoints(g_locations, proj4string=CRS("tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +datum=OSGB36 +units=m +no_defs +ellps=airy+towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894"))

transformed_locations <- spTransform(long_lat, CRS('+proj=tmerc')) %>% 
    as.data.frame() %>% 
    as.matrix()

我的问题是,在进行空间变换时如何陈述正确的投影?

以下是我的SpatialPolygonsDataFrame的摘要。您会看到我使用proj4string :之后的文本作为我的CRC参数。

  

local_authority_shp%>%summary()

Object of class SpatialPolygonsDataFrame
Coordinates:
       min       max
x 5512.999  655644.8
y 5337.901 1220301.5
Is projected: TRUE 
proj4string :
[+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000
+y_0=-100000 +datum=OSGB36 +units=m +no_defs +ellps=airy
+towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894]
Data attributes:
    objectid        lad17cd             lad17nm             lad17nmw  
 1      :  1   E06000001:  1   Aberdeen City:  1   Abertawe     :  1  
 10     :  1   E06000002:  1   Aberdeenshire:  1   Blaenau Gwent:  1  
 100    :  1   E06000003:  1   Adur         :  1   Bro Morgannwg:  1  
 101    :  1   E06000004:  1   Allerdale    :  1   Caerdydd     :  1  
 102    :  1   E06000005:  1   Amber Valley :  1   Caerffili    :  1  
 103    :  1   E06000006:  1   Angus        :  1   (Other)      : 17  
 (Other):374   (Other)  :374   (Other)      :374   NA's         :358  
     bng_e         bng_n          long              lat       
 126473 :  1   268437 :  2   Min.   :-6.6572   Min.   :49.92  
 199821 :  1   1006584:  1   1st Qu.:-2.5644   1st Qu.:51.46  
 200740 :  1   101094 :  1   Median :-1.3868   Median :52.23  
 212501 :  1   101357 :  1   Mean   :-1.4918   Mean   :52.61  
 226544 :  1   104948 :  1   3rd Qu.:-0.2817   3rd Qu.:53.41  
 227922 :  1   105685 :  1   Max.   : 1.6495   Max.   :60.50  
 (Other):374   (Other):373                                    
   st_areasha          st_lengths      local_authority_shp_centroids
 Min.   :2.904e+06   Min.   :   9250   Length:380                   
 1st Qu.:8.626e+07   1st Qu.:  63953   Class :SpatialPoints         
 Median :2.644e+08   Median : 115284   Mode  :S4                    
 Mean   :6.054e+08   Mean   : 193451                                
 3rd Qu.:6.098e+08   3rd Qu.: 197695                                
 Max.   :2.616e+10   Max.   :5261282  

1 个答案:

答案 0 :(得分:0)

但后代的一个答案是将矩阵转换为栅格,然后使用raster::rasterToPoints()转换为点的data.frame