haotu : an open lab notebook

2016/07/06

center gis point of a polygon shape file

Filed under: arcmap, R spatial — Tags: , — S @ 08:20

http://support.esri.com/technical-article/000009381

In the map document, open the attribute table for the polygon feature class by right-clicking the layer name.
In the attribute table, navigate to Table Options > Add Field and add two new fields of type Double. Name one ‘Longitude’ and the other ‘Latitude’.
Right-click the Longitude field and select Calculate Geometry.
In the Calculate Geometry dialog box, select ‘X Coordinate of Centroid’ from the Property drop-down menu. Click OK.
Right-click the Latitude field and select Calculate Geometry.
In the Calculate Geometry dialog box, select ‘Y Coordinate of Centroid’ from the Property drop-down menu. Click OK.

Advertisements

2016/04/25

assign nearest point to a polygon

Filed under: R, R spatial, R Stats, Uncategorized — S @ 11:31

 

wer<-SpatialPointsDataFrame(data.frame(x.subset[,"longitude"],x.subset[,"latitude"]),data=data.frame(x.subset))
n <- length(wer)
nearest <- character(n)
for (i in seq_along(nearest)) {
 nearest[i] <- names(polys)[which.min(gDistance(wer[i,], polys, byid=TRUE))]
}

This may give you warnings if your code is not projected into a planar coordinate system

http://stackoverflow.com/questions/26308426/how-do-i-find-the-polygon-nearest-to-a-point-in-r

2016/04/19

get latitude longitude raster cells

Filed under: R, R graphics, R spatial, Uncategorized — S @ 07:46
rasterToPoints(stacked) #this also gives the cell values of the raster layer or layers

http://gis.stackexchange.com/questions/142156/r-how-to-get-latitudes-and-longitudes-from-a-rasterlayer

 

 

number of layers in raster stack

Filed under: R, R graphics, R spatial, R Stats, Uncategorized — S @ 07:08
dimension(stacked)[3]

2016/04/18

stack rasters with different extents etc..

Filed under: arcmap, R, R, R spatial, R Stats, Uncategorized — S @ 13:42
two<-resample(two,one)
stack(one,two)

raster cell area size 1 degree cell size km2

Filed under: R, R spatial, R Stats, Uncategorized — Tags: , — S @ 08:14

For a 1×1 degree cell size raster

r <- raster(ncol=360, nrow=180) #or just the default r<-raster()
area(r)
area(r)$values

 

http://gis.stackexchange.com/questions/177622/r-calculate-raster-cell-size-in-map-units

 

http://gis.stackexchange.com/questions/29734/how-to-calculate-area-of-1-x-1-degree-cells-in-a-raster

2016/02/19

Join polygons like countries from mapdata

Filed under: arcmap, R, R, R spatial — S @ 13:28
library(maps)
library(mapdata)
library(maptools)
library(rgeos)

DR<-map(database = 'worldHires',regions="Dominican Republic",fill=TRUE)
 IDs<-DR$names
 DR<-map2SpatialPolygons(DR,IDs, proj4string=CRS("+proj=longlat +datum=WGS84"))
Haiti<-map(database = 'worldHires',regions="Haiti",fill=TRUE)
 IDs<-Haiti$names
 Haiti<-map2SpatialPolygons(Haiti,IDs, proj4string=CRS("+proj=longlat +datum=WGS84"))
Hispaniola<-gUnion(DR, Haiti)
plot(Hispaniola)

Note fill=TRUE

Create a free website or blog at WordPress.com.