Skip to content

Instantly share code, notes, and snippets.

View mfurlend's full-sized avatar

Mikhail Furlender mfurlend

  • WeatherBELL Analytics
  • New York, NY
View GitHub Profile
@mfurlend
mfurlend / move children to parent
Created January 28, 2014 16:07
recursive move all files in child folders to parent folder and delete child folder
#!/bin/bash
for dir in *; do
if test -d "$dir"; then
(
cd "$dir";
find . -maxdepth 1 -type f -print0 | xargs -0 -I {} mv {} ../{}
);
rmdir "$dir";
fi;
@mfurlend
mfurlend / group-write-for-new-files.txt
Created January 28, 2014 16:07
Set group to "dev" and turn group write permissions on for all new files created within this directory. Uses ACL.
mount -o remount,acl / #mount / with acl turned on
chgrp dev /path/to/dir -R
chmod 7775 /path/to/dir -R
setfacl -d -m g:dev:rwX,o::- /path/to/dir #group write to dev for new files
@mfurlend
mfurlend / shp to geojson
Created January 28, 2014 16:08
convert shp to GeoJson
ogr2ogr -f "GeoJSON" E:\gitstore\public\res\shapes\ag_master_regions.json E:\master_regions\master_regions_SimplifyPolyg.shp
@mfurlend
mfurlend / topojson-to-geojson
Created January 28, 2014 16:08
convert topojson to geojson
geojson –o /home/mgleason/geo –precision 6 --id-property fips -- outcounties_topo.json
-o = output directory (filename is automatically chosen)
-precision = number of digits after decimal place to keep
--id-property = demote geometry id to specified feature property
@mfurlend
mfurlend / batch-topojson
Created January 28, 2014 16:08
batch geojson to topojson
for f in *.geojson; do echo $f | sed 's/.geojson//' ; done | xargs -I {} topojson {}.geojson -o topojson/{}.topojson --id-property STATE_ZONE
@mfurlend
mfurlend / gdal-from-source
Last active January 4, 2016 19:59
install gdal with python bindings
cd /usr/local/src
wget http://download.osgeo.org/gdal/gdal-1.9.0.tar.gz
tar xvfz gdal-1.9.0.tar.gz
cd gdal-1.9.0
./configure --with-python
# include --tag=LD in the LIBTOOL_LINK directive in the GDALmake.opt file.
make
@mfurlend
mfurlend / js-state-fullnames-to-abbrv
Created January 28, 2014 16:09
javascript state names to abbreviations
state_abbr = {
'Alabama' : 'AL' ,
'Alaska' : 'AK' ,
'America Samoa' : 'AS' ,
'Arizona' : 'AZ' ,
'Arkansas' : 'AR' ,
'California' : 'CA' ,
'Colorado' : 'CO' ,
'Connecticut' : 'CT' ,
'Delaware' : 'DE' ,
@mfurlend
mfurlend / set field value to layer name
Created January 28, 2014 16:09
For ever layer, set every attribute field's value to the base file name of the layer. Useful for later aggregating by field value.
import arcpy
from arcpy import env
env.workspace = "E:/master_regions"
files = arcpy.ListFiles("*.dbf")
for file in files:
rows = arcpy.UpdateCursor(file)
for row in rows:
row.NAME = file.split('.')[0]
rows.updateRow(row)
@mfurlend
mfurlend / gist:8670635
Created January 28, 2014 16:09
add field to each layer
import arcpy
from arcpy import env
env.workspace="E:\master_regions_unpacked"
files = arcpy.ListFiles("*.dbf")
for file in files:
arcpy.AddField_management(file, "CODE", "TEXT")
@mfurlend
mfurlend / $shapefile=>array(fieldNames)
Created January 28, 2014 16:09
arcGIS shape filename -> array of field names as PHP array
import arcpy
import json
from arcpy import env
env.workspace = "E:/master_regions_unpacked"
txtFile = open("E:/master_regions/regionArray","w")
txt = []
files = arcpy.ListFiles("*.dbf")
for file in files:
txt.append("'"+str(file).split(".")[0]+"'=>array(")