Skip to content

Instantly share code, notes, and snippets.

@rabbleNaut
rabbleNaut / reName.py
Created March 20, 2014 12:38
Simple 1-liner that renames all texts files in a folder ending with ".sf1" to ".txt"
import os
# This will rename all files ending with ".sf1" to ".txt"
[os.rename(f, f.replace('.sf1', '.txt')) for f in os.listdir('') if f.endswith('.sf1')]
@rabbleNaut
rabbleNaut / rePlace.py
Last active August 29, 2015 13:57
Used for preparing 2010 Census Summary tables for Texas.
# For each line in the text file, remove the first 4 columns
f1 = open('tx000382010.txt', 'r')
f2 = open('tx000382010mod.txt', 'w')
for line in f1:
f2.write(line.replace('SF1ST,TX,000,38,', ''))
f1.close()
f2.close()
@rabbleNaut
rabbleNaut / DropLastFields.py
Last active August 29, 2015 13:57
Used for editing a .csv file that was too large for Excel or Access.
import csv
#removes columns starting at remove_from up to- but *not including* - remove_to
remove_from = 239
remove_to = 260
fp_in = open("tx000452010.txt", "rb")
fp_out = open("tx000452010_PT1.txt", "wb")
reader = csv.reader(fp_in, delimiter=",")
@rabbleNaut
rabbleNaut / DropMidFields.py
Created March 20, 2014 12:46
Used for editing a .csv file that was too large for Excel or Access.
import csv
# Removes columns starting at remove_from up to- but *not including* - remove_to
# In this example, all columns are removed except for the first 5 and last 21
remove_from = 5
remove_to = 239
fp_in = open("tx000452010.txt", "rb")
@rabbleNaut
rabbleNaut / batchFieldUpdate.py
Last active August 29, 2015 13:57
Uses Arcpy to iterate through all feature classes in a feature dataset to create and populate new fields.
'''
batchFieldUpdate.py
For each feature class in EMST_Districts on Comanche.sde, do the following:
1 - Adds new field "Feature_Type"
2 - Calculates field
if type = null add "vegetation"
'''
@rabbleNaut
rabbleNaut / batchFieldDelete.py
Created March 20, 2014 13:04
Uses Arcpy to iterate through features in a featuredataset to delete unwanted fields.
'''
batchFieldDelete.py
Iterate through features in featuredataset to delete unwanted fields.
Delete fields:
1 - Area_MI
2 - DOT_Feature
3 - Area_MI
'''
@rabbleNaut
rabbleNaut / batchRename.py
Created March 20, 2014 13:05
Uses Arcpy to iterate through feature classes in a feature dataset and rename them.
import arcpy
from arcpy import *
env.workspace = r"C:\Users\RABBEY-C\RA_GIS\Projects\RA_EMST\Updated_Phase_Features.gdb\District_Unions"
fcList = arcpy.ListFeatureClasses()
#Renames featureclasses ending in "_Union" with ""
for fc in fcList:
@rabbleNaut
rabbleNaut / ClipLooper.py
Last active June 29, 2023 12:18
This was for a Scripting for GIS class project using Arcmap 10.1 and Model Builder
'''===============================
ClipLooper.py
The purpose of this script is to step through all 10 counties in the dataset and
clip each of the 3 features (Water Bodies, Streams, City Limits) to the counties border.
Script Arguments:
0 - Input County FC
1 - Input Water Bodies FC
2 - Input Streams FC
@rabbleNaut
rabbleNaut / DoForms_Downloader.py
Last active August 29, 2015 13:57
For use with ESRI model builder. Downloads images based on URLs, creates new fields, populates new fields with links to local images for reporting.
'''
DoForms_Downloader.py
v1.10
3/21/2014
This script will accomplish the following:
- Allows user to select featureclass generated from DoForms
@rabbleNaut
rabbleNaut / listAliases.py
Created April 10, 2014 14:46
This script will allow the user to select a feature class and output the features Name, Alias, and Type to a .csv file. To be used in ArcGIS Modelbuilder.
'''
===========================
listAliases.py
4/8/2014
This script will allow the user to select a feature class and output the features Name, Alias, and Type to a .csv file.
Arguments:
0 - Input Featureclass