Search code examples
rcoordinatesgislatitude-longitudeprojection

Changing WGS84 to EPSG:5330 in R


I would like to change my coordinate form WGS84 to EPSG:5330. Hope, anyone can help me thanks

ID,X,Y   
1,106.6874498,-6.2107887   
2,106.6883199,-6.2069667

Solution

  • Easy-cheesy with the sp library.

    library(sp)
    # Create SpatialPoints out of coordinates. 
    # Assign WGS84 (EPSG 4326) coordinate reference system.
    pts <- SpatialPoints(coords = data.frame(x = c(106.6874498, 106.6883199), 
                                             y = c(-6.2107887, -6.2069667)),
                         proj4string = CRS("+init=epsg:4326")) 
    
    # Transform SpatialPoints to EPSG 5330.    
    pts_epsg5330 <- spTransform(x = pts, CRSobj = CRS("+init=epsg:5330"))
    

    Result:

    # Get coordinates of new SpatialPoints.
    > coordinates(pts_epsg5330)
    
               x        y
    [1,] 3532231 213991.4
    [2,] 3532328 214415.3