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
-- Call function with the schema name | |
CREATE OR REPLACE FUNCTION rename_columns(_schema text) RETURNS VOID AS $func$ | |
DECLARE | |
rec RECORD; | |
table RECORD; | |
result RECORD; | |
sql TEXT := ''; | |
i INTEGER; | |
BEGIN |
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
SELECT pg_terminate_backend(pg_stat_activity.pid) | |
FROM pg_stat_activity | |
WHERE pg_stat_activity.datname = 'TARGET_DB' -- ← change this to your DB | |
AND pid <> pg_backend_pid(); |
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
# Directly modify file & create a backup | |
sed -i.bak '/pattern to match/d' ./input_file | |
# Directly modify file - no backup | |
sed -i '' '/pattern to match/d' ./infile |
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
WITH data AS | |
(SELECT column_to_test, | |
count(*) OVER (PARTITION BY column_to_test), other_columns_to_output | |
FROM schema.table ) | |
SELECT * | |
FROM data | |
WHERE count > 1 | |
ORDER BY column_to_test; |
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
DELETE | |
FROM schema.table a USING | |
(SELECT MIN(ctid) AS ctid, | |
duplicate_field | |
FROM schema.table | |
GROUP BY duplicate_field | |
HAVING COUNT(*) > 1) b | |
WHERE a.duplicate_field = b.duplicate_field | |
AND a.ctid <> b.ctid; |
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
from pathlib import Path | |
import pandas | |
import geopandas | |
folder = Path("/path/to/shapefile/folder") | |
shapefiles = folder.glob("shapefile_name_with_wildcards_*.shp") | |
gdf = pandas.concat([ | |
geopandas.read_file(shp) | |
for shp in shapefiles | |
]).pipe(geopandas.GeoDataFrame) |
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
# Remove all merged, closed branches from your local machine, leaving unmerged branches in place | |
git remote prune origin | |
git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | xargs git branch -d |
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
networkx | |
geopandas | |
pillow | |
matplotlib |
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
import pandas as pd | |
import geopandas as gpd | |
from shapely import wkt | |
import time | |
# Read pub points from CSV to a pandas dataframe | |
pubs = pd.read_csv('~/Documents/pub_points.csv', | |
header=None, names=['name', 'coordinates']) | |
# Parse the WKT coordinate format from PostGIS |
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
-- Snap the points to their closest lines, found in the subquery below | |
SELECT | |
point_id, | |
line_id, | |
ST_LINE_INTERPOLATE_POINT(line_geom, | |
ST_Line_Locate_Point(line_geom, point_geom)) AS snapped_points --Create the snapped points | |
FROM | |
--Subquery to find the closest line to each point (within a pre-defined raidus) | |
( |
OlderNewer