Skip to content

Instantly share code, notes, and snippets.

Alex Tereshenkov AlexArcPy

Block or report user

Report or block AlexArcPy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@AlexArcPy
AlexArcPy / drop_db_with_pattern.sh
Created May 28, 2019
Drop PostgreSQL database matching name pattern
View drop_db_with_pattern.sh
echo "Drop PostgreSQL database matching a pattern"
cd C:/Temp
sql_query="select 'drop database \"'||datname||'\";' from pg_database WHERE datistemplate = false and datname like 'operat%';"
echo $sql_query
PGPASSWORD=postgres psql -p 5432 -d postgres -U postgres -t -A -F"," -c "${sql_query}" > drop_dbs.sql
cat drop_dbs.sql | while read line
do
echo $line;
PGPASSWORD=postgres psql -p 5432 -d postgres -U postgres -t -A -F"," -c "${line}"
@AlexArcPy
AlexArcPy / ogrtools.sh
Created May 28, 2019
Using bash to run OGR command line tools
View ogrtools.sh
echo "Working directory: $PWD";
echo "List files in a given directory"
for file in C:/GISData/*; do
echo $file;
done
echo "Get basic info about all shapefiles in a given folder"
for file in C:/GISData/*; do
if [[ ${file: -4} == ".shp" ]]
View aggregate_flake8_results.py
# flake8 > C:/Temp/StyleGuide.csv
import os
os.chdir('C:/Temp')
import pandas as pd
for errors_file in ['StyleGuide1.csv', 'StyleGuide2.csv']:
df = pd.read_csv(errors_file, sep=':')
df.columns = ['FilePath', 'LineNo', 'ColumnNo', 'ErrorMessage']
@AlexArcPy
AlexArcPy / preferences
Created Jun 2, 2018
Wing IDE preferences to reuse between installations.
View preferences
# To be put into "C:\Users\alte\AppData\Roaming\Wing IDE 6\preferences"
[user-preferences]
cache.external-check-freq = 0.1
consoles.auto-clear = True
consoles.wrap-long-lines = True
debug.multi-process-debug-sub-processes = True
debug.pretty-print-in-shells = True
debug.prompt-to-restart-python-shell-debug = False
debug.show-breaks-moved-message = False
debug.wrap-debug-io = True
@AlexArcPy
AlexArcPy / heapq_merge.py
Created Apr 3, 2018
Demonstrating efficient use of heapq.merge when working with arcpy.da.SearchCursor structures
View heapq_merge.py
'''
Demonstrating efficient use of heapq.merge when working with
arcpy.da.SearchCursor structures. The heapq.merge function will
merge multiple sorted inputs into a single sorted output which
can be useful when iterating over multiple arcpy.da.SearchCursor
iterators.
'''
from pprint import pprint
import heapq
@AlexArcPy
AlexArcPy / pprint_table_arcpy.py
Created Mar 24, 2018
Printing pretty tables with Python in ArcGIS
View pprint_table_arcpy.py
# using the built-in Python modules
import arcpy
arcpy.env.workspace = r'C:\Program Files (x86)\ArcGIS\Desktop10.5\TemplateData\TemplateData.gdb'
fc = r'USA\cities'
data = ['CITY_FIPS', 'CITY_NAME', 'STATE_FIPS', 'STATE_NAME', 'POP1990']
feats = [f for f in arcpy.da.SearchCursor(fc, field_names=data)][:10]
arcpy.AddMessage(" ")
row_format = u"{:>20}" * (len(data))
arcpy.AddMessage(row_format.format(*data))
@AlexArcPy
AlexArcPy / MultipleRingBufferPostGIS.sql
Created Mar 23, 2018
Multiple Ring Buffer with PostGIS
View MultipleRingBufferPostGIS.sql
--using set returning function generate_series
--https://www.postgresql.org/docs/9.1/static/functions-srf.html
WITH buffer_values as (
SELECT * FROM generate_series(5, 20, 5) AS dist
)
SELECT
CAST(p.id AS INT), p.name, b.dist, ST_Buffer(p.geom, b.dist) AS Poly
FROM
nyc_subway_stations p
@AlexArcPy
AlexArcPy / MultipleRingBufferSS.sql
Created Mar 23, 2018
Multiple Ring Buffer with SQL Server
View MultipleRingBufferSS.sql
--simple list of values to generate buffers around
DECLARE @buffer_distances TABLE (dist int);
INSERT @buffer_distances(dist) VALUES (1), (2), (3);
SELECT
p.STATE_NAME, p.CITY_NAME, b.dist, p.Shape.STBuffer(b.dist) AS Poly
FROM
CITIES p
CROSS JOIN
@buffer_distances b
@AlexArcPy
AlexArcPy / python_startup.py
Created Mar 15, 2018
Python start up script for ArcGIS Desktop users
View python_startup.py
'''
Python start up file that supports both Python 2 and 3.
Helpful set of preimported modules and predefined
variables for ArcMap and ArcGIS Pro users.
'''
# pretty printing instead of regular print
# https://docs.python.org/2/library/pprint.html
from pprint import pprint
import os
You can’t perform that action at this time.