Skip to content

Instantly share code, notes, and snippets.

@glw
glw / gist:0e340a987acdc1a49814
Last active June 8, 2016 21:26
gdal compress and mosaic
#as seen on http://blog.cleverelephant.ca/2015/02/geotiff-compression-for-dummies.html
gdal_translate \
-co COMPRESS=JPEG \
-co PHOTOMETRIC=YCBCR \
-co TILED=YES \
5255C.tif 5255C_JPEG_YCBCR.tif
#create overviews
gdaladdo \
@glw
glw / gist:6fc733c9beaaad462900
Last active August 29, 2015 14:18
shp2pgsql bulk import shpfiles
#Import a directory of shapefiles into postgis as a geometry
#replace EPSG SRID, database, and username, and others if necessary
for f in *.shp;
do
shp2pgsql -s <EPSG SRID> -g geom $f main.${f%.*} | psql -h localhost -p 5432 -d <database> -U <username>;
done
@glw
glw / gist:1b2e9e8b29b645bada84
Last active February 12, 2016 19:11
bash copy and move files and keep current modified date
cp -r -v -p <file> <dir>
@glw
glw / changefileext
Created February 11, 2015 07:04
change file extension
for file in *.JPG ; do mv $file `echo $file | sed 's/\(.*\.\)JPG/\1jpg/'` ; done
@glw
glw / arcsde-to-shp
Created December 24, 2014 18:05
Batch export from ArcSDE to shapefile
# Name: arcsde-to-shp.py
# Description: Copies data from ArcSDE, converts it to shp file format and puts into destination folder
# Author: Garret Wais
import arcpy, os
from arcpy import env
arcpy.env.overwriteOutput=True
#set OS working directory
os.chdir("T:\\")
@glw
glw / ubuntu14-gis-install
Last active July 18, 2016 00:49
postgis, pgrouting, qgis install on ubuntu 14
#The following will install Postgres, pgAdmin3, PostGIS, PGRouting, QGIS, and numix (for cooler icons)
#The ubuntugis launchpad repo provides all but pgrouting, pgAdmin and of course the numix icons, it provides similar versions of software - https://launchpad.net/~ubuntugis/+archive/ubuntu/ubuntugis-unstable
#Currently on Ubuntu 14.x the universal package sources offer Posgresql 9.3, and Postgis 2.1.2 so there is no need to add repositories for these alone, unless looking for the most up-to-date version. In which case going straight to the source will be your best bet.
#! /bin/bash (include if you want to turn this into a script)
#install postgis postgresql pgadmin3 from PGDG Repo **See alternative installation below if interested in a more up-to-date QGIS.
#source: http://trac.osgeo.org/postgis/wiki/UsersWikiPostGIS21UbuntuPGSQL93Apt
@glw
glw / pykml_install
Created July 3, 2014 21:09
installing pykml on Ubuntu 12.04
sudo apt-get install libxml2-dev libxslt1-dev python-dev
sudo pip install lxml
sudo pip install pykml
sudo apt-get update
@glw
glw / batch_arcpy_fieldcalculation
Last active August 29, 2015 14:02
Arcpy batch field calculation
import arcpy
mxd = arcpy.mapping.MapDocument("Current") # finds metadata on your current MXD
layerlist = arcpy.mapping.ListLayers(mxd) # grabs a list of layers with in your MXD
del layerlist[3] #If you need to delete an item in the layerlist list
expr = "'Northwest'" # Variables to run the calculatefield function. **notice the extra '' within ""...
field = "Zone" #
# Goes through list and assigns expr to the field you specified
@glw
glw / gdal_mosaic
Last active August 29, 2015 14:02
Simple GDAL mosaic of all tifs in folder
#Compress tif with gdal
gdal_translate -of GTiff -co COMPRESS=DEFLATE -co TILED=NO image1.tif image1_compressed.tif
#copy all tifs to new location
for %I in (image1.tif image2.tif image3.tif image4.tif) do copy %I test\folder\
#mosaic with gdal
gdalwarp --config GDAL_CACHEMAX 3000 -wm 3000 *.tif final_mosaic.tif
@glw
glw / RMySQL_Install
Last active August 29, 2015 14:02
RMySQL Install
#Ubuntu 12.04
#R 3.1.0
terminal:
sudo apt-get install libdbd-mysql libmysqlclient-dev
wget http://cran.r-project.org/src/contrib/RMySQL_0.9-3.tar.gz
sudo R CMD INSTALL --configure-args='--with-mysql-inc=/usr/include/mysql' --configure-args='--with-mysql-lib=/usr/lib64/mysql' /home/user/Downloads/RMySQL_0.9-3.tar.gz