0
votes

I have a SpatialPolygonsDataFrame that I would like to use as the base map for an igraph plot. I have successfully created my igraph network and merged the locations using the centroids in the SpatialPolygonsDataFrame. I would like to transform my layout coordinates, which is in matrix format, in a way that can be plotted over my base map.

I'm using this code but not getting the correct layout.

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()

My question is, how can I state the correct projection when doing a spatial transformation?

Below is a summary of my SpatialPolygonsDataFrame. You will see that I used the text following proj4string : as my CRC argument.

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

1 Answers

0
votes

Late but for posterity one answer is to convert matrix to raster then to data.frame of points with raster::rasterToPoints()