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 / ender3_manta_bltouch.md
Last active October 15, 2023 19:49
3D Printer, Ender 3 + Bigtreetech Manta EZ3D + BLTouch 3
@joakimsk
joakimsk / onlinemapsources_addsjokart.xml
Created February 18, 2019 21:37
Add Norwegian Seamap to Oruxmaps
<onlinemapsource uid="1000">
<name>Kartverket Sjøkart (NO)</name>
<url><![CDATA[http://opencache.statkart.no/gatekeeper/gk/gk.open_gmaps?layers=sjokartraster&zoom={$z}&x={$x}&y={$y}]]></url>
<website><![CDATA[<a href="http://www.kartverket.no/" target="_blank">Kartverket</a>]]></website>
<minzoom>1</minzoom>
<maxzoom>19</maxzoom>
<projection>MERCATORESFERICA</projection>
<servers></servers>
<httpparam name="User-Agent">{om}</httpparam>
<cacheable>1</cacheable>
@joakimsk
joakimsk / planetscope.md
Last active July 16, 2021 02:52
PlanetScope data to QGIS

PlanetScope data to QGIS

https://medium.com/planet-stories/a-gentle-introduction-to-gdal-part-4-working-with-satellite-data-d3835b5e2971 A typical workflow to create an image from raw satellite data would be:

  1. Download data.
  2. Re-order or assemble bands into the desired order (red, green, blue; or near-infrared, red, green; etc.)
  3. Increase the resolution with pan-sharpening, if desired.
  4. Contrast-stretch and color-correct the imagery, either algorithmically or by hand.
  5. Restore georeferencing information, if necessary.
@joakimsk
joakimsk / faware-scheduled.py
Last active March 27, 2018 08:06
Flightaware FlightXML2 REST API test
#!/usr/bin/env python
import json
import requests
username = 'YOURUSERNAMEHERE'
api_token = 'YOURKEYHERE'
fxml_urlbase = 'http://flightxml.flightaware.com/json/FlightXML2/';
print('Flightaware FlightXML2 test')
@joakimsk
joakimsk / select_within_polyline.lsp
Last active March 21, 2018 05:29
Autocad 2018 - Select elements within a POLYLINE
; Script courtesy of wronzky @ http://ww3.cad.de/foren/ubb/Forum54/HTML/018135.shtml
; Use a polyline (supposedly only LWPOLYLINE) as a selector. Will select all items inside.
; If you have a Region, try to EXPLODE, QSELECT lines then JOIN to form a single POLYLINE
; Use BOUNDARY to create a new POLYLINE from an enclosed area.
; Follow the command with WBLOCK to write elements to a new file.
; Modified by joakimsk, tested on Autocad 2018 OS X
(defun c:lcp ( / ) ; lcp selects all elements crossing or is inside the polyline (Crossing Polygon)
(sssetfirst nil (ssget "_CP" (vox-get-points (car (entsel "\nSelect 'Crossing Polygon' POLYLINE:")))))
)
@joakimsk
joakimsk / sh-upload.sh
Created March 18, 2018 14:22
Upload DXF to Postgis database, and add filename to field mapfile
#!/bin/bash
# sh-upload.sh
# -i input DXF file
#
#
# To execute in batch mode:
# find . -type d \( -name "MERGE*" -o -name "Extra" -o -name "RESOLVE*" -o -name "SEPARATE*" \) -prune -o -iname "*.dxf" -print0 | xargs -0 -I {} ./sh-upload.sh -i "{}"
#
# By Joakim Skjefstad
@joakimsk
joakimsk / mergeandwritedxf.md
Last active March 14, 2018 09:37
Merge and write DXF

Merge DXF (up to 2018) and then write DXF (2004) file

Make or update sqlite database using file1.dxf, preserve any layers and drop Z coordinate

ogr2ogr -f SQLite "merged.sqlite" "file1.dxf" -dsco SPATIALITE=YES -nln 'entities' -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');" --config OGR_ENABLE_PARTIAL_REPROJECTION TRUE --debug ON -update -append -dim XY

Repeat this step for each file to be merged.

Create DXF from sqlite database, preserving text fields using custom styling

@joakimsk
joakimsk / 0-polygonize.md
Last active March 18, 2018 14:29
Polygonize linestring geometries

Ways to polygonize

Using Qgis

Manual. Uses ST_Polygonize from GDAL. I did not manage to get this to work, but it is manual, mind you.

Using Postgresql, Postgis and ST_Polygonize: elephant.sh

Fast method, but complex query. Uses ST_Polygonize from GDAL. I suggest using this method, works well with insanely large datasets. Remember to use GiST index.

Using Python3 and Shapely+Fiona

Relatively slow, but seems to work, also gives you good control over dangles and cuts.

@joakimsk
joakimsk / sh-ogrgetlayers.sh
Created March 12, 2018 06:18
Get layers from DXF files using ogrinfo
#!/bin/bash
# sh-ogrgetlayers.sh
# -i input DXF file
# Output all dxf files and their layers to layers.csv. Layers in array format ['a','b']
#
# To execute in batch mode:
# find . -iname "*.dxf" -print0 | xargs -0 -I {} ./sh-ogrgetlayers.sh -i "{}"
#
# Requires ogrinfo, uses sed and grep, tested on OS X 10.13.3
@joakimsk
joakimsk / oneliners.sh
Last active March 5, 2018 02:08
Oneliners to manipulate and search geographical data with ogr, gdal and more
# Find all files recursively of dxf type, run ogrinfo and sort by geometry types
find . -iname "*.dxf" -print0 | xargs -0 -I {} ogrinfo -dialect SQLITE -sql "SELECT ST_GeometryType(geometry), COUNT(ST_GeometryType(geometry)) FROM entities e GROUP BY ST_GeometryType(geometry);" {}
# Convert from dxf to sqlite using proper arguments and discard unneeded fields, drop Z dimension
ogr2ogr -f SQLite testspatialite.sqlite a18ascii.dxf -s_srs "+proj=sterea +lat_0=34.2 +lon_0=39.15 +k=1.0 +x_0=28 +y_0=-42 +a=6378249.2 +b=6356515 +units=m +no_defs" -t_srs EPSG:4326 -a_srs EPSG:4326 -dsco SPATIALITE=YES -dim XY -nln 'entities' -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');" --config OGR_ENABLE_PARTIAL_REPROJECTION TRUE --debug ON
# Add field mapfile to table, length of character optional (default = 1), detai