Skip to content

Instantly share code, notes, and snippets.

@rossbernet
Last active March 6, 2017 18:15
Show Gist options
  • Save rossbernet/f40754d3d7e91a67f2a410e69915c890 to your computer and use it in GitHub Desktop.
Save rossbernet/f40754d3d7e91a67f2a410e69915c890 to your computer and use it in GitHub Desktop.
import ee
ee.Initialize()
# Get a download URL for an image.
image1 = ee.Image('srtm90_v4')
path = image1.getDownloadUrl({
'scale': 30,
'crs': 'EPSG:4326',
'region': '[[-120, 35], [-119, 35], [-119, 34], [-120, 34]]'
})
print path

Local

  • Arithmetic operations (+, -, *, /, Abs, …)
  • Relational operators (>, <, …)
  • Boolean (true, false, if, then)
  • Statistic operations (Min, Max, Mean, Majority, …)
  • Trigonometric operations (Sine, Cosine, Tan, Arcsine, Arccosine, …)
  • Exponential and logarithmic operations (Sqr, sqrt, exp, exp2, …)
  • Reclassify

Focal

  • Terrain (slope, aspect)
  • Focal Operations
    • Define neighborhood size and shape

Zonal

  • Zonal Statistics

Global

  • Euclidean Distance
  • Cost Distance
  • Euclidean Allocation
  • Hydrology
  • Viewshed

Common operations I'd like to do

  • Clip
  • Set extent
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# map_algebra_test_python.py
# Created on: 2017-02-28 17:42:24.00000
# (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
# Local variables:
test_data = "\\\\FILESHARE\\users\\rbernet\\libya_data_ross\\test_data"
EucDist_test1 = "C:\\Users\\rbernet\\Documents\\ArcGIS\\Default.gdb\\EucDist_test1"
Output_direction_raster = ""
accled = "\\\\FILESHARE\\users\\rbernet\\libya_data_ross\\accled"
CostDis_accl1 = "C:\\Users\\rbernet\\Documents\\ArcGIS\\Default.gdb\\CostDis_accl1"
Output_backlink_raster = ""
FocalSt_test1 = "C:\\Users\\rbernet\\Documents\\ArcGIS\\Default.gdb\\FocalSt_test1"
Slope_test_d1 = "C:\\Users\\rbernet\\Documents\\ArcGIS\\Default.gdb\\Slope_test_d1"
rastercalc1 = "C:\\Users\\rbernet\\Documents\\ArcGIS\\Default.gdb\\rastercalc1"
CellSta_test1 = "C:\\Users\\rbernet\\Documents\\ArcGIS\\Default.gdb\\CellSta_test1"
ZonalSt_test1 = "C:\\Users\\rbernet\\Documents\\ArcGIS\\Default.gdb\\ZonalSt_test1"
Reclass_test1 = "C:\\Users\\rbernet\\Documents\\ArcGIS\\Default.gdb\\Reclass_test1"
# Process: Euclidean Distance
arcpy.gp.EucDistance_sa(test_data, EucDist_test1, "", "0.056420429134", Output_direction_raster)
# Process: Cost Distance
arcpy.gp.CostDistance_sa(accled, test_data, CostDis_accl1, "", Output_backlink_raster, "", "", "", "")
# Process: Focal Statistics
arcpy.gp.FocalStatistics_sa(test_data, FocalSt_test1, "Rectangle 3 3 CELL", "MAJORITY", "DATA")
# Process: Slope
arcpy.gp.Slope_sa(test_data, Slope_test_d1, "DEGREE", "1")
# Process: Raster Calculator
arcpy.gp.RasterCalculator_sa("\"%FocalSt_test1%\" + \"%Slope_test_d1%\"", rastercalc1)
# Process: Cell Statistics
arcpy.gp.CellStatistics_sa("\\\\FILESHARE\\users\\rbernet\\libya_data_ross\\test_data;\\\\FILESHARE\\users\\rbernet\\libya_data_ross\\accled", CellSta_test1, "MEAN", "DATA")
# Process: Zonal Statistics
arcpy.gp.ZonalStatistics_sa(test_data, "VALUE", accled, ZonalSt_test1, "SUM", "DATA")
# Process: Reclassify
arcpy.gp.Reclassify_sa(test_data, "VALUE", "1 2 1;2 4 2;4 6 3;6 8 4;8 10 5;10 12 6;12 15 7;15 17 8;17 20 9", Reclass_test1, "DATA")
@rossbernet
Copy link
Author

rossbernet commented Feb 28, 2017

image

modelbuilder representation for the arcpy script

each tool has a GUI as such:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment