Skip to content

Instantly share code, notes, and snippets.

View sshopov's full-sized avatar

Stoyan Shopov sshopov

View GitHub Profile
@sshopov
sshopov / arcpy_attribute_based_etl.py
Last active August 29, 2015 13:58
The Data Interoperability Extension for ArcGIS Desktop, also known as Safe FME, is great mainly thanks to its hunderds of transformers. However for simple use cases it's easier to perform such tasks in Python. The script below appends records from one feature class to another while applying transformers and mappings as defined in the config. Tag…
import sys
import os
import copy
import arcpy
def get_field_values(fc, field, where=""):
'''
@return: A list of the values for the given field in the given feature class
with the given optional where clause applied.
dict((section, dict(cfg_parser.items(section))) for section in cfg_parser.sections())
@sshopov
sshopov / clip_and_zip.py
Created March 12, 2014 06:05
Clip desired features from the current ArcMap map document, export them to a file geodatabase and zip it up when done. Tags: arcpy, arcgis, arcmap, python, clip, zip.
'''
1. Open ArcMap and add the desired feature dataset to it.
2. Zoom to the extent that you want to export.
3. Open the Python prompt.
4. Paste the code below into it and hit Enter.
5. Go to where out_fgdb points to, then copy the export_fgdb.gdb.zip file and send it out.
'''
import shutil
import os
@sshopov
sshopov / leaflet_add_locate_me_button.js
Created March 12, 2014 05:09
Adds a locate me button between the + and - zoom buttons. When clicked it zooms to the user's current location. Requires jquery, leaflet and font awesome CSS http://fortawesome.github.io/Font-Awesome/icons
$('.leaflet-control-zoom-in').after('<a onclick="map.locate({setView:true, zoomLevel:18})" href="#"><i class="fa fa-male"></i></a>');
@sshopov
sshopov / arcpy_list_toolbox_tools.py
Created March 12, 2014 04:19
Listing all tools for every toolbox in ArcGIS
import re
import arcpy
for toolbox in arcpy.ListToolboxes():
wildcard = re.search(r"\((\w+)\)", toolbox).group(1)
for tool in arcpy.ListTools("*_%s"%wildcard):
print toolbox, tool, arcpy.Usage(tool)