Skip to content

Instantly share code, notes, and snippets.

@knutole
knutole / install-docker-ubuntu.sh
Last active November 7, 2018 16:48
Install Docker on Ubuntu
#!/bin/bash
# https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-docker-ce
# Update the apt package index:
sudo apt-get update
# Install packages to allow apt to use a repository over HTTPS:
sudo apt-get install -y \
apt-transport-https \
ca-certificates \

Keybase proof

I hereby claim:

  • I am knutole on github.
  • I am knutole (https://keybase.io/knutole) on keybase.
  • I have a public key ASBT74e3EQKj9uGxrw-yK_x32_G0AvYU0XFgX_M94FEqNgo

To claim this, I am signing this object:

@knutole
knutole / docker-compose.yml
Created May 30, 2017 20:17 — forked from volkanunsal/docker-compose.yml
docker-postgis setup with streaming replication
master:
image: mdillon/postgis:9.3
ports:
- '5432:5432'
volumes:
- /import_data
- ./postgis/init-master.sh:/docker-entrypoint-initdb.d/init-master.sh
- ./postgis:/tmp/postgresql
restart: always
environment:
#!/bin/bash
# Install docker community edition on Ubuntu
# Updated May 5th 2017
# Maintained by <knutole at mapic dot io>
#
# For more info, see: https://docs.docker.com/engine/installation/linux/ubuntu/
DOCKER_COMPOSE_VERSION=1.13.0
DOCKER_MACHINE_VERSION=0.10.0
Art Bot Terms of Service and Privacy Policy
1. Terms
By accessing the website at https://www.facebook.com/ArtBot-2083196591906830/, you are agreeing to be bound by these terms of service, all applicable laws and regulations, and agree that you are responsible for compliance with any applicable local laws. If you do not agree with any of these terms, you are prohibited from using or accessing this site. The materials contained in this website are protected by applicable copyright and trademark law.
2. Use License
@knutole
knutole / Issues.md
Created October 6, 2016 12:45 — forked from rclark/Issues.md
Leaflet WMS + GetFeatureInfo

There are a bunch of reasons why this is convoluted, mostly in building the URL to make the request:

  1. You have to rely on an AJAX request, this example uses jQuery
  2. To make a GetFeatureInfo request, you must provide a BBOX for a image, and the pixel coordinates for the part of the image that you want info from. A couple of squirrely lines of Leaflet code can give you that.
  3. Output formats. The info_format parameter in the request. We don't know a priori which will be supported by a WMS that we might make a request to. See Geoserver's docs for what formats are available from Geoserver. That won't be the same from WMS to WMS, however.
  4. WMS services return XML docs when there's a mistake in the request or in processing. This sends an HTTP 200, which jQuery doesn't think is an error.
I simply need to clip a raster by a GeoJSON polygon. However, the query needs to fit into a Mapnik wrapper (of which I have no control).
# Full Mapnik query from PostGIS logs
SELECT ST_AsBinary(ST_Band(ST_Resample(ST_Clip("rast", ST_Expand(ST_SetSRID('BOX3D(743579.4111581944 8570731.10756024,900122.4450862355 8727274.141488284)'::box3d, 3857), greatest(abs(ST_ScaleX("rast")), abs(ST_ScaleY("rast"))))),305.748 * sign(ST_ScaleX("rast")),305.748 * sign(ST_ScaleY("rast")), 0, 0), 1)) AS geom FROM (SELECT ST_Clip(rast, st_transform(st_setsrid(ST_geomfromgeojson('{"type":"Polygon","coordinates":[[[9.019775390625,61.370409712010435],[7.998046875,61.17503266354878],[8.7890625,61.16443708638272],[9.29443359375,60.62471311568258],[10.469970703124998,61.63250678169624],[9.5361328125,61.201506036385375],[9.019775390625,61.370409712010435]]]}'), 4326), 3857)) FROM file_tpspmpkrwlsrcchskibg) as subquery WHERE "rast" && ST_SetSRID('BOX3D(743579.4111581944 8570731.10756024,900122.4450862355 8727274.141488284)'::box3d, 3857)
The idea here is that there are two different rasters - one large rasterA, and one small rasterB used as a mask. We need to get the values of rasterA which are within the bounds of rasterB.
Additional problem: rasterB has NODATA value of 0, and ONLY the part of the rasterB that is NOT NODATA should be used as a mask.
The example below is wrong, for several reasons. Can you fix it?
select row_to_json(t) from (
SELECT A.rid, B.rid, pvc
FROM rasterA A
JOIN rasterB B
WITH first AS (
SELECT id, (ST_Intersection(rast, rast, 0)).val
FROM file_caolvkddzzlgmvyeofrh
INNER JOIN file_xbwnbydpmwesokzmrcht ON ST_Intersects(rast, rast, 0)
)
SELECT id, COUNT(val), SUM(val), AVG(val), stddev(val), MIN(val), MAX(val)
FROM first
GROUP BY id;
# second problem
select row_to_json(t) from (SELECT rid, pvc FROM file_pszjkuicfjvxvizbygbq, ST_ValueCount(rast,1) AS pvc WHERE st_intersects(st_transform(st_setsrid(ST_geomfromgeojson('{"geometry":{"type":"Polygon","coordinates":[[[9.31640625,60.88770004207789],[9.31640625,61.48075950007598],[10.8984375,61.48075950007598],[10.8984375,60.88770004207789],[9.31640625,60.88770004207789]]]}}'), 4326), 3857), rast) as t;
error running query { [Error: ERROR: unknown GeoJSON type
# first problem, solved!
select row_to_json(t) from (