This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def some(): | |
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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 |
NewerOlder