Skip to content

Instantly share code, notes, and snippets.

View thomas-maschler's full-sized avatar

Thomas Maschler thomas-maschler

View GitHub Profile
@thomas-maschler
thomas-maschler / my_pyspark.py
Last active November 16, 2016 16:13
Basic pyspark program
from pyspark.sql import SparkSession
spark = SparkSession\
.builder\
.appName("MyPySpark")\
.getOrCreate()
sc = spark.sparkContext
my_file = sc.textFile("s3n://path/to/file")
import numpy as np
from math import pi, sqrt
def get_area(lat: float, d_lat: float, d_lng: float) -> float:
"""
Calculate geodesic area for lat/lng pixels using WGS 1984 as spatial reference.
Pixel area for a fix pixel width and hight various with latitude.
Pixels close to the equator have a larger areas. Area decreases towards the poles.
Arguments:
@thomas-maschler
thomas-maschler / harvest_feature_service.py
Last active September 19, 2017 18:11
Helper function to harvest all records of an ArcGIS feature service
import arcpy
import urllib
import json
def harvest_feature_service(baseURL, whereClause="", fields="*", token="", messages=None):
"""
Return all records from a feature service as a feature set
:param baseURL: The base URL of the feature service, including the layer ID
:param whereClause: SQL where clause (optional)
# coding=utf-8
import arcpy
arcpy.env.workspace = r"Database Servers\WRICWLT111900_SQLEXPRESS.gds\cmr_forest_atlas (VERSION:dbo.DEFAULT)"
desc = arcpy.Describe(arcpy.env.workspace)
print desc.workspaceType
subtypes = {"9100100": "Loi",
@thomas-maschler
thomas-maschler / update_agol_metadata.py
Last active July 18, 2018 20:57
Update ArcGIS online metadata
import requests
import json
def request_token(user, password):
d = {"username": user,
"password": password,
"referer":"http://www.arcgis.com",
"f": "json"}
import arcpy
import numpy as np
import os
import gc
import sys
arcpy.env.overwriteOutput = True
def gf(scene, year, i):
input_folder = r'G:\UMD_Landsat_tiles\%i' % year
@thomas-maschler
thomas-maschler / fire_updates.py
Created November 3, 2014 20:50
Download Nasa Global 24h fire alerts and process file line by line
import os
import urllib
import csv
url = 'https://firms.modaps.eosdis.nasa.gov/active_fire/text/Global_24h.csv'
file_path = 'path_where_you_what_to_save_file'
urllib.urlretrieve(url, file_path)