Skip to content

Instantly share code, notes, and snippets.

View trolleway's full-sized avatar
🎯
Python, PostGIS, PostgreSQL, GIS

Artem Svetlov trolleway

🎯
Python, PostGIS, PostgreSQL, GIS
View GitHub Profile
#Largest cities per administrative entity of Russia
SELECT DISTINCT ?city ?cityLabel ?population ?country ?countryLabel ?loc WHERE {
{
SELECT (MAX(?population) AS ?population) ?country WHERE {
?city wdt:P31/wdt:P279* wd:Q515 .
?city wdt:P1082 ?population .
?city wdt:P131 ?country .
?country wdt:P17 wd:Q159 .
}
GROUP BY ?country
import os,shutil
def slice(video,folder='frames',fps=2,timecode_start='00:00:00',duration=3):
shutil.rmtree(folder, ignore_errors=True)
if not os.path.exists(folder):
os.mkdir(folder)
cmd = 'ffmpeg -ss {timecode_start} -i "{video}" -t {duration} -r {fps} -f image2 -vcodec mjpeg -qscale 1 "{folder}/frame_%05d.jpg"'.format(folder=folder,video=video,fps=fps,timecode_start=timecode_start,duration=duration)
os.system(cmd)
@trolleway
trolleway / asciimatics_uploader.py
Created December 11, 2017 15:13
test asciimatics forms
from asciimatics.widgets import Frame, ListBox, Layout, Divider, Text, \
Button, TextBox, Widget
from asciimatics.scene import Scene
from asciimatics.screen import Screen
from asciimatics.exceptions import ResizeScreenError, NextScene, StopApplication
import sys
import sqlite3
class NGWModel(object):
@trolleway
trolleway / add_nodes_to_line_network.sql
Last active November 23, 2017 17:12
We have linestring road network and point layer (terminals). Query inserting nodes into road network for future use in ogr2pbf
-- таблица точек на дорогах напротив терминалов. Генерируются точки на всех ближайших дорогах в заданом радиусе
CREATE TEMP TABLE cut_points AS (
SELECT
terminals.id AS id, line_id AS line_id,
ST_ClosestPoint(subquery.wkb_geometry::geography, terminals.geom::geography) AS wkb_geometry,
ST_Distance(terminals.geom::geography, ST_ClosestPoint(subquery.wkb_geometry, terminals.geom)::geography) AS dist
FROM (SELECT
ST_Multi(St_collect(network.wkb_geometry)) AS wkb_geometry,
network.line_id
FROM
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@trolleway
trolleway / reinstall_ngqgis.sh
Last active November 13, 2017 10:22
reinstall ngqgis
#Посмотреть, какая версия стоит сейчас
gdal-config --version
#Удалить всё похожее по названию на qgis, и gdal
sudo apt-get remove --purge ngqgis
sudo apt-get remove --purge ngqgis*
sudo apt-get remove --purge gdal-bin
sudo apt-get remove --purge python-gdal libgdal20 libgdal1i libgdal1h libgdal-dev
sudo apt-get remove --purge libqgis*
#Проверить, что ничего не осталось, если эти комманды выведут какие-либо пакеты - удалить их.

Dockerfiles

Standart dockerfile

FROM registry.nextgis.com/sshd:0.1.0
#там ubuntu с gdal

ARG DEBIAN_FRONTEND=noninteractive
ARG APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn
@trolleway
trolleway / shapes2geopackage.py
Created June 20, 2017 10:27
shapes2geopackage.py
# -*- coding: utf-8 -*-
'''
'''
from __future__ import unicode_literals
import config

I need to geotag every photo from trip to .gpx track, but GPX Logger accidentaly stopped. Luckly, i has turned on Google location history.

  1. Takeout location history from google.
  2. Extract .json file
git clone https://github.com/Scarygami/location-history-json-converter.git
location-history-json-converter-master\location_history_json_converter.py -f gpx -s 2017-05-06 -e 2017-05-07 "Takeout/Location History\Location History.json"
"c:\Program Files (x86)\GPSBabel\gpsbabel.exe" -i gpx -f "Takeout/Location History\Location History.gpx" -x transform,trk=wpt -o gpx -F track.gpx
REM склейка кадров в видео с заданным fps
"c:\Program Files (x86)\RICOH THETA\tools\ffmpeg.exe" -y -f image2 -framerate 60 -i %04d.jpg -vf format=yuv420p 103-3-30.mp4
REM создание клипа со статической картой, увеличение масштаба до размера кадра
"c:\Program Files (x86)\RICOH THETA\tools\ffmpeg.exe" -loop 1 -f image2 -t 4 -i map.png -vf scale=4608:2592 -pix_fmt yuv420p map.mp4
REM вклеить в начало ролика карту
"c:\Program Files (x86)\RICOH THETA\tools\ffmpeg.exe" -y -i map.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
"c:\Program Files (x86)\RICOH THETA\tools\ffmpeg.exe" -y -i 103-3-30.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
"c:\Program Files (x86)\RICOH THETA\tools\ffmpeg.exe" -y -i "concat:intermediate1.ts|intermediate2.ts|intermediate1.ts" -c copy -bsf:a aac_adtstoasc 103-4.mp4
REM Добавить музыку
"c:\Program Files (x86)\RICOH THETA\tools\ffmpeg.exe" -y -i 103-4.mp4 -i "C:\Users\trolleway\Downloads\De Lorra - Tomorrow.mp3" -codec copy -shortest 103-5.mp4