Skip to content

Instantly share code, notes, and snippets.

View joakimsk's full-sized avatar

Joakim Skjefstad joakimsk

  • Skjefstad Under Pressure
  • Somewhere in the deep blue sea
View GitHub Profile
@joakimsk
joakimsk / sh-dwgtodxf.sh
Last active March 4, 2018 10:23
Convert DWG to DXF using Teigha in batch
#!/bin/bash
# To execute in batch mode
# find . -iname "*.dwg" -print0 | xargs -0 -I {} ./sh-dwgtodxf.sh -i "{}"
TEIGHA="/Applications/TeighaFileConverter.app/Contents/MacOS/TeighaFileConverter"
OUTVER="ACAD2004"
OUTFORMAT="DXF"
RECURSIVE="0"
AUDIT="1"
@joakimsk
joakimsk / sh-upload.sh
Created March 4, 2018 05:42
Find all dxf recursively and upload to database
#!/bin/bash
# Find all dxf recursively and upload to Postgresql+Postgis database, using ogr2ogr
find . -iname "*.dxf" -print0 | xargs -0 -I {} ogr2ogr --config OGR_ENABLE_PARTIAL_REPROJECTION TRUE --config CPL_DEBUG ON -f "PostgreSQL" PG:"dbname=mapDatabase user=postgres" "{}" -s_srs "+proj=sterea +lat_0=34.2 +lon_0=39.15 +x_0=28 +y_0=-42 +a=6378249.2 +b=6356515 +units=m +no_defs" -t_srs EPSG:4326 -a_srs EPSG:4326 -dim XY -dialect SQLITE -sql "SELECT e.layer, e.text, e.geometry FROM entities e WHERE ST_GeometryType(e.geometry) IN ('POINT', 'POINT Z', 'LINESTRING', 'LINESTRING Z', 'MULTILINESTRING', 'MULTILINESTRING Z', 'POLYGON', 'POLYGON Z', 'MULTIPOLYGON', 'MULTIPOLYGON Z');" -nln 'entities' -append
@joakimsk
joakimsk / sh-info.sh
Created March 4, 2018 04:52
Check geometry types in files, counts number of features. Using ogrinfo, can take dxf, geosjon and more
#!/bin/bash
# Check geometry types in files, counts number of features. Using ogrinfo, can take dxf, geosjon and more
ogrinfo -dialect SQLITE -sql "SELECT ST_GeometryType(geometry), COUNT(ST_GeometryType(geometry)) FROM entities e GROUP BY ST_GeometryType(geometry);" input.dxf
@joakimsk
joakimsk / merge-geojsons.py
Created February 27, 2018 08:10 — forked from migurski/merge-geojsons.py
Merge multiple GeoJSON files into one
from json import load, JSONEncoder
from optparse import OptionParser
from re import compile
float_pat = compile(r'^-?\d+\.\d+(e-?\d+)?$')
charfloat_pat = compile(r'^[\[,\,]-?\d+\.\d+(e-?\d+)?$')
parser = OptionParser(usage="""%prog [options]
Group multiple GeoJSON files into one output file.
@joakimsk
joakimsk / sh-merge.sh
Last active March 4, 2018 05:30
Script to merge geographical data using ogr2ogr
#!/bin/bash
# Merge accepted files into one geojson using ogr2ogr. Supports DXF 2004 and later, Geojson and more
# http://www.gdal.org/ogr_formats.html
# This is a bit slow, but npm install geojson-merge seems to have trouble with big files
# Includes option to enable partial reprojection, dropping invalid coordinates, and also reprojects with custom PROJ.4 string
# Drops Z axis using -dim XY, but accepts Z axis features.
for f in *.dxf
do
@joakimsk
joakimsk / overpass_find_boundaries_for_lebanon_lvl4.js
Created January 29, 2018 13:44
Overpass Turbo query to find boundaries on admin level 4 from OSM data
/* overpass-turbo: Find all boundaries for Lebanon on admin_level 4 */
{{geocodeArea:"LB"}}->.a;
(
relation["boundary"="administrative"]["admin_level"="4"](area.a);
);
/*added by auto repair*/
(._;>;);
/*end of auto repair*/
out;
@joakimsk
joakimsk / install-postgis.sh
Last active January 15, 2018 10:54 — forked from whyvez/install-postgis.sh
postGIS install on AWS linux AMI
#!/bin/bash
# Script to setup an Elastic Beanstalk AMI with geospatial libraries and postGIS, extra python3
# Stable releases as of 15. January 2018
# Go to ec2-user home directory
cd /home/ec2-user
sudo yum -y install gcc gcc-c++ make cmake libtool libcurl-devel libxml2-devel rubygems swig fcgi-devel\
libtiff-devel freetype-devel curl-devel libpng-devel giflib-devel libjpeg-devel\
cairo-devel freetype-devel readline-devel openssl-devel python27 python27-devel\
@joakimsk
joakimsk / dwgver.py
Created January 14, 2018 04:25
Autocad DWG version read using python3
#!/usr/bin/env python
# http://vislab-ccom.unh.edu/~schwehr/rt/python-binary-files.html
# https://knowledge.autodesk.com/support/autocad/learn-explore/caas/sfdcarticles/sfdcarticles/drawing-version-codes-for-autocad.html
# MC0.0 - DWG Release 1.1
# AC1.2 - DWG Release 1.2
# AC1.4 - DWG Release 1.4
# AC1.50 - DWG Release 2.0
# AC2.10 - DWG Release 2.10
# AC1002 - DWG Release 2.5
@joakimsk
joakimsk / poweroffice_api_test.py
Created June 19, 2017 22:09
Poweroffice Go API REST test in python3
#!/usr/bin/env python3
import requests
from pprint import pprint
client_id = r'REPLACEME' #Application key
client_secret = r'REPLACEME' #Client key
oauth_token_base_url = 'https://godemo.poweroffice.net/OAuth/Token'
api_base_url = 'https://api-demo.poweroffice.net/'
def _url(path):
@joakimsk
joakimsk / 99-gpio.rules
Created April 14, 2017 20:57
Odroid-C1 gpio udev rules for user space access without root on Arch Linux
SUBSYSTEM=="meson-gpiomem", KERNEL=="gpiomem", GROUP="gpio", MODE="0660"
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'"
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"