Skip to content

Instantly share code, notes, and snippets.

View mu88's full-sized avatar

Mirko mu88

View GitHub Profile
@mu88
mu88 / CreateDevelopBranches.ps1
Last active March 1, 2018 16:37
Git - Create develop-Branch in several Git repositories
Clear-Host
$ErrorActionPreference = 'Stop'
# get all existing Git repositories => For this, C:\Git get filtered for all folders ending on 'v' and a digit because only those folders are accesibble via Git-Server
$Git_Repos = Get-ChildItem C:\Git | ?{ $_.PSIsContainer } | Where-Object {$_.Name -match '\w*v\d\b'} | Select-Object Name
$Git_Server = 'https://www.MyGitServer.com'
$Git_Branch = 'develop'
$Git_LocalCloneDirectory = 'C:\temp'
@mu88
mu88 / SetDefaultBranch.ps1
Last active March 1, 2018 16:35
Git - Set default branch
Clear-Host
$ErrorActionPreference = 'Stop'
$Git_Branch = 'develop'
$Git_Base_Directory = 'C:\Git'
# get all existing Git repositories => For this, L:\src get filtered for all folders ending on 'v' and a digit because only those folders are accesibble via Git-Server
$Git_Repos = Get-ChildItem $Git_Base_Directory | ?{ $_.PSIsContainer } | Where-Object {$_.Name -match '\w*v\d\b'} | Select-Object Name
ForEach($Git_Repo in $Git_Repos)
@mu88
mu88 / ListOcls.py
Created March 1, 2018 16:09
ArcPy - List all Object Classes of all File Geodatabases within a given directory
import arcpy, codecs, csv, os, shutil
os.system("cls")
origFgdbLocation = r"\\Server\Share"
origFgdbNames = ["A", "B", "C"]
csvFilePath = r"C:\temp\members.csv"
elements = []
for fgdbName in origFgdbNames:
@mu88
mu88 / GetLayerDatasources.py
Created March 1, 2018 16:10
ArcPy - Get Layer Data Sources of MXDs
import arcpy, codecs, csv, os
mxd_folder = "C:\\temp\\MXDs"
output = "C:\\temp\\dataSources.csv"
f = codecs.open(output, "w", encoding="utf-8")
f.write("MXD;Layer;Data Source\n")
for file in os.listdir(mxd_folder):
if file.endswith(".mxd"):
@mu88
mu88 / FindDuplicateFieldAliases.py
Created March 1, 2018 16:13
ArcPy - Find duplicate Field Aliases within MXD
import arcpy, os
os.system('cls')
mxd = arcpy.mapping.MapDocument(r"\\Server\Share\MyMap.mxd")
tolerateFieldWhenDisabled = True
for layer in arcpy.mapping.ListLayers(mxd):
print "Checking Layer '" + layer.name + "'"
@mu88
mu88 / DetectLayerJoins.py
Created March 1, 2018 16:15
ArcPy - Detect Layers with Joins in MXD
import arcpy, codecs, csv, os
mxd_folder = "C:\\temp\\MXD"
output = "C:\\temp\\results.csv"
f = codecs.open(output, "w", encoding="utf-8")
f.write("MXD;Layer;Result\n")
for file in os.listdir(mxd_folder):
if file.endswith(".mxd"):
@mu88
mu88 / CreateGisServerConnectionFiles.py
Created March 1, 2018 16:16
ArcPy - Create ArcGIS Server Connection File
import arcpy
servers = ['myServer1', 'myServer2', 'myServer3']
outdir = 'GIS Servers' # using 'GIS Servers' results in creating the AGS files in the 'GIS Servers' section of ArcCatalog (equivalent to '%appdata%\ESRI\Desktop10.5\ArcCatalog')
username = ''
password = ''
for server in servers:
out_name = server + ' (admin).ags'
server_url = 'https://' + server + '/arcgis/admin'
@mu88
mu88 / Compare.py
Created March 1, 2018 16:19
ArcPy - Compare two File Geodatabases
import arcpy, logging, math, os, shutil, sys
def GetCharDigitSum(s):
if s is None:
return 0
sum = 0
for c in s:
sum = sum + ord(c)
@mu88
mu88 / CloneAndTransformFGDB.py
Created March 1, 2018 16:27
ArcPy - Create an empty clone of a File Geodatabase (with all Feature Classes and Tables) and set a new Coordinate Reference System
import arcpy, os, shutil
os.system("cls")
origFgdbLocation = r"\\Server\Share"
origFgdbNames = ["myFileGeodatabase"] # DON'T append the suffix ".gdb"
newFgdbLocation = r"\\OtherServer\OtherShare"
resolution = "0.00005 Meters"
tolerance = "0.0001 Meters"
newCrs = arcpy.SpatialReference(2056) # EPSG code of "CH1903+ LV95"
@mu88
mu88 / ListRaster.py
Created March 1, 2018 16:28
ArcPy - List all Rasters within File Geodatabase
import arcpy, codecs, csv, os, shutil
os.system("cls")
origFgdbLocation = r"\\Server\Share"
origFgdbNames = ["MyFileGeodatabase1", "MyFileGeodatabase2", "MyFileGeodatabase3"]
csvFilePath = r"C:\temp\members.csv"
elements = []
for fgdbName in origFgdbNames: