Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul Bartsch pdbartsch

  • UC Santa Barbara
View GitHub Profile
View README.md

Overwrite many ArcGIS Web Layers using many maps in a single esri Project file

Step 1: Publish a bunch of web layers to ArcGIS Online or another portal using ArcGIS Pro > Share > Web Layer

Step 2: Become overwhelmed by keeping your data on ArcGIS Online in sync with your local esri maps

Step 3: Automate it

A few notes:

  • This little script asks for user input to choose between two office locations and then update the path to the esri project file
  • Uses stored credentials to keep my ArcGIS Online password separate from this code
  • It helps to have the web feature name match the name of your local map
@pdbartsch
pdbartsch / 8266_adafruitio_00_publish.ino
Created Mar 16, 2021
lightly modified example sketch to write to feed within group on Adafruit.io
View 8266_adafruitio_00_publish.ino
// Adafruit IO Publish Example
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016 Adafruit Industries
// Licensed under the MIT license.
//
@pdbartsch
pdbartsch / arcmap_example_update_source_folder.py
Last active Mar 15, 2019
Simple example of updating a single mxd file that has missing sources when data is moved to a new folder. For more information see: http://desktop.arcgis.com/en/arcmap/10.6/analyze/arcpy-mapping/updatingandfixingdatasources.htm
View arcmap_example_update_source_folder.py
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Projects\arc_examples\broken_sources_example.mxd")
original_directory = r"C:\Projects\arc_examples"
new_directory = r"C:\Projects\arc_examples\data_moved_to_this_folder"
mxd.findAndReplaceWorkspacePaths(original_directory, new_directory)
mxd.saveACopy(r"C:\Projects\arc_examples\data_moved_to_this_folder\new_map.mxd")
del mxd
View fieldcalc04.py
# expression:
lat_main(!size!)
# code block:
def lat_main(diameter):
if (diameter >= 8):
return "Main"
else:
return "Lateral"
@pdbartsch
pdbartsch / dd_pages_export.py
Created Mar 6, 2019
ArcGIS Data driven pages export to Google Drive file sync
View dd_pages_export.py
# Name: dd_pages_export.py - Data Driven Page(s) to PDF
# Description: exports either a single data Driven Page or all pages from a .mxd document to pdf(s). Replaces multiple previous scripts in favor of user input.
# Author: Paul Bartsch - updated December 2018
# Intent: for use at UCSB to keep hosted PDF atlas sheets up to date with GIS data and ArcGIS Online Services (see other documents for help keeping online services in sync.)
# Python 2 because this one is intended for use with ArcGIS Desktop maps that have not yet been imported to ArcGIS Pro
## IMPORTS
import arcpy
## CONSTANTS
View fieldcalc03.py
# expression:
sqft_to_acres(!Shape_Area!)
# code block:
def sqft_to_acres(area):
return round((area / 43560),2)
View fieldcalc02.py
# expression:
abbreviate(!SciName!)
# code block:
def abbreviate(x):
words = x.split()
letters = [word[:2] for word in words]
return "".join(letters)
View fieldcalc01.py
# find the minimum value across a list of fields:
# expression:
min([!field1!, !field2!, !field3!])
# find the maximum value across a list of fields:
# expression:
max([!field1!, !field2!, !field3!])
# find the sum of all values from a list of fields:
# expression:
View 12-list-ends.py
'''
Write a program that takes a list of numbers (for example, a = [5, 10, 15, 20, 25]) and makes a
new list of only the first and last elements of the given list.
'''
import random
a = random.sample(range(1, 100), 15)
def listends(a):
print('',a,'\n',[a for a in [a[0], a[-1]]])
View 11-Check-Primality.py
invar = int(input("Please enter an integer to find out whether it's prime or not: "))
def prime(n):
divisors = [ x for x in range(1,n+1) if n % x == 0]
if len(divisors) == 2:
print('prime')
else:
print('not prime')
prime(invar)