This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
projected_fc = "joined" | |
new_field = "nearby_FLOC" | |
floc_id_field = "FLOC_ID" | |
# Add a new field | |
arcpy.management.AddField(projected_fc, new_field, "TEXT") | |
# Step 1: Create a dictionary to map OBJECTID to FLOC_ID | |
floc_id_dict = {} | |
with arcpy.da.SearchCursor(projected_fc, ["OBJECTID", floc_id_field]) as search_cursor: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def validate_and_calculate_field(layer, field, expression): | |
# Validate field exists | |
fields = [f.name for f in arcpy.ListFields(layer)] | |
if field not in fields: | |
raise ValueError(f"Field {field} does not exist in layer") | |
# Validate expression fields exist | |
def get_fields_from_expression(expression): | |
matches = re.findall(r"!\w+!", expression) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from calendar import monthrange, day_name | |
from datetime import datetime, date | |
def is_saturday(d): | |
return day_name[d.weekday()] == "Saturday" | |
def is_current_month(d): | |
return (d.year, d.month) == (datetime.now().year, datetime.now().month) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arcpy | |
fc1 = 'buildings' | |
fc2 = 'buildings_1' | |
fields1 = ['osm_id', 'type'] | |
fields2 = ['osm_id', 'test'] | |
libraries = [] | |
# loop through each row in fc1 and add the osm_id to the libraries list | |
with arcpy.da.SearchCursor(fc1, fields1) as search_cursor: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
layer = 'grid' # if running this script outside of ArcGIS, this should be a full path to a feature class, not a layer name | |
fields = ['ID'] # this is field which matches the .tif filename | |
tif_folder = r'c:\my_tifs' | |
out_folder = r'c:\output' | |
with arcpy.da.SearchCursor(layer, fields) as cursor: | |
for r in cursor: # for each row in the layer: | |
print(r[0]) # print the ID | |
tif_file = os.path.join(tif_folder,r[0]+'.tif') # get the path to the matching .tif file (c:\my_tifs\01234.tif) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# blinky vs blinky_gap | |
# inspired by https://learn.adafruit.com/sipping-power-with-neopixels?view=all | |
import time | |
from adafruit_circuitplayground import cp | |
cp.pixels.brightness = .004 | |
def blinky(color,t=1): | |
t = t/10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get a random line from the Zen of Python without a print (preferably for a colorful cow to chant!) | |
# Replace stdout by an anonymous class that returns nothing on write() | |
import sys | |
stdout = sys.stdout | |
sys.stdout = type('BlackHole', (), {'write': (lambda self, string: '')})() | |
# This import's output has now been supressed | |
import this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
strings = ['abc@1@xyz','abc@2@xyz','abc@789@xyz','abc@defghijklmno@xyz'] | |
for text in strings: | |
regextest = re.sub("@.*@",str(strings.index(text)),text) # .* means zero or more of any character | |
print regextest | |
'''expected output | |
abc0xyz | |
abc1xyz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------------------------- | |
# Title: Remove all fedlands layers | |
# Purpose: Remove all fedlands from MXDs. This script takes an input | |
# directory and walks through it, finding all MXDs and searching | |
# for fedlands layers | |
# | |
# Author: Esri Support | |
# Based on: https://github.com/Esri/developer-support/tree/master/python/arcpy-python/remove-all-basemaps-batch | |
# | |
# Created: 10/31/2017 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob, os | |
def batchfile(script_folder, batchfile_folder, pyexe): | |
os.chdir(script_folder) | |
for file in glob.glob("*.py"): | |
script = os.path.splitext(file)[0] | |
batch = batchfile_folder+script+".bat" | |
with open(batch, 'w+') as f: | |
print batch | |
f.write("echo executing with "+pyexe+"\n") |
NewerOlder