This file contains hidden or 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 geopands 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) |
This file contains hidden or 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
| # -*- coding: utf-8 -*- | |
| """ | |
| Created on Tue Sep 20 08:20:02 2016 | |
| @author: mweber | |
| """ | |
| import os | |
| from ftplib import FTP |
This file contains hidden or 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
| # example of reading regular data table from Postgres using RPostgresSQL library | |
| library(RPostgreSQL) | |
| con <- dbConnect(PostgreSQL(), host="localhost", port="5432", user="username", password="password", dbname="db_name") | |
| result <- dbGetQuery(con, statement = "SELECT * FROM table1, table2 WHERE table1.key = table2.key") | |
| head(result) | |
| # example of reading spatial data from PostGIS using rpostgis library | |
| library(rpostgis) | |
| conn <- dbConnect(PostgreSQL(), host="localhost", port="5432", user="postgres", password="postgres", dbname="sp_db") | |
| dbSchema(conn, name = 'sp_db') |
This file contains hidden or 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 | |
| data = gr.from_file('myraster.tif') | |
| data.nodata_value | |
| # assuming we want to set 0s to nodata- | |
| data2= gr.GeoRaster( | |
| data.raster, | |
| data.geot, | |
| nodata_value=0, | |
| projection=data.projection, | |
| datatype=data.datatype, |
This file contains hidden or 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 | |
| import rasterio | |
| import fiona | |
| from rasterio import features | |
| import os | |
| from datetime import datetime as dt | |
| def Rasterize(shapefile, inras, outras, meta, field): | |
| with rasterio.open(inras) as src: | |
| kwargs = src.meta.copy() |
This file contains hidden or 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 | |
| def reduce_depth(inras, outras, out_depth, nodata): | |
| infile = gr.from_file(inras) | |
| out= gr.GeoRaster( | |
| infile.raster, | |
| infile.geot, | |
| nodata_value=nodata, | |
| projection=data.projection, | |
| datatype='Byte') |
This file contains hidden or 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 os | |
| dir1_vars = [f.split('_')[0] for f in os.listdir(dir1) if f.count('Region01')] # files in this directory have repeating base names with '_Region##' at end, this grabs unique file names | |
| state_vars = [f.split('_')[0] for f in os.listdir('L:/Priv/CORFiles/Geospatial_Library/Data/Project/StreamCat/FTP_Staging/StreamCat/States') if f.count('AL')] # files in this directory have repeating base names with state name at end, this grabs unique file names | |
| missing = list(set(hydroregion_vars) - set(state_vars)) |
This file contains hidden or 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
| nearby = function(points, polys, column){ | |
| m = gDistance(points, polys, byid=TRUE) | |
| row = apply(m, 2, function(x) which(x==min(x))) | |
| row = sapply(row, "[",1) | |
| labels = unlist(polys@data[row,][[column]]) | |
| points$missing <- labels | |
| # head(missing) | |
| return(points@data) | |
| } |
This file contains hidden or 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
| "c:\Program Files\ArcGIS\Pro\bin\Python\scripts\propy.bat" my_script.py |
This file contains hidden or 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(sf) | |
| gages <- st_read('C:/Users/mweber/Temp/gages_test.shp') | |
| class(gages) | |
| # Let's pretend it's a csv file we read in rather than a shapefile - I'll strip out the 'spatial' | |
| # part (the geometry column) and make it just a data.frame with Lon and Lat columns, then show | |
| # how to promote it back | |
| st_geometry(gages) <- NULL | |
| class(gages) |