Skip to content

Instantly share code, notes, and snippets.

View rukku's full-sized avatar

RK Aranas rukku

  • Philippine Space Agency
  • Quezon City, Philippines
View GitHub Profile
@rukku
rukku / nn2.R
Created February 8, 2012 09:32
Finds nearest neighbor between point patterns using FNN
#Get second nearest neighbors using knnx
x1 <- cbind(ponderosa$x, ponderosa$y)
x2 <- cbind(rp$x, rp$y)
nn2 <- get.knnx(x1, x2, 2)
X.2 <- nn2$nn.dist[,2]
X.22 <- X.2^2
sumX.22 <- sum(X.22)
@rukku
rukku / nn2.crossdist.r
Created February 8, 2012 09:45
Gets the second nearest neighbor using spatstat's crossdist
#get pairwise distances from rp and ponderosa datasets
xpairs <- crossdist(rp, ponderosa)
#Initialize vector container for X.2
X.2 = numeric()
#Sort rows and get second nearest neighbor
for (i in 1:nrow(xpairs) {
x <- sort(xpairs[i,])[2]
X.2 <- append(X.2, x)
@rukku
rukku / nn2wrong.R
Created February 12, 2012 02:43
Second nearest neighbor with crossdist. NOT.
#Get second nearest neighbors using crossdist
crossnn2 <- crossdist(rp, ponderosa)
X.2 <- crossnn2[,2]
@rukku
rukku / estero.html
Created February 12, 2012 09:02
Loading the estero WFS file
<html>
<head>
<title>OpenLayers: Google Layer Example</title>
<link rel="stylesheet" href="style1.css" type="text/css" />
<link rel="stylesheet" href="style2.css" type="text/css" />
<!-- this gmaps key generated for http://localhost:8080/geoserver/ -->
<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAl9RMqSzhPUXAfeBCXOussRTQDbvAygy0cfGJr8dEMAYKf3RWNBQqP9mjKIsqTfmAlz5LOJ3Xpy5s4w'></script>
<script src="resources/openlayers/OpenLayers.js"></script>
<script type="text/javascript">
@rukku
rukku / style1.css
Created February 12, 2012 09:06
Style for Pasig loader.
div.olMap {
z-index: 0;
padding: 0 !important;
margin: 0 !important;
cursor: default;
}
div.olMapViewport {
text-align: left;
}
@rukku
rukku / style2.css
Created February 12, 2012 09:07
Second style file for the Pasig loader
/**
* CSS Reset
* From Blueprint reset.css
* http://blueprintcss.googlecode.com
*/
html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, code, del, dfn, em, img, q, dl, dt, dd, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {margin:0;padding:0;border:0;font-weight:inherit;font-style:inherit;font-size:100%;font-family:inherit;vertical-align:baseline;}
body {line-height:1.5;}
table {border-collapse:separate;border-spacing:0;}
caption, th, td {text-align:left;font-weight:normal;}
table, td, th {vertical-align:middle;}
@rukku
rukku / plugins.ini
Created February 12, 2012 09:17
pgadmin3 plugins.ini for Linux hosts
;
; pgShapeLoader (Linux):
;
Title=PostGIS Shapefile and DBF loader
Command=$$PGBINDIR/shp2pgsql-gui -U $$USERNAME -d $$DATABASE -p $$PORT -h $$HOSTNAME
Description=Open a PostGIS ESRI Shapefile or Plain dbf loader console to the current database.
KeyFile=$$PGBINDIR/shp2pgsql-gui
Platform=unix
ServerType=postgresql
Database=Yes
@rukku
rukku / index.val.R
Created February 16, 2012 08:33
Find the index for a value in an array
mat<-matrix(1:9,1,9)
which(mat==5,arr.ind=TRUE)
row col
[1,] 1 5
#from: http://r.789695.n4.nabble.com/How-do-I-find-the-index-for-a-value-in-an-array-td846012.html
@rukku
rukku / angle.bet.vectors.R
Created February 16, 2012 08:35
Computes the angle between two vectors in R
theta <- acos( sum(a*b) / ( sqrt(sum(a * a)) * sqrt(sum(b * b)) ) )
#taken from http://stackoverflow.com/questions/1897704/angle-between-two-vectors-in-r
@rukku
rukku / nncross2.R
Created February 20, 2012 03:39
Second nearest neighbor with crossdist using apply()
#get pairwise distances from rp and ponderosa datasets
xpairs <- crossdist(rp, ponderosa)
#A function to get the second nearest neighbor
nncross2 <- function (x) sort(x)[2]
#Initialize the vector container for x.2
x.2 <- numeric()
#Applies the nncross2 function to the xpairs matrix.