Skip to content

Instantly share code, notes, and snippets.

View amarinelli's full-sized avatar
😅

Adam Marinelli amarinelli

😅
View GitHub Profile
@amarinelli
amarinelli / check_ags_connection.py
Created October 23, 2014 17:56
Workaround to validate an AGS connection file
import arcpy
import os
outdir = r'C:\TEMP'
out_folder_path = outdir
out_name = 'test_connection.ags'
server_url = 'http://localhost:6080/arcgis/admin'
username = 'admin'
password = 'admin'
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--The viewport meta tag is used to improve the presentation and behavior of the samples
on iOS devices-->
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Create Map and add a dynamic layer</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css"/>
<style>
@amarinelli
amarinelli / legend_style.py
Created November 13, 2014 19:46
Set style of legend items to user style and tests 'Override default patch' property. Mxd.save() seems like the key here.
import arcpy
mxd = arcpy.mapping.MapDocument("./Legend.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
#Setup Legend
legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0]
styleItems = arcpy.mapping.ListStyleItems("USER_STYLE", "Legend Items")
for styleItem in styleItems:
if styleItem.itemName == "PATCH_Single":
@amarinelli
amarinelli / list_layer_mapservice.py
Created November 16, 2014 16:51
List the layers in an AGS map service using the REST endpoint
import urllib2
import json
content = urllib2.urlopen("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/layers?f=pjson").read()
service = json.loads(content)
for layer in service['layers']:
print layer['name'], ":", layer['type']
@amarinelli
amarinelli / consolidate_layers.py
Created January 9, 2015 22:30
This script using arcpy to consolidate all the feature layers in a map document into a single File GDB
import arcpy
import time
import os
mxd = arcpy.mapping.MapDocument(r'C:\<path>\<to>\<map>.mxd')
dfs = arcpy.mapping.ListDataFrames(mxd)
file_gdb = r'C:\<path>\<to>\<file>.gdb'
@amarinelli
amarinelli / IIFE.js
Created January 13, 2015 20:41
Sample JS template for writing an IIFE
// Code goes here
(function() {
var createWorker = function() {
var workCount = 0;
var task1 = function() {
workCount += 1;
@amarinelli
amarinelli / leaflet-geojson-esri.html
Last active August 29, 2015 14:17
Leaflet GeoJSON (esri): Leaflet AJAX // source http://jsbin.com/debolatopa
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=1024, user-scalable=no">
<style>
html { height: 100% }
body { height: 100%; margin: 0; padding: 0;}
#map{ height: 100% }
@amarinelli
amarinelli / item_details.py
Created March 25, 2015 16:31
Get a formatted JSON representation of an item's data hosted in ArcGIS Online
import json
import tortilla
class AGOL:
""" A class for administering an ArcGIS Online account"""
def __init__(self, in_username, in_password, expiration=60):
self.agol = tortilla.wrap('https://www.arcgis.com')
self.username = in_username
self.password = in_password
@amarinelli
amarinelli / agol_backup_utility.py
Created March 31, 2015 22:11
Python utility to backup (batch or single) hosted feature services in ArcGIS Online. Requires ArcGIS Desktop 10.2+
from __future__ import print_function
import time
import json
import os
import tortilla
from requests.packages import urllib3
import arcpy
@amarinelli
amarinelli / SearchCursor.py
Created October 23, 2015 17:18
Search Cursor (arcpy)
# from: http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-data-access/searchcursor-class.htm
import arcpy
fc = 'c:/data/base.gdb/well'
fields = ['WELL_ID', 'WELL_TYPE', 'SHAPE@XY']
# For each row print the WELL_ID and WELL_TYPE fields, and the
# the feature's x,y coordinates
with arcpy.da.SearchCursor(fc, fields) as cursor: