Skip to content

Instantly share code, notes, and snippets.

View bjornharrtell's full-sized avatar

Björn Harrtell bjornharrtell

View GitHub Profile
@bjornharrtell
bjornharrtell / cleanpolys.sql
Last active August 29, 2015 14:13
cleanpolys
-- Function: gkdb.repairgeom(geometry)
-- DROP FUNCTION gkdb.repairgeom(geometry);
CREATE OR REPLACE FUNCTION gkdb.repairgeom(polygon geometry)
RETURNS geometry AS
$BODY$
DECLARE
linework geometry;
@bjornharrtell
bjornharrtell / split_polygon.sql
Last active August 29, 2015 14:24
split_polygon
CREATE OR REPLACE FUNCTION osm.split_polygon(polygon geometry, level integer)
RETURNS SETOF geometry AS
$BODY$
DECLARE
num_points int;
mid double precision;
envelope geometry;
b1 geometry;
b2 geometry;
geom1 geometry;
@bjornharrtell
bjornharrtell / osm.land_polygons.sql
Last active August 29, 2015 14:24
Rectangular cut out of OSM land_polygons subdivided to contain at most 1000 vertices
-- source is in 4326
drop table osm.land_polygons_3006;
create table osm.land_polygons_3006 (gid serial primary key, geom geometry(Polygon,3006));
with transformed_subset1 as (
select ST_Transform(ST_ClipByBox2D(geom, ST_MakeEnvelope(0, 40, 50, 75, 4326)), 3006) as geom from osm.land_polygons
), subset2 as (
select ST_ClipByBox2D(geom, ST_MakeEnvelope(-350000, 5600000, 1870000, 7980000, 3006)) as geom from transformed_subset1 where ST_IsEmpty(geom) is false
)
insert into osm.land_polygons_3006 (geom) select (ST_Dump(ST_SubDivide(geom, 1000))).geom from subset2 where ST_IsEmpty(geom) is false;
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="font">
<edit mode="assign" name="rgba">
<const>rgb</const>
</edit>
</match>
<match target="font">
<edit mode="assign" name="hinting">
@bjornharrtell
bjornharrtell / turnlogic.scala
Created March 19, 2012 18:09
This works! :) and is now a one-liner! :)
if ((delta & 7) > 4) rightOf else leftOf
@bjornharrtell
bjornharrtell / matchtype.scala
Created August 15, 2012 20:40
Trying to understand this...
trait POf2[Bi[_, _]] {
def unapply[A, B](x: Bi[A, B]): Option[(A, B)]
}
implicit val TuplePOf2: POf2[Tuple2] = new POf2[Tuple2] {
def unapply[A, B](x: (A, B)) = Some(x)
}
(1, 4) match { case TuplePOf2(a, b) => a + b }
@bjornharrtell
bjornharrtell / override.scala
Created August 29, 2012 19:37
cannot compile because cannot override mutable variable
// cannot compile because cannot override mutable variable
// purpose of this pattern is to reuse logic from Base in Sub that works with BaseElements while Sub contains logic that works with SubElements
// not allowing override of vals has valid reasons so I'm looking for other options on how to design this
class BaseElement {
def foo() { println("I like foo") }
}
class SubElement extends BaseElement {
def bar() { println("I like bar") }
@bjornharrtell
bjornharrtell / twice.scala
Created September 3, 2012 16:00
inherits twice?
class BaseElement {
def foo() { println("I like foo") }
}
class SubElement extends BaseElement {
def bar() { println("I like bar") }
}
trait Base[T <: BaseElement] {
var map = Map[Int, T]()
@bjornharrtell
bjornharrtell / twolist.scala
Created September 8, 2012 10:57
Filter a with c?
val a = Vector.fill(64){true}
val b = Vector.fill(64){false}
val c = b.updated(10, true)
a zip c foreach { case (ae, ce) => if (ce) ae = false }
function consolidateImageWMSLayers (layers) {
let i, j
const layersProcessed = [] // need to record processed layers to only process once
const layersToConsolidate = [] // intended to contain arrays of layer that are to be consolidated
const otherIndices = [] // indices of unconsolidated layers, will be used when assembling new layers
const isImageWMS = layer => layer.type === 'Image' && layer.source.type === 'ImageWMS'
const isProcessed = layer => layersProcessed.indexOf(layer) !== -1
const isCandidate = (l1, l2) => l1.source.url === l2.source.url && !(l1.metadata.unconsolidated === true || l2.metadata.unconsolidated === true)