Skip to content

Instantly share code, notes, and snippets.

View pdbartsch's full-sized avatar

Paul Bartsch pdbartsch

  • UC Santa Barbara
  • 93455
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pdbartsch
pdbartsch / List Comprehension 2023.ipynb
Last active February 26, 2024 02:47
Learn Python - List Comprehension
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pdbartsch
pdbartsch / sync_movies.bat
Created February 17, 2023 23:32
Simple Windows batch file to backup our movies
@echo OFF
set source_folder=M:\Movies
set target_folder=G:\Movies
echo Syncing Movies from source to target
robocopy %source_folder% %target_folder% /s /xc /z /ETA /log:"G:\sync.log"
echo Syncing Movies from target to source
robocopy %target_folder% %source_folder% /s /xc /z /ETA /log:"G:\sync.log"

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 March 16, 2021 13:52
lightly modified example sketch to write to feed within group on Adafruit.io
// 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 March 15, 2019 22:36
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
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
# 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 March 6, 2019 23:09
ArcGIS Data driven pages export to Google Drive file sync
# 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
# expression:
sqft_to_acres(!Shape_Area!)
# code block:
def sqft_to_acres(area):
return round((area / 43560),2)
# expression:
abbreviate(!SciName!)
# code block:
def abbreviate(x):
words = x.split()
letters = [word[:2] for word in words]
return "".join(letters)