Skip to content

Instantly share code, notes, and snippets.

View AlexArcPy's full-sized avatar

Alexey Tereshenkov AlexArcPy

View GitHub Profile
@AlexArcPy
AlexArcPy / 1-Constants.py
Created October 31, 2017 20:28
Python configuration options snippets
import os
WORKING_FOLDER = r'C:\Temp'
DATA_FILE = 'grafiti.csv'
with open(os.path.join(WORKING_FOLDER, DATA_FILE), 'rb') as f:
data = f.readlines()
print(data)
@AlexArcPy
AlexArcPy / read_lyrs.py
Created October 24, 2017 09:47
Python and comtypes: read map document layers and .lyr files with ArcObjects
from comtypes.client import GetModule, CreateObject
from snippets102 import GetStandaloneModules, InitStandalone
GetStandaloneModules()
InitStandalone()
esriCarto = GetModule(r"C:\Program Files (x86)\ArcGIS\Desktop10.4\com\esriCarto.olb")
layerFile = CreateObject(esriCarto.LayerFile,interface=esriCarto.ILayerFile)
lyrs = ["C:\GIS\Temp\lyrs_remote_sde_many_features\c123.lyr",
@AlexArcPy
AlexArcPy / move_bookmarks_mxd.py
Created October 24, 2017 09:44
Migrate ArcMap map document bookmarks between map documents (.mxd files)
from comtypes.client import GetModule, CreateObject
from snippets102 import GetStandaloneModules, InitStandalone
esriCarto = GetModule(r"C:\Program Files (x86)\ArcGIS\Desktop10.4\com\esriCarto.olb")
# First time through, need to import the “StandaloneModules”. Can comment out later.
#GetStandaloneModules()
#InitStandalone()
#----------------------------------------------------------------------
@AlexArcPy
AlexArcPy / py_concurrent1.py
Created October 20, 2017 10:05
Some snippets for Python concurrent multiprocessing
import os
import shutil
import time
from datetime import datetime
import arcpy
from concurrent import futures
HOME = r"C:\GIS\Temp\cc"
@AlexArcPy
AlexArcPy / call_arcmap_tool_comtypes.py
Last active October 23, 2017 08:04
Execute a tool on an ArcMap toolbar from Python script tool in open ArcMap session
#based on
#https://gis.stackexchange.com/questions/252950/how-can-i-call-a-net-c-tool-i-e-a-dll-file-from-a-model-workflow-or-a-py
import arcpy
import sys
from comtypes.client import GetModule, CreateObject
#path where snippets102.py module is stored
sys.path.append(r'C:\GIS\arcobjects')
import snippets102
@AlexArcPy
AlexArcPy / divide_polygons_into_areas.py
Created September 10, 2017 20:32
Dividing a polygon into a given number of equal areas with arcpy
import os
import sys
import arcpy
import pythonaddins
mxd = arcpy.mapping.MapDocument('CURRENT')
poly_lyr = arcpy.mapping.ListLayers(mxd.activeDataFrame, 'polys')[0]
num_out_polys = 10
@AlexArcPy
AlexArcPy / CopyParallelsExecuteClass.cs
Created September 6, 2017 09:17
Execute Copy Parallel on a selected line feature with the set offset value while in the editing session in ArcMap. Will create multiple features using the interval values set.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.Editor;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
@AlexArcPy
AlexArcPy / 1read_gdb_domains_ogr.py
Last active July 14, 2022 08:56
Read file geodatabase domains with OGR without using arcpy and find what fields have assigned domains
from __future__ import print_function
import json
import xml.etree.ElementTree as ET
import ogr
gdb_path = r'C:\GIS\data\Adv.gdb'
ds = ogr.Open(gdb_path)
res = ds.ExecuteSQL('select * from GDB_Items')
res.CommitTransaction()
@AlexArcPy
AlexArcPy / route2video.py
Created August 7, 2017 10:45
Generate a video street view stream based on a route polyline feature class using Mapillary API
'''
* generate a list of (x,y) for points along the route polyline feature class
with the set interval (using arcpy);
* save image from the API for each point trying to find the closest one as well
as the one looking at the next point in the route (using requests);
* merge the images into an output avi video file (using opencv);
'''
import os
import json
@AlexArcPy
AlexArcPy / gdb2elastic.py
Last active April 16, 2024 21:59
Convert geodatabase feature class features into GeoJSON strings for loading into elastic search database (bulk api)
'''
Convert file geodatabase feature class features into GeoJSON and
then construct text file for loading into elastic search bulk api
'''
import json
import arcpy
arcpy.env.overwriteOutput = True
#create a geojson file