Skip to content

Instantly share code, notes, and snippets.

View filipkral's full-sized avatar

Filip Kral filipkral

View GitHub Profile
@filipkral
filipkral / importing_osgeo_to_pyscripter.py
Created December 11, 2015 01:46
Importing OSGeo4W osgeo Python package to Pyscripter on Windows
import sys, os
sys.path.insert(0, r'C:\OSGeo4W\apps\Python27\Lib\site-packages')
#sys.path.insert(0, r'C:\OSGeo4W\lib')
sys.path.insert(0, r'C:\OSGeo4W\bin')
#os.environ['PATH'] = os.environ['PATH'] + ';' + r'C:\OSGeo4W\lib'
os.environ['PATH'] = os.environ['PATH'] + ';' + r'C:\OSGeo4W\bin'
@filipkral
filipkral / read_and_write_spatialite.py
Created March 15, 2016 10:59
Read and Write Spatialite with Python
from osgeo import ogr, osr
def read_splt(db):
drvr = ogr.GetDriverByName('SQLite')
ds = drvr.Open(db, 0)
layer=ds.GetLayer('pts')
for feature in layer:
print(feature)
break
@filipkral
filipkral / logging_to_sqlite_with_multiprocessing.py
Created October 26, 2016 12:46
Logging to SQLite with multiprocessing in Python
import sqlite3
from contextlib import closing
import multiprocessing
def prepare_db(db, tbl, col):
sql = "CREATE TABLE {0} ({1} text);".format(tbl, col)
with closing(sqlite3.connect(db)) as cnn:
cursor = cnn.cursor()
cursor.execute('DROP TABLE IF EXISTS {0};'.format(tbl))
cursor.execute(sql)
@filipkral
filipkral / reduce_repo_size.sh
Last active October 10, 2017 19:05
Reduce repository size after you accidentally committed a large file.
# given that you accidentally added a large file to git branch feature/adding, then removed it in another commit, you can reduce the repo size by the following commands
# for more details and alternatives see https://confluence.atlassian.com/bitbucket/reduce-repository-size-321848262.html
git checkout develop
git merge --squash feature/adding
git branch -D feature/adding
#git reflog expire --expire=now --all
git gc --prune=now
git commit -m "Merged"
@filipkral
filipkral / ogr2ogr_shp_to_pg.sh
Created January 6, 2025 08:30
Import Polygon ESRI Shapefile to PostgreSQL database using ogr2ogr
ogr2ogr -f "PostgreSQL" -a_srs "EPSG:4326" -lco SCHEMA=<schema> PG:"host=<ip or hostname> user=<user> password=<password> dbname=<dbname>" -nlt MULTIPOLYGON -nln <table_name> <shapefile_name>.shp