# Projection CRS problem

i would like to convert gauge station data using the following code.
setwd("D:\Time Series\chirps\station data and precipitation data")

names(ValparaisoPPgis)[1]<-c("Code")
str(ValparaisoPPgis)

stations <- ValparaisoPPgis
( stations <- st_as_sf(stations, coords = c('lon', 'lat'), crs = 32642) )
stations.utm <- sf::st_transform(stations, crs=32642)
st.coords <- st_coordinates(stations.utm)
lon <- st.coords[, "X"]
lat <- st.coords[, "Y"]
ValparaisoPPgis <- data.frame(Id=stations.utm[["Code"]], lon=lon, lat=lat)

and when i want to give a projection for ValparaisoPPgis i am getting NA as crs.
my question is how to project ValparaisoPPgis ?

Regards

You are building ValparaisoPPgis as a regular data.frame, not a spatial data frame. So of course it does not have crs defined.

``````ValparaisoPPgis <- read.csv(file="kunduz_ST4 - Copy.csv",header=TRUE, stringsAsFactors = FALSE) # a normal data.frame
names(ValparaisoPPgis)[1] <- c("Code") # rename the first column
str(ValparaisoPPgis)

stations <- ValparaisoPPgis # make a copy
( stations <- st_as_sf(stations, coords = c('lon', 'lat'), crs = 32642) ) # convert it to a simple features (sf) spatial data frame with crs 32642
stations.utm <- sf::st_transform(stations, crs=32642) # do nothing I think
st.coords <- st_coordinates(stations.utm) # extract the coordinates
lon <- st.coords[, "X"] # extract the X coordinate
lat <- st.coords[, "Y"] # extract the Y coordinate
ValparaisoPPgis <- data.frame(Id = stations.utm[["Code"]], lon=lon, lat=lat) # put the first column and the coordinate values into a normal data frame``````

respected sir,

to be honest i did not understand what you wrote here as a reply. if it is possible i would like to send my csv file for you to have a look and see how should i proceed.
Regards

there is no need to send the whole csv-file. Just enclose the first data line of the csv file in the form of a `data.frame` so that we see what is wrong (if anything) with your code and how the code of @woodward has to be adapted for your special case.

See providing a minimal REPRoducible EXample (reprex) for a full discussion of providing data in such a case but here a good start could be just to define

``````ValparaisoPPgis <- data.frame(my_x= ...,my_y= ...,my_attr1 = ...)
``````

where you replace `my_x` and `my_y` with the name of your longitude and latitude variables.

Let us know.

sir,

i would like to run
names(ValparaisoPPgis)[1]<-c("Code")
stations <- ValparaisoPPgis
( stations <- st_as_sf(stations, coords = c('lon', 'lat'), crs = 32642) )
ValparaisoSHP.utm <- sf::st_transform(ValparaisoSHP, crs=32642)
st.coords <- st_coordinates(stations.utm)
lon <- st.coords[, "X"]
lat <- st.coords[, "Y"]
ValparaisoPPgis.utm <- data.frame(ID=stations.utm[["Code"]], lon=lon, lat=lat)

but after runing all these i am getting CRS=NA.
i would like that this csv file should have utm zone 42 projection.

Regards

I think you have WGS84 coordinates in your csv-file (?)

``````library(sf)
ValparaisoPPgis = data.frame(
id = c('K101119','K101112'),
lon = c(68.8634,68.6721),
lat = c(36.3609,36.1088),
stringsAsFactors = F
)
stations = ValparaisoPPgis
(stations <- st_as_sf(stations, coords = c('lon', 'lat'), crs = 4326)) # WGS 84
stations.utm =sf::st_transform(stations, crs=32642) # UTM42N

st.coords <- st_coordinates(stations.utm)
lon <- st.coords[, "X"]
lat <- st.coords[, "Y"]
ValparaisoPPgis.utm <- ValparaisoPPgis
ValparaisoPPgis.utm[,'lon']=lon
ValparaisoPPgis.utm[,'lat']=lat
``````

[quote="HanOostdijk, post:6, topic:83384"]

``````library(sf)
ValparaisoPPgis = data.frame(
id = c('K101119','K101112'),
lon = c(68.8634,68.6721),
lat = c(36.3609,36.1088),
stringsAsFactors = F
)
stations = ValparaisoPPgis
(stations <- st_as_sf(stations, coords = c('lon', 'lat'), crs = 4326)) # WGS 84
stations.utm =sf::st_transform(stations, crs=32642) # UTM42N

st.coords <- st_coordinates(stations.utm)
lon <- st.coords[, "X"]
lat <- st.coords[, "Y"]
ValparaisoPPgis.utm <- ValparaisoPPgis
ValparaisoPPgis.utm[,'lon']=lon
ValparaisoPPgis.utm[,'lat']=lat
``````

Sir,
still its not accepting the projection see the attached picture of my data.

sir,
i inserted all the station lat and long still no projection. attached is showing that still the projection is NA

check out that `stations.utm` has indeed the required CRS by entering

``````sf::st_crs(stations.utm)
``````

(I have only loaded the `sf` package and have no `crs` function available)

But as @woodward already remarked, the `ValparaisoPPgis` variable is an ordinary data.frame and has no spatial attributes. You can download this data.frame to a new csv-file and load in ARCGIS or QGIS knowing that the coordinates are now in UTM42N.
Or do you have another purpose for this data.frame ?

Sir,
As you can see, in this csv the points X and Y or lat and lon is already stored. the whole purpose which i have is how to assign a projected utm zone 42 for this data frame. this is all my purpose.

Regards

I understand (but I may be wrong) that you started with a csv-file with coordinates in WGS84.
If you save the `ValparaisoPPgis.utm` data.frame as a csv-file you also have a csv-file with UTM42N coordinates.
You also have the `stations` simple-feature object that you can use in spatial analysis, plots etc.

I have the feeling that you need something more, but it is not clear to me what that is.
If this is the case please indicate so and otherwise close the issue.

Sir,
I attached a pdf file here, i apology for taking your time. just if you could scan page 5 and page 7. its is all about the problem i have. and that is my purpose to do with my csv.

Regards

i think i was not able to send the pdf sir,

page 5 to 7 very short.
Thank you.
Regards

I now understand that you want to redo the analysis with your own data.
I scanned quickly through these pages and I think that with the adapted code you reproduced these steps.
If you have specific questions, please let them know.

Thank you sir,

Regards

Sir,
i have 4078 chirps rainfall daily data, how i can do a raster brick. when i apply raster brick i lose 1000 data. i use this code.
library(raster)
lista<-list.files(path=getwd(), pattern="tif\$")
cdd <- stack(lista)
brc<-brick(cdd)

Regards