Skip to content

Instantly share code, notes, and snippets.

View alexfriant's full-sized avatar

Alex alexfriant

View GitHub Profile
@alexfriant
alexfriant / set_min_scales.py
Last active July 4, 2023 23:03
set the minimum scale values for all layers in an mxd that don't have minimum scale values already set (the don't show out-beyond scale)
#################################################################################
#
# Requirements: You'll need ArcGIS Desktop 10.1 or higher with Python 2.7
#
# If you are publishing an MXD as a map service you might get a warning from
# the Analyze option that some number of layers "draws at all scale ranges".
#
# This script sets all the layers in the MXD you have open to a minimum scale
# value of your choosing IF a layer's value is not set (indicated by being 0.0).
#
@alexfriant
alexfriant / list_min_scales.py
Last active November 13, 2020 19:40
list the minimum scale values for all layers in an mxd (the don't show out-beyond scale)
#################################################################################
#
# Requirements: You'll need ArcGIS Desktop 10.1 or higher with Python 2.7
#
# If you are publishing an MXD as a map service you might get a warning from
# the Analyze option that some number of layers "draws at all scale ranges".
#
# This script lists all the layers in the MXD you have open and what their
# minimum scale is set at, if at all. Those with '0.0' values have no value set.
#
@alexfriant
alexfriant / list_fields.py
Last active May 17, 2018 16:37 — forked from tyler-austin/arcpy_field_names.py
generate a list of field names for a feature class, with datatype and length
import arcpy, os
fc = os.path.join(r"path",r"to",r"your",r"featureclass")
field_list = [[field.name,field.type,str(field.length)] for field in arcpy.ListFields(fc)]
for field in field_list:
print(','.join(field))
@alexfriant
alexfriant / patternEyes.py
Last active August 31, 2022 21:21
This Python script will provide a summary of alphanumeric patterns which exist in a list of values
#####################################################################################
#
# Requirements: You'll need Python 3.5.1 or higher to run this
#
# This script will provide you a basic understanding of the alphanumeric patterns
# which exist in a list. You might get this list from a SQL query or something like
# that.
#
# INPUT: Give this script a file that has a single column of ID type strings.
# EXAMPLE (from command line):
@alexfriant
alexfriant / remove_gp_history_geodatabase.py
Last active August 30, 2017 22:53
Give this script a geodatabase (Personal, File, or SDE connection) and it will remove the "Geoprocssing History" contents from the Metadata in every Feature Class inside the geodatabase.
#################################################################################
#
# Requirements: You'll need ArcGIS Desktop 10.1 or higher with Python 2.7
#
# Give this script a geodatabase (Personal, File, or SDE connection) and it will
# remove the "Geoprocssing History" contents from the Metadata in every Feature
# Class inside the geodatabase.
#
# Before you attempt to use/run this script, make sure you have read the section
# near the top called "MODIFIABLE VARIABLES HERE".
@alexfriant
alexfriant / gdb_get_editor_tracking_statuses.py
Last active August 4, 2017 23:03
Give this script an entire Geodatabase and it reports a list of it's feature classes and whether or not Editor Tracking is enabled.
###############################################################################
#
# Requirements: You'll need ArcGIS Desktop 10.1 or higher with Python 2.7+
# Use as a ArcToolbox Script Tool. Add the parameters as needed.
#
# Give this script an entire Geodatabase and it reports a list of its feature
# classes and whether or not Editor Tracking is enabled.
#
# The output is useful for managing Editor Tracking for a large number of
# feature classes.
@alexfriant
alexfriant / extract_attachments.py
Created April 3, 2016 01:44
Extract attachments from ArcGIS file geodatabase
#############################################################################
# Requirements: ArcGIS 10.0 or higher, Python 2.7 or higher
#
# Description: Give this script an attachment table in a file geodatabase,
# and it will extract all the files and place them into the
# folder you designate.
#
# Note: Since attachments can have the same file name (i.e. Image00001.jpg)
# this script appends the attachment id to the file name so that every
# file is uniquely named in the folder you designate.
@alexfriant
alexfriant / ArcGISPermanentOneToOneJoin.py
Last active November 16, 2022 17:43 — forked from nickrsan/ArcGISPermanentOneToOneJoin.py
Provides a way to permanently attach a field to another table, as in a one to one join, but without performing a join then exporting a new dataset. Operates in place by creating a new field on the existing dataset.
import arcpy
def permanent_join(target_table, target_attribute, source_table, source_attribute, attribute_to_attach, rename_attribute=None):
"""
Attaches a field to a dataset in place in ArcGIS - instead of the alternative of doing an actual join and then saving out a new dataset
Only works as a one to one join.
:param target_table: the table to attach the joined attribute to
:param target_attribute: the attribute in the table to base the join on
:param source_table: the table containing the attribute to join
:param source_attribute: the attribute in table2 to base the join on
@alexfriant
alexfriant / change_image_sizes.py
Last active March 7, 2016 17:11
Modify image sizes for all images in a folder
from PIL import Image
import glob, os
size = 800, 600
for infile in glob.glob("c:/myphotos/*.jpg"):
file, ext = os.path.splitext(infile)
im = Image.open(infile)
im.thumbnail(size, Image.ANTIALIAS)
im.save(file + ".jpg", "JPEG")
@alexfriant
alexfriant / gdb_feature_counts_report.py
Last active December 7, 2016 00:04
Give this script an entire Geodatabase and it reports the number of features in each feature class to a CSV file
###############################################################################
#
# Requirements: You'll need ArcGIS Desktop 10.1 or higher with Python 2.7+
# Use as a ArcToolbox Script Tool. Add the parameters as needed.
#
# Give this script an entire Geodatabase and it reports the number of
# attachments in attachment table and features in each feature class.
#
# The output is useful for comparing FC counts between multiple
# identical GDBs.