Skip to content

Instantly share code, notes, and snippets.

View debboutr's full-sized avatar
💭
...working on it...

Rick Debbout debboutr

💭
...working on it...
View GitHub Profile
@debboutr
debboutr / BatchRename.txt
Last active March 14, 2016 20:01
Batch rename files in Powershell
Dir | Rename-Item -NewName {$_.name -replace "","_"}
@debboutr
debboutr / SimpleHTTPServer.py
Created March 14, 2016 20:00
HTTP Server Python
python -m SimpleHTTPServer
http://192.168.1.2:8000
http://127.0.0.1:8000
import os
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
place = 'D:/Projects/chkNRSA_Watersheds/arcpyWSheds'
for f in os.listdir(place):
if '.shp' in f and not '.xml' in f:
if f[:9].replace('_','-') in wsheds:
addLayer = arcpy.mapping.Layer('%s/%s' % (place, f))
arcpy.mapping.AddLayer(df,addLayer,"BOTTOM")
@debboutr
debboutr / explode.py
Last active October 26, 2018 17:14
Explode MultiPolygon geometry into individual Polygon geometries in a shapefile using GeoPandas and Shapely
import geopandas as gpd
from shapely.geometry.polygon import Polygon
from shapely.geometry.multipolygon import MultiPolygon
def explode(indata):
indf = gpd.GeoDataFrame.from_file(indata)
outdf = gpd.GeoDataFrame(columns=indf.columns)
for idx, row in indf.iterrows():
if type(row.geometry) == Polygon:
outdf = outdf.append(row,ignore_index=True)
@debboutr
debboutr / getZone.py
Created July 27, 2016 18:26
find COMID zone
final = np.load('D:/Projects/chkNRSA_Watersheds/FlowlineComidsZone.npy')
temp = final[:,0].astype(int)
x = 23763375
final[np.where(temp == x)]
@debboutr
debboutr / getUpstream.py
Created August 13, 2016 19:17
Gather upstream COMIDs fron the NHDPlusV2 from numpy files
import sys
import pandas as pd
import numpy as np
sys.path.append('D:/Projects/StreamCat')
from StreamCat_functions import dbf2DF, findUpstreamNpy
NHD_Dir = 'D:/NHDPlusV21'
numpy_dir = 'D:/NHDPlusV21/StreamCat_npy/bastards'
zone = '07'
import arcpy, os, sys
from arcpy import env
inputs = {'CA':['18'],'CO':['14','15'],'GB':['16'],'GL':['04'],'MA':['02'],'MS':['05','06','07','08','10L','10U','11'],'NE':['01'],'PN':['17'],'RG':['13'],'SA':['03N','03S','03W'],'SR':['09'],'TX':['12']}
# process one coordinate at a time, locating routes for all hydroregions before looping to next coordinate set
# note that once the flowlines are converted into routes, all attribute information will get dropped, we will process the Locate Routes tool again to determine COMID (to get to stream order) for all sites that fail the checks
sites = 'D:/Projects/WEMAP_WSA/SplitCatsNAD83/xyLayer_join.shp'
@debboutr
debboutr / sjoinPointsNHD.py
Created September 15, 2016 22:46
Spatially joins points with all zones of the NHD appending the COMID of the catchment that each point falls in
import numpy as np
import geopandas as gpd
from geopandas.tools import sjoin
NHD_dir = "D:/NHDPlusV21"
inputs = np.load('%s/StreamCat_npy/zoneInputs.npy' % NHD_dir).item()
pt_file = "C:/Users/Rdebbout/Downloads/Stations_albers.shp"
pts = gpd.GeoDataFrame.from_file(pt_file)
l = "/NHDPlus"
@debboutr
debboutr / compareRasters.py
Created October 25, 2016 18:24
compares if no data cells exist between two rasters
import os
import rasterio
import numpy as np
home = 'L:/Priv/CORFiles/Geospatial_Library/Data/Project/StreamCat/LandscapeRasters/QAComplete'
tifs = []
for x in os.listdir(home):
if ".tif" in x and "mar14" in x and not 'xml' in x and not 'ovr' in x:
print x
tifs.append(x)
@debboutr
debboutr / polygonToRaster.py
Created March 8, 2017 17:17
Handle conversion for very large rasters to prevent Overflow Error!
import itertools
import rasterio as rs
import geopandas as gpd
from rasterio.crs import CRS
from rasterio import features
def makeAffine(tf, lbl, w, h):
if lbl == 'A':
return tf
if lbl == 'B':