This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rgeos);library( rgdal) | |
polys <- readOGR('.','polys') | |
lines <- readOGR('.','lines') | |
if (proj4string(polys) == proj4string(lines){ | |
plot(polys); plot(lines, add=T, color='Blue') | |
lines$LENGTHKM <- SpatialLinesLengths(lines)*0.001 # assumes lines are in projection using meters | |
line.sum <- over(polys, lines[6], fn=sum) | |
line.mean <- over(polys, lines[6], fn=mean) | |
line.min <- over(polys, lines[6], fn=min) | |
line.max <- over(polys, lines[6], fn=max) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create data frame 1 | |
x = c("ID1","ID2","ID3","ID4","ID5") | |
y = c("C1","C2","C3","C4","C5") | |
d1 = data.frame("SiteID" = x, "Value" = y) | |
d1 | |
# Create lookup table | |
x = c("ID2","ID5") | |
y = c("C5","C2") | |
lookup = data.frame("SiteID" = x, "Value" = y) | |
lookup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = c("AA","BB","A:B", "CC","C:A") | |
df = data.frame("ID" = x) | |
df | |
df$colons[grep(":", df$ID)] ='yes' | |
df$colons[is.na(df$colons)] ='no' | |
df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pysal as ps | |
import pandas as pd | |
''' | |
Arguments | |
--------- | |
dbfile : DBF file - Input to be imported | |
upper : Condition - If true, make column heads upper case | |
''' | |
def dbf2DF(dbfile, upper=True): #Reads in DBF files and returns Pandas DF | |
db = ps.open(dbfile) #Pysal to open DBF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SpatialLinesEndPoints = function(sldf){ | |
Lns <- slot(sldf, "lines") | |
hash_lns <- sapply(Lns, function(x) length(slot(x, "Lines"))) | |
N <- sum(hash_lns) | |
endpoints <- matrix(NA, ncol = 2, nrow = N) | |
Ind <- integer(length = N) | |
ii <- 1 | |
for (i in 1:length(Lns)) { | |
Lnsi <- slot(Lns[[i]], "Lines") | |
for (j in 1:hash_lns[i]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(raster) | |
## grab US counties shapefile in Oregon | |
shp <- shapefile("C:/Users/mweber/Temp/OR_counties.shp") | |
## no dropping of projection metadata | |
r <- raster(shp,nrows=100,ncols=150) | |
r <- rasterize(shp,r,fun="first") | |
plot(shp,axes=TRUE,border="grey") |
This file has been truncated, but you can view the full file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 52, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import geopandas as gpd | |
from itertools import combinations | |
Feat1 = gpd.GeoDataFrame.from_file('Feat1.shp') | |
Feat2 = gpd.GeoDataFrame.from_file('Feat2.shp') | |
Feat3= gpd.GeoDataFrame.from_file('Feat3.shp') | |
# gather geometries in iterable a list | |
shapes = [Feat1, Feat2, Feat3] | |
# or to show catching overlap try |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import georasters as gr | |
import matplotlib.pyplot as plt | |
r1 = gr.from_file('wshed1') | |
NDV, xsize, ysize, GeoT, Projection, DataType = gr.get_geo_info('wshed1') | |
# change the data type from uint8 to uint32 | |
r1.datatype=4 | |
r1 = r1*2546909 | |
r2 = gr.from_file('wshed2') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Plots = gpd.GeoDataFrame.from_file('Plots.shp') | |
Plots.plot() | |
Features = gpd.GeoDataFrame.from_file('Features.shp') | |
Features.plot() | |
# union features | |
Both = overlay(Plots, Features, how="union") | |
Both.head() | |
# 'clip' by getting rid of union features where attributes for plot are null in the union | |
Clips = Both[pd.notnull(Both['ORIG_FID'])] | |
Clips.plot() |
OlderNewer