Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added code block, fixed lines
Source Link
GISHuman
  • 3.7k
  • 1
  • 21
  • 44

##My dataframe with point files (lets call it trainData_crs) trainData_crs<- read.csv(file.csv) > class(trainData_crs) [1] "data.frame"

trainData_crs<- read.csv(file.csv)  
                                                                     
class(trainData_crs)
[1] "data.frame"

crs(trainData_crs) [1] NA

summary(trainData_crs) PlotType Class Latitude Longitude
closedforest:22 Min. :1.000 Min. :17.81 Min. :24.72
grass :34 1st Qu.:2.000 1st Qu.:17.86 1st Qu.:24.98
lowforest :24 Median :3.000 Median :17.92 Median :25.02
mediumforest:26 Mean :2.904 Mean :17.95 Mean :25.02
shrubs : 4 3rd Qu.:4.000 3rd Qu.:18.01 3rd Qu.:25.10
unknown : 3 Max. :7.000 Max. :18.46 Max. :25.16
water : 1

crs(trainData_crs)
[1] NA




summary(trainData_crs)
 PlotType      Class                      Latitude       Longitude    
 closedforest:22   Min.   :1.000   Min.   :17.81   Min.   :24.72  
 grass       :34   1st Qu.:2.000   1st Qu.:17.86   1st Qu.:24.98  
 lowforest   :24   Median :3.000   Median :17.92   Median :25.02  
 mediumforest:26   Mean   :2.904   Mean   :17.95   Mean   :25.02  
 shrubs      : 4   3rd Qu.:4.000   3rd Qu.:18.01   3rd Qu.:25.10  
 unknown     : 3   Max.   :7.000   Max.   :18.46   Max.   :25.16  
 water       : 1 

all_landsat_bands<-list.files ("file.tif") img <- brick(all_landsat_bands)

img <- brick(LandsatAprJune_2019_st) class(img) [1] "RasterBrick" attr(,"package") [1] "raster" names(img) [1] "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B10" "B11"

all_landsat_bands<-list.files ("file.tif")

img <- brick(all_landsat_bands)

img <- brick(LandsatAprJune_2019_st)
 class(img)
[1] "RasterBrick"
attr(,"package")
[1] "raster"
 names(img)
[1] "B1"  "B2"  "B3"  "B4"  "B5"  "B6"  "B7"  "B10" "B11"
coordinates(trainData_crs)<-~Latitude +Longitude 

proj4string(trainData_crs) = CRS("+init=epsg:4326")

crs(trainData_crs_sp) CRS arguments: +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m +no_defs crs(img) CRS arguments: +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m +no_defs

crs(trainData_crs_sp)
CRS arguments:
 +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m
+no_defs 

 crs(img)
CRS arguments:
 +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m
+no_defs 

##My dataframe with point files (lets call it trainData_crs) trainData_crs<- read.csv(file.csv) > class(trainData_crs) [1] "data.frame"

crs(trainData_crs) [1] NA

summary(trainData_crs) PlotType Class Latitude Longitude
closedforest:22 Min. :1.000 Min. :17.81 Min. :24.72
grass :34 1st Qu.:2.000 1st Qu.:17.86 1st Qu.:24.98
lowforest :24 Median :3.000 Median :17.92 Median :25.02
mediumforest:26 Mean :2.904 Mean :17.95 Mean :25.02
shrubs : 4 3rd Qu.:4.000 3rd Qu.:18.01 3rd Qu.:25.10
unknown : 3 Max. :7.000 Max. :18.46 Max. :25.16
water : 1

all_landsat_bands<-list.files ("file.tif") img <- brick(all_landsat_bands)

img <- brick(LandsatAprJune_2019_st) class(img) [1] "RasterBrick" attr(,"package") [1] "raster" names(img) [1] "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B10" "B11"

coordinates(trainData_crs)<-~Latitude +Longitude
proj4string(trainData_crs) = CRS("+init=epsg:4326")

crs(trainData_crs_sp) CRS arguments: +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m +no_defs crs(img) CRS arguments: +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m +no_defs

##My dataframe with point files (lets call it trainData_crs)

trainData_crs<- read.csv(file.csv)  
                                                                     
class(trainData_crs)
[1] "data.frame"
crs(trainData_crs)
[1] NA




summary(trainData_crs)
 PlotType      Class                      Latitude       Longitude    
 closedforest:22   Min.   :1.000   Min.   :17.81   Min.   :24.72  
 grass       :34   1st Qu.:2.000   1st Qu.:17.86   1st Qu.:24.98  
 lowforest   :24   Median :3.000   Median :17.92   Median :25.02  
 mediumforest:26   Mean   :2.904   Mean   :17.95   Mean   :25.02  
 shrubs      : 4   3rd Qu.:4.000   3rd Qu.:18.01   3rd Qu.:25.10  
 unknown     : 3   Max.   :7.000   Max.   :18.46   Max.   :25.16  
 water       : 1 
all_landsat_bands<-list.files ("file.tif")

img <- brick(all_landsat_bands)

img <- brick(LandsatAprJune_2019_st)
 class(img)
[1] "RasterBrick"
attr(,"package")
[1] "raster"
 names(img)
[1] "B1"  "B2"  "B3"  "B4"  "B5"  "B6"  "B7"  "B10" "B11"
coordinates(trainData_crs)<-~Latitude +Longitude 

proj4string(trainData_crs) = CRS("+init=epsg:4326")
crs(trainData_crs_sp)
CRS arguments:
 +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m
+no_defs 

 crs(img)
CRS arguments:
 +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m
+no_defs 
spelling, and format
Source Link
nmtoken
  • 13.6k
  • 5
  • 38
  • 89

Can someone help me understand why I have issue getting my dataframe (point coordinates into the same coordinate with my Raster data?

##My dataframe with point files (lets call it trainData_crs) trainData_crs<- read.csv(file.csv) > class(trainData_crs) [1] "data.frame"

##The data frame had no coordinate system

crs(trainData_crs) [1] NA

summary(trainData_crs) PlotType Class Latitude Longitude
closedforest:22 Min. :1.000 Min. :17.81 Min. :24.72
grass :34 1st Qu.:2.000 1st Qu.:17.86 1st Qu.:24.98
lowforest :24 Median :3.000 Median :17.92 Median :25.02
mediumforest:26 Mean :2.904 Mean :17.95 Mean :25.02
shrubs : 4 3rd Qu.:4.000 3rd Qu.:18.01 3rd Qu.:25.10
unknown : 3 Max. :7.000 Max. :18.46 Max. :25.16
water : 1

##create##Create a tifTIFF raster and convert it to Rasterbricks

all_landsat_bands<-list.files ("file.tif") img <- brick(all_landsat_bands)

img <- brick(LandsatAprJune_2019_st) class(img) [1] "RasterBrick" attr(,"package") [1] "raster" names(img) [1] "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B10" "B11"

##Fist##First convert data frame to Latitude and Longitude coordinate numbers coordinates(trainData_crs)<-~Latitude +Longitude proj4string(trainData_crs) = CRS("+init=epsg:4326")

coordinates(trainData_crs)<-~Latitude +Longitude
proj4string(trainData_crs) = CRS("+init=epsg:4326")

##convert##Convert to same projection trainData_crs_sp <- spTransform(trainData_crs, crs(img))

trainData_crs_sp <- spTransform(trainData_crs, crs(img))

##confirm##Confirm if points and image are in same coordinates

crs(trainData_crs_sp) CRS arguments: +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m +no_defs crs(img) CRS arguments: +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m +no_defs

##plot##Plot them to check if the points overlap with rasterBrick plotRGB(img, r = 4, g = 3, b = 2, stretch = "lin", scale=1000, axes = TRUE, main = "RGB composite image\n Landsat Bands 7, 3, 2"); plot(trainData_crs_sp, add=T)

But the difficulty that iI have is that, even after converting the dataframe of points to rasterbrick coordinates, they still do not fall in the same arearea or overlap.

Can someone help me understand why I have issue getting my dataframe (point coordinates into the same coordinate with my Raster data?

##My dataframe with point files (lets call it trainData_crs) trainData_crs<- read.csv(file.csv) > class(trainData_crs) [1] "data.frame"

##The data frame had no coordinate system

crs(trainData_crs) [1] NA

summary(trainData_crs) PlotType Class Latitude Longitude
closedforest:22 Min. :1.000 Min. :17.81 Min. :24.72
grass :34 1st Qu.:2.000 1st Qu.:17.86 1st Qu.:24.98
lowforest :24 Median :3.000 Median :17.92 Median :25.02
mediumforest:26 Mean :2.904 Mean :17.95 Mean :25.02
shrubs : 4 3rd Qu.:4.000 3rd Qu.:18.01 3rd Qu.:25.10
unknown : 3 Max. :7.000 Max. :18.46 Max. :25.16
water : 1

##create a tif raster and convert it to Rasterbricks

all_landsat_bands<-list.files ("file.tif") img <- brick(all_landsat_bands)

img <- brick(LandsatAprJune_2019_st) class(img) [1] "RasterBrick" attr(,"package") [1] "raster" names(img) [1] "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B10" "B11"

##Fist convert data frame to Latitude and Longitude coordinate numbers coordinates(trainData_crs)<-~Latitude +Longitude proj4string(trainData_crs) = CRS("+init=epsg:4326")

##convert to same projection trainData_crs_sp <- spTransform(trainData_crs, crs(img))

##confirm if points and image are in same coordinates

crs(trainData_crs_sp) CRS arguments: +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m +no_defs crs(img) CRS arguments: +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m +no_defs

##plot them to check if the points overlap with rasterBrick plotRGB(img, r = 4, g = 3, b = 2, stretch = "lin", scale=1000, axes = TRUE, main = "RGB composite image\n Landsat Bands 7, 3, 2"); plot(trainData_crs_sp, add=T)

But the difficulty that i have is that, even after converting the dataframe of points to rasterbrick coordinates, they still do not fall in the same are or overlap.

Can someone help me understand why I have issue getting my dataframe (point coordinates into the same coordinate with my Raster data?

##My dataframe with point files (lets call it trainData_crs) trainData_crs<- read.csv(file.csv) > class(trainData_crs) [1] "data.frame"

##The data frame had no coordinate system

crs(trainData_crs) [1] NA

summary(trainData_crs) PlotType Class Latitude Longitude
closedforest:22 Min. :1.000 Min. :17.81 Min. :24.72
grass :34 1st Qu.:2.000 1st Qu.:17.86 1st Qu.:24.98
lowforest :24 Median :3.000 Median :17.92 Median :25.02
mediumforest:26 Mean :2.904 Mean :17.95 Mean :25.02
shrubs : 4 3rd Qu.:4.000 3rd Qu.:18.01 3rd Qu.:25.10
unknown : 3 Max. :7.000 Max. :18.46 Max. :25.16
water : 1

##Create a TIFF raster and convert it to Rasterbricks

all_landsat_bands<-list.files ("file.tif") img <- brick(all_landsat_bands)

img <- brick(LandsatAprJune_2019_st) class(img) [1] "RasterBrick" attr(,"package") [1] "raster" names(img) [1] "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B10" "B11"

##First convert data frame to Latitude and Longitude coordinate numbers

coordinates(trainData_crs)<-~Latitude +Longitude
proj4string(trainData_crs) = CRS("+init=epsg:4326")

##Convert to same projection

trainData_crs_sp <- spTransform(trainData_crs, crs(img))

##Confirm if points and image are in same coordinates

crs(trainData_crs_sp) CRS arguments: +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m +no_defs crs(img) CRS arguments: +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m +no_defs

##Plot them to check if the points overlap with rasterBrick plotRGB(img, r = 4, g = 3, b = 2, stretch = "lin", scale=1000, axes = TRUE, main = "RGB composite image\n Landsat Bands 7, 3, 2"); plot(trainData_crs_sp, add=T)

But the difficulty that I have is that, even after converting the dataframe of points to rasterbrick coordinates, they still do not fall in the same area or overlap.

deleted 25 characters in body; deleted 36 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Can someone help me understand why I have issue getting my dataframe (point coordinates into the same coordinate with my Raster data.?

##My dataframe with point files (lets call it trainData_crs) trainData_crs<- read.csv(file.csv) > class(trainData_crs) [1] "data.frame"

##The data frame had no coordinate system

crs(trainData_crs) [1] NA

summary(trainData_crs) PlotType Class Latitude Longitude
closedforest:22 Min. :1.000 Min. :17.81 Min. :24.72
grass :34 1st Qu.:2.000 1st Qu.:17.86 1st Qu.:24.98
lowforest :24 Median :3.000 Median :17.92 Median :25.02
mediumforest:26 Mean :2.904 Mean :17.95 Mean :25.02
shrubs : 4 3rd Qu.:4.000 3rd Qu.:18.01 3rd Qu.:25.10
unknown : 3 Max. :7.000 Max. :18.46 Max. :25.16
water : 1

##create a tif raster and convert it to Rasterbricks

all_landsat_bands<-list.files ("file.tif") img <- brick(all_landsat_bands)

img <- brick(LandsatAprJune_2019_st) class(img) [1] "RasterBrick" attr(,"package") [1] "raster" names(img) [1] "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B10" "B11"

##Fist convert data frame to Latitude and Longitude coordinate numbers coordinates(trainData_crs)<-~Latitude +Longitude proj4string(trainData_crs) = CRS("+init=epsg:4326")

##convert to same projection trainData_crs_sp <- spTransform(trainData_crs, crs(img))

##confirm if points and image are in same coordinates

crs(trainData_crs_sp) CRS arguments: +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m +no_defs crs(img) CRS arguments: +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m +no_defs

##plot them to check if the points overlap with rasterBrick plotRGB(img, r = 4, g = 3, b = 2, stretch = "lin", scale=1000, axes = TRUE, main = "RGB composite image\n Landsat Bands 7, 3, 2"); plot(trainData_crs_sp, add=T)

But the difficulty that i have is that, even after converting the dataframe of points to rasterbrick coordinates, they still dontdo not fall in the same are or overlap. Is there anything I am doing wrong?

Thank you for your help

Can someone help me understand why I have issue getting my dataframe (point coordinates into the same coordinate with my Raster data.

##My dataframe with point files (lets call it trainData_crs) trainData_crs<- read.csv(file.csv) > class(trainData_crs) [1] "data.frame"

##The data frame had no coordinate system

crs(trainData_crs) [1] NA

summary(trainData_crs) PlotType Class Latitude Longitude
closedforest:22 Min. :1.000 Min. :17.81 Min. :24.72
grass :34 1st Qu.:2.000 1st Qu.:17.86 1st Qu.:24.98
lowforest :24 Median :3.000 Median :17.92 Median :25.02
mediumforest:26 Mean :2.904 Mean :17.95 Mean :25.02
shrubs : 4 3rd Qu.:4.000 3rd Qu.:18.01 3rd Qu.:25.10
unknown : 3 Max. :7.000 Max. :18.46 Max. :25.16
water : 1

##create a tif raster and convert it to Rasterbricks

all_landsat_bands<-list.files ("file.tif") img <- brick(all_landsat_bands)

img <- brick(LandsatAprJune_2019_st) class(img) [1] "RasterBrick" attr(,"package") [1] "raster" names(img) [1] "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B10" "B11"

##Fist convert data frame to Latitude and Longitude coordinate numbers coordinates(trainData_crs)<-~Latitude +Longitude proj4string(trainData_crs) = CRS("+init=epsg:4326")

##convert to same projection trainData_crs_sp <- spTransform(trainData_crs, crs(img))

##confirm if points and image are in same coordinates

crs(trainData_crs_sp) CRS arguments: +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m +no_defs crs(img) CRS arguments: +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m +no_defs

##plot them to check if the points overlap with rasterBrick plotRGB(img, r = 4, g = 3, b = 2, stretch = "lin", scale=1000, axes = TRUE, main = "RGB composite image\n Landsat Bands 7, 3, 2"); plot(trainData_crs_sp, add=T)

But the difficulty that i have is that, even after converting the dataframe of points to rasterbrick coordinates, they still dont fall in the same are or overlap. Is there anything I am doing wrong?

Thank you for your help

Can someone help me understand why I have issue getting my dataframe (point coordinates into the same coordinate with my Raster data?

##My dataframe with point files (lets call it trainData_crs) trainData_crs<- read.csv(file.csv) > class(trainData_crs) [1] "data.frame"

##The data frame had no coordinate system

crs(trainData_crs) [1] NA

summary(trainData_crs) PlotType Class Latitude Longitude
closedforest:22 Min. :1.000 Min. :17.81 Min. :24.72
grass :34 1st Qu.:2.000 1st Qu.:17.86 1st Qu.:24.98
lowforest :24 Median :3.000 Median :17.92 Median :25.02
mediumforest:26 Mean :2.904 Mean :17.95 Mean :25.02
shrubs : 4 3rd Qu.:4.000 3rd Qu.:18.01 3rd Qu.:25.10
unknown : 3 Max. :7.000 Max. :18.46 Max. :25.16
water : 1

##create a tif raster and convert it to Rasterbricks

all_landsat_bands<-list.files ("file.tif") img <- brick(all_landsat_bands)

img <- brick(LandsatAprJune_2019_st) class(img) [1] "RasterBrick" attr(,"package") [1] "raster" names(img) [1] "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B10" "B11"

##Fist convert data frame to Latitude and Longitude coordinate numbers coordinates(trainData_crs)<-~Latitude +Longitude proj4string(trainData_crs) = CRS("+init=epsg:4326")

##convert to same projection trainData_crs_sp <- spTransform(trainData_crs, crs(img))

##confirm if points and image are in same coordinates

crs(trainData_crs_sp) CRS arguments: +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m +no_defs crs(img) CRS arguments: +proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m +no_defs

##plot them to check if the points overlap with rasterBrick plotRGB(img, r = 4, g = 3, b = 2, stretch = "lin", scale=1000, axes = TRUE, main = "RGB composite image\n Landsat Bands 7, 3, 2"); plot(trainData_crs_sp, add=T)

But the difficulty that i have is that, even after converting the dataframe of points to rasterbrick coordinates, they still do not fall in the same are or overlap.

Source Link
Loading