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 / 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)
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 / 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"}
# 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 / 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)
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 / 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 csv
import glob
import os
csv_path = r"D:\temp\fires_tsv\csv\*"
csv_files = glob.glob(csv_path)
tsv_path = r"D:\temp\fires_tsv\tsv"
if not os.path.exists(tsv_path):
os.mkdir(tsv_path)
@thomas-maschler
thomas-maschler / get_s3_bucket_content.py
Last active August 30, 2016 14:23
Get S3 bucket content
from boto.s3.connection import S3Connection
conn = S3Connection('AWS_Key','AWS_Secret')
bucket = conn.get_bucket('my_bucket')
for key in bucket.list():
print key.name.encode('utf-8')
@thomas-maschler
thomas-maschler / quart_geom.py
Last active September 19, 2016 14:00
Quarter Geometries
import arcpy
import os
import io
import sys
def quart_geom(geom):
"""
Quarter an arcpy geometry
:param geom: arcpy.geometry