Skip to content

Instantly share code, notes, and snippets.

View astrong19's full-sized avatar

Asa Strong astrong19

View GitHub Profile
import json
from shapely.geometry import shape
aoi_fpath = r"field.geojson" #path to geojson aoi
with open(aoi_fpath) as f:
geom = json.load(f)
geom_shape = shape(geom)
def get_overlap(image, aoi):
import fiona
import geojson
import pyproj
import requests
import json
import os
import glob
import time
from functools import partial
from requests import Session
@astrong19
astrong19 / get_agol_token_api.py
Last active April 26, 2018 17:13
Get a token and expiration date with the ArcGIS API for Python
from arcgis.gis import GIS
def authenticate(user, password):
if not user and password:
raise ValueError("username and password required")
gis = GIS("https://arcgis.com", user, password)
con = gis._con
@astrong19
astrong19 / get_agol_token.py
Last active April 26, 2018 16:43
Get AGOL token with Arc Rest
import requests
import json
import datetime
def request_token(user, password):
'''
:param agol_creds: the name of the local file with the user/pass
:return: a dictionary with folder_name, folder_id, item_name, item_id
'''
if not user and password:
@astrong19
astrong19 / update_metadata.py
Last active April 25, 2018 23:00
Testing metadata updates to AGOL items with python API
from arcgis.gis import GIS
from getpass import getpass
#authenticate (replace second argument with your agol username)
gis = GIS("https://arcgis.com", "astrong_pnw", getpass())
#find item (replace item string with the unique item id of your AGOL feature
item = gis.content.get('de97aa2fc02f45a8ba61ee9cab4aad2e')
#define metadata in dict
@astrong19
astrong19 / sync_agol_with_python.ipynb
Created March 17, 2018 18:49
For jupyter notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import arcpy
arcpy.env.workspace = r"C:\Users\asa7362\Desktop\ArcGIS\ProProjects\PNW_Portal.gdb" #path to your sde
arcpy.Rename_management("test", "test2") #param1 = current name, #param2 = desired name
@astrong19
astrong19 / Widget.js
Last active March 7, 2018 22:31
Quick adjustment to Custom Heat Map Widget for WAB
//source: https://github.com/AdriSolid/WAB-Custom-Widgets/tree/master/HeatMap
define(['dojo/_base/declare',
'jimu/BaseWidget',
'dojo/on',
'dijit/form/Select',
'dijit/form/Button',
'dijit/form/CheckBox',
'./idWebMapLayers',
'esri/layers/FeatureLayer',
'esri/renderers/HeatmapRenderer',
from arcgis.gis import GIS
username = None #specify your AGOL username here (string)
password = None #specify your AGOL password here (string)
item_id = None #specify the Item ID of the Application you want to copy here (string)
portal_url = None #(optional) specify Portal URL
folder = None #(optional) specify folder you want item copied to
#authenticate
if portal_url:
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"#Get Set Up\n",
"from arcgis.gis import GIS\n",