Skip to content

Instantly share code, notes, and snippets.

View mdiener21's full-sized avatar

Michael Diener mdiener21

View GitHub Profile
@mdiener21
mdiener21 / gdbList2csv.py
Last active August 29, 2015 14:06
Write a list of personal geodatabase feature classes to a CSV file
import csv, arcpy
from arcpy import env
# set path using raw string to personal geodatabase
env.workspace = r"c:\users\mdiener\documents\mypersonalgeodatabase.gdb"
# create a python list of all datasets in personal geodatabase
datasetList = arcpy.ListDatasets('*','Feature')
# open a file for writing.
@mdiener21
mdiener21 / test_datum_shift_at2wgs84
Last active August 29, 2015 14:07
Python proj4 test Austrian datum shift to WGS84 from local coordinate system
from pyproj import Proj, transform
## my test coordinates, location is on the end of a peer on lake Wörthersee
## if the tranformation is wrong our point will be in the water
# these coorinates below I believe I can trust
# and are all TRUE for reference ( source KAGIS Atlas 17.10.2014)
# epsg proj coord
# epsg:31252 GK M31 70534.8 165013.4
@mdiener21
mdiener21 / django_api
Created December 19, 2014 11:42
run django api in one python file without starting server
import os
import django
from myapp import models
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
django.setup()
print models.MyModel.objects.get(pk=1)
@mdiener21
mdiener21 / deploy_win_server_iis.py
Last active August 29, 2015 14:15
Django deploy script on windows server IIS 8 when you are logged on
import os
import shutil
import distutils
import subprocess
base_source_path = r"E:\WEBGIS\source\trunk\mysite" # svn source location
base_deploy_path = r"C:\inetpub\mysite"
source_dir3 = r"C:\Python27\Lib\site-packages\django_admin_bootstrapped\static\admin"
@mdiener21
mdiener21 / install-apache-ant-win7
Last active January 29, 2016 00:23
install apache24 and ant windows 7
#download apache binaries: http://www.apachelounge.com/download/
#http://www.apachelounge.com/download/VC11/binaries/httpd-2.4.10-win32-VC11.zip
#unzip to a location you have permissions on your machine
#go in to folder to install apache and start it
cd c:\Apache24\conf
# edit file httpd.conf
# change all directory paths to cd c:\Apache24\
#install apache
@mdiener21
mdiener21 / base_models_views.py
Created August 26, 2016 07:50
Django base models and views
from django.db import models
class AppQueryset(models.QuerySet):
pass
class AppManager(models.Manager):
queryset_class = AppQuerySet
def get_queryset(self):
return self.queryset_class(self.model)
@mdiener21
mdiener21 / qgis-expression-coordinate-transform
Last active December 16, 2016 10:18
qgis expression to convert x-coordinate to epsg 3857 from epsg 4326
x-geom
substr(to_string(geom_to_wkt(transform( $geometry ,'EPSG:4326','EPSG:3857'))),7,16)
y-geom
substr(to_string(geom_to_wkt(transform( $geometry ,'EPSG:4326','EPSG:3857'))),25,16)
@mdiener21
mdiener21 / updateJsonb.sql
Last active January 17, 2017 13:38
update a jsonb postgresql field from columns data
update tableName set columnName = json_build_object('keyfieldname1',fieldname1,'keyfieldname2',fieldname2)
-- keyfieldname1 is any text name you give to the key
-- fieldname1 is an existing column name you have in your table
-- docs https://www.postgresql.org/docs/9.5/static/functions-json.html
@mdiener21
mdiener21 / csv2json.py
Created January 17, 2017 23:41
CSV to json using pandas with option records
import pandas as pd
df = pd.read_csv('..\data\hospitals.csv')
#print(df.to_json(orient='records'))
with open('..\data\hospitals.json', 'w') as outfile:
outfile.write(df.to_json(orient='records'))
@mdiener21
mdiener21 / set-pwd-postgres.sh
Created February 7, 2017 20:18
Set initial password for postgres database ubuntu fresh install
#In a terminal, type:
sudo -u postgres psql postgres
# this connects as a role with same name as the local user, i.e. "postgres", to the database called "postgres" (1st argument to psql).
# Set a password for the "postgres" database role using the command:
\password postgres