[R-sig-Geo] Problem in represents shapefile in Landsat image
Agustin Lobo
alobolistas at gmail.com
Fri Jan 17 10:24:49 CET 2014
Alexandre,
You should also have a prj file for your shapefile. This is where all
the projection info is
stored.
Once you get it, try reading with readOGR(), i.e.
require(rgdal)
contorno_line <- readOGR(dsn="path to the shapefile", layer="Tamandua288")
And verify that the slots proj4string in both raster and vector are
identical, i.e
using
projection(landa)
projection(contorno_line)
and verify that they do overlay:
plot(landa[[3]])
plot(contorno_line,add=TRUE)
If both projection() match but the objects do not overlay, then the
most likely is that the 2 objects are actually not
in the same projection (Datum difference?) as you think, note that
lacking a prj file should make you feel uncomfortable. If you do not
have the prj, then you must get the information on projection and
datum and either make a prj on your own or set the projection in R
Agus
On Wed, Jan 15, 2014 at 5:33 PM, ASANTOS <alexandresantosbr at yahoo.com.br> wrote:
> Dear Members,
>
> I would like to represents my contour area (contorno_line object)
> (53,22ha) in shapefile format in a Landsat 5 images (r1a, r2a and r3a), but
> I don't know why my area drops in a river, I verify the proj4string and both
> are "+proj=utm +zone=23 +south +datum=WGS84 +units=m +no_defs" and it's OK
> and the shapefile was create with the use of geodetic GPS. I suspect that
> some kind of transformation is necessary in Landsat image before the use or
> any projection problem, Any member can helps me. Follow my scrip:
>
> require(raster)
> require(sp)
> require(maptools)
>
> #STARTS
> ##------------------------------------------------------------------------------
> ## Bands 5, 4 e 3 of Landsat 5
> #
> #Download
> links <- c(
> "https://www.dropbox.com/s/6oie1ns3w52ur96/band5.crop.tif",
> "https://www.dropbox.com/s/aa333he7g7vxcsj/band4.crop.tif",
> "https://www.dropbox.com/s/3d7ad89uddx57o8/band3.crop.tif")
>
> tokens <- gsub("^.*/s/","",dirname(links))
> fileNames <- basename(links)
> newLinks <- file.path("http://dl.dropbox.com/s", tokens, fileNames);
> newLinks
>
> for (a in newLinks) {
> tryCatch(download.file(a, dest=basename(a), mode='wb'),
> error=function(...) print("Falha no
> download!"))}
>
> #Graphic representation of satellite images
> r1a<- raster(c("band5.crop.tif"))
> r2a<- raster(c("band4.crop.tif"))
> r3a<- raster(c("band3.crop.tif"))
> landa<- stack(r1a,r2a,r3a)
> plotRGB(landa)
> #
>
> #-------------------------------------------------------------------------------
> #Download of the contour in shapefile
> links <- c(
> "https://www.dropbox.com/s/1oz5lhnk96jih3w/Tamandua288.dbf",
> "https://www.dropbox.com/s/6b3uygyrjhq1bby/Tamandua288.shp",
> "https://www.dropbox.com/s/wntluhn8bi7us2f/Tamandua288.shx")
>
> tokens <- gsub("^.*/s/","",dirname(links))
> fileNames <- basename(links)
> newLinks <- file.path("http://dl.dropbox.com/s", tokens, fileNames);
> newLinks
>
> for (a in newLinks) {
> tryCatch(download.file(a, dest=basename(a), mode='wb'),
> error=function(...) print("Falha no
> download!"))}
>
> contorno_line <- readShapeLines ("Tamandua288.shp",
> proj4string=CRS("+proj=utm +zone=23 +south +datum=WGS84 +units=m +no_defs"))
> lines(contorno_line,col="red") # And the area drops inside a river.
> #
> #END
>
>
> Thanks,
>
> --
> ======================================================================
> Alexandre dos Santos
> Proteção Florestal - Forest Protection
> IFMT - Instituto Federal de Educação, Ciência e Tecnologia de Mato Grosso
> Campus Cáceres
> Caixa Postal 244
> Avenida dos Ramires, s/n
> Bairro: Distrito Industrial
> Cáceres - MT CEP: 78.200-000
> Fone: (+55) 65 8132-8112 (TIM) (+55) 65 9686-6970 (VIVO)
>
> alexandre.santos at cas.ifmt.edu.br
> Lattes: http://lattes.cnpq.br/1360403201088680
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list