haotu : an open lab notebook

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/04/12

R project to R package Rstudio

Filed under: R, R Stats, Uncategorized — S @ 08:18

This is OK

http://www.r-bloggers.com/building-a-package-in-rstudio-is-actually-very-easy/

  1. Start with a Github repository. This will have a set of R sourcecode files, which collectively do something interesting.
  2. Within RStudio, create a new project, using your local Github repository as the project’s source directory.
  3. Within the “Build Tools” section of the “Project Options” make sure that you’ve selected “Package” from the “Project Build Tools” dropdown box.
  4. In that same dialog box, enter the “–no-examples” flag of the “Check Package” build options. (At this stage, you probably don’t have any examples composed. The default assumes that you do. I don’t know why this is.)
  5. If RStudio, didn’t create one, create a subdirectory in your project folder called “R”. Move all your code here. Github will reflect the deletion and new file creation.
  6. Create a DESCRIPTION file. There are numerous sources which explain how to do this.
  7. Make sure your code doesn’t have any errors in it. Easiest way to do that is to source all of them.
  8. Build the package.

A nice Video here:

Also this devtools checklist

https://www.rstudio.com/wp-content/uploads/2015/06/devtools-cheatsheet.pdf

 

2016/03/01

select multiple columns of a data.table by column name

Filed under: Manipulate Data in R, R, R Stats — Tags: , — S @ 12:39
myDT[,.(mycolname1,mycolname2,mycolname3)]

2016/02/22

true copy of a data.table

Filed under: Manipulate Data in R, R — S @ 10:13
mycopy<-copy(DT)

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

2016/02/03

add unique id to attributes table ArcMap 10.3.1

Filed under: arcmap, Python — Tags: , , , — S @ 08:39

This requires a bit of Python scripting, but it is simple. See here for the original post

1. Add a numeric field (column) to attributes table (the column in blue is an example of what I want to produce):

uniqueid1

2. Right click on the new field and select field calculator.

uniqueid2

3. Make sure parser is Python and type is Numeric. In the code box put in:

counter = 100000
def uniqueID():
 global counter
 counter += 1
 return counter

and in the field = box make sure to give the function name

uniqueid()

in this example.

uniqueid3

4. Then it should produce a unique id for each element in the table. Note that you can change the starting number (1000000) and the increment number (1).

uniqueid4

 

2016/01/28

add XY lat long latitude longitude data in Arcmap 10.3

Filed under: arcmap, spatial — S @ 07:23

1. Click the + add data button and add the csv or other file with the XY data. It is helpful to have the columns labeled longitude and latitude.
2. Right click on the newly added table and display XY data.
3. There are some fields here that you can adjust if necessary, just make sure that longitude is X and latitude is Y
4. Once you click OK you will probably get a warning that says that the table you specified does not include an Object-ID field (even though it may very well).
5. Then right click on the newly made item in the table of contents, go to Data… and then Export Data…
6. You will probably want to change the name of the shape file by clicking the folder icon.
7. Then save it!
 

This is sort of helpful https://geonet.esri.com/thread/76217

You can also do this in the ArcCatalog

 

 

« Newer PostsOlder Posts »

Create a free website or blog at WordPress.com.