Skip to content

Instantly share code, notes, and snippets.

View AlexArcPy's full-sized avatar

Alexey Tereshenkov AlexArcPy

View GitHub Profile
@AlexArcPy
AlexArcPy / arcpy_chain_cursors.ipynb
Created January 13, 2017 14:20
Using itertools module within arcpy workflows
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@AlexArcPy
AlexArcPy / python_bisect.ipynb
Created January 13, 2017 14:22
Using Python bisect module to group list values
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@AlexArcPy
AlexArcPy / call_charp_from_Python.py
Last active March 26, 2021 22:21
Access C# code from Python
import clr
import sys
print sys.version
sys.path.append(r"C:\GIS")
lb = clr.AddReference('SampleClassLibrary') #add .dll file
from SampleClassLibrary import Calculator
c = Calculator()
print "Result is", c.DoSum(1,2)
@AlexArcPy
AlexArcPy / rotate_pdf_python.py
Created February 2, 2017 19:58
Rotate pages in a pdf using Python
import PyPDF2
pdf_in = open('doc.pdf', 'rb')
pdf_reader = PyPDF2.PdfFileReader(pdf_in)
pdf_writer = PyPDF2.PdfFileWriter()
for pagenum in range(pdf_reader.numPages):
page = pdf_reader.getPage(pagenum)
print pagenum
if pagenum in [1,4,5]:
@AlexArcPy
AlexArcPy / update_geodatabase_field_alias.py
Last active August 6, 2021 14:39
Update field aliases of map layers within an ArcGIS map document file and geodatabase feature class fields
## -*- coding: UTF-8 -*-
import os
from collections import defaultdict
from comtypes.client import GetModule, CreateObject
from snippets102 import GetStandaloneModules, InitStandalone
GetStandaloneModules()
InitStandalone()
@AlexArcPy
AlexArcPy / get_points_along_line.py
Created March 21, 2017 07:50
Get points along the line feature (arcpy)
import arcpy
def get_points_along_line(input_line_feature, interval, number_of_points):
'''given a single polyline feature shape will return a list of point features
positioned along the line at set intervals'''
out_pnts = []
intervals_list = []
if number_of_points:
interval = input_line_feature.length / number_of_points
@AlexArcPy
AlexArcPy / apply_watermark.py
Created April 1, 2017 08:58
Export a pdf file from ArcMap map document (.mxd) and add a URL link to the source map document path
import PyPDF2
watermark_pdf_path = r"C:\GIS\Temp\pdfs\MapWatermark.pdf"
pdf_path = r"C:\GIS\Temp\pdfs\MapImage.pdf"
map_pdf = open(pdf_path, 'rb')
watermark_pdf = open(watermark_pdf_path, 'rb')
pdfReader = PyPDF2.PdfFileReader(map_pdf)
pdfWatermarkReader = PyPDF2.PdfFileReader(watermark_pdf)
@AlexArcPy
AlexArcPy / mxd_map_grid_show_hide.py
Created April 14, 2017 16:11
Show or hide ArcMap map document (.mxd) map grids using comtypes and ArcObjects
'''
This code shows how to hide/show map grids in a map document before exporting the map.
This can be handy when you have multiple grids with different grid cell size and you
want to be able to control at what map scales each of the map grids should be visible.
As this is not exposed via arcpy, you have to use ArcObjects.
This code assumes there are two grids for the data frame with the name `small` and `large`
'''
import sys
from comtypes.client import GetModule, CreateObject
@AlexArcPy
AlexArcPy / edit_scale_bar_arcobjects.py
Created April 17, 2017 07:54
Modify properties of scale bar element in ArcMap map document layout using Python and ArcObjects
'''
This code provides access to a map document layout MapsurroundElement such as scale bar.
In order to use this code, you would need to have a map document with a pre-created
scale bar.
'''
import sys
from comtypes.client import GetModule, CreateObject
from snippets102 import GetStandaloneModules, InitStandalone
@AlexArcPy
AlexArcPy / create_convex_hull.py
Created April 18, 2017 10:53
ArcPy: Create Convex Hull polygons from features of various geometry type optionally grouping input features
import arcpy
arcpy.env.overwriteOutput = True
#----------------------------------------------------------------------
def create_convex_hull(in_fc, grouping_field=None):
"""
generate convex hull features optionally grouping input features;
if no grouping_field specified, a single Convex Hull will be generated
for all input features
"""