This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION geom2bin (geometry) | |
RETURNS text AS $$ | |
SELECT reverse(string_agg( | |
CASE WHEN i > 0 AND mod(i, 8) = 0 THEN ' ' ELSE '' END || | |
CASE | |
WHEN chr = '0' THEN '0000' | |
WHEN chr = '1' THEN '0001' | |
WHEN chr = '2' THEN '0010' | |
WHEN chr = '3' THEN '0011' | |
WHEN chr = '4' THEN '0100' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def masked_vectorize(fn): | |
vectorized = np.vectorize(fn) | |
def ret(*args, **kwargs): | |
# In theory, it should be possible to replace this with | |
# np.ma.logical_or.reduce([a.mask for a in args]) | |
# In practice, it seems to generate an error when the | |
# internal storage of the arguments is different | |
# ValueError: setting an array element with a sequence. | |
masked_args = [arg for arg in args if isinstance(arg, np.ma.core.MaskedArray)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Divide an input geometry into equal-length portions of the specified length. | |
-- The final segment will contain the "unused" portion of the line and will be | |
-- shorter than the others. | |
-- | |
-- Note that segment_length is in the units of the geometry's coordinate system, | |
-- i.e. degrees for 4326. To use the function with geographic coordinates and | |
-- a distance in meters, it is recommended to project the geometry into a | |
-- planar coordinate system, e.g. using _ST_BestSRID. | |
CREATE OR REPLACE FUNCTION pg_temp.DivideLine(g geometry, segment_length double precision) | |
RETURNS SETOF geometry AS $$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM phusion/baseimage | |
RUN apt-get update && apt-get install -y build-essential git bison flex zlib1g-dev autoconf libtool libxml2-dev libproj-dev libjson0-dev libcunit1-dev libxml2-utils xsltproc imagemagick docbook-xsl docbook-mathml libgdal-dev wget cmake libgmp-dev libmpfi-dev libboost-thread-dev libboost-system-dev | |
RUN git clone --depth 1 https://github.com/postgres/postgres.git && cd postgres && ./configure --without-readline && make -j6 && make install && make clean && cd .. && rm -rf postgres | |
RUN git clone --depth 1 https://github.com/libgeos/libgeos.git && cd libgeos && ./autogen.sh && ./configure --libdir=/usr/lib && make -j6 && make install && make clean && cd .. && rm -rf libgeos | |
RUN wget https://github.com/CGAL/cgal/releases/download/releases%2FCGAL-4.7/CGAL-4.7.tar.gz && tar xzvf CGAL-4.7.tar.gz && rm CGAL-4.7.tar.gz && cd CGAL-4.7 && cmake . && make -j6 && make install && make clean && cd .. && rm -rf CGAL-4.7 | |
RUN git clone --depth 1 https://github.com/Oslandia/SFCGAL.git && cd SFCGAL && cmake |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM phusion/baseimage | |
RUN apt-get update && apt-get install -y \ | |
build-essential \ | |
git \ | |
bison \ | |
flex \ | |
zlib1g-dev \ | |
autoconf \ | |
libtool \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PG_FUNCTION_INFO_V1(cluster_intersecting_window); | |
Datum cluster_intersecting_window(PG_FUNCTION_ARGS) | |
{ | |
WindowObject win_obj = PG_WINDOW_OBJECT(); | |
uint32_t row = WinGetCurrentPosition(win_obj); | |
uint32_t ngeoms = WinGetPartitionRowCount(win_obj); | |
uint32_t* cluster_assignments = WinGetPartitionLocalMemory(win_obj, ngeoms * sizeof(uint32_t)); | |
if (row == 0) /* beginning of the partition; do all of the work now */ | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.vividsolutions.jts.geom.Geometry; | |
import com.vividsolutions.jts.geom.util.GeometryCombiner; | |
import com.vividsolutions.jts.index.strtree.STRtree; | |
import java.util.Collection; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
public class ParallelCascadedPolygonUnion { | |
public static Geometry union(Collection<Geometry> geoms) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- convert 'text' fields into varchar fields of an appopriate length (useful for exporting to shp, dbf, etc) | |
CREATE OR REPLACE FUNCTION set_varchar_length (schema_name text, table_name text) RETURNS VOID AS $$ | |
DECLARE rec record; | |
DECLARE len int; | |
DECLARE qry text; | |
DECLARE is_first boolean; | |
BEGIN | |
qry := 'ALTER TABLE ' || quote_ident(schema_name) || '.' || quote_ident(table_name); | |
is_first := true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.maponics.algorithm; | |
import com.vividsolutions.jts.geom.Coordinate; | |
import com.vividsolutions.jts.geom.Geometry; | |
import com.vividsolutions.jts.operation.polygonize.Polygonizer; | |
import com.vividsolutions.jts.operation.union.UnaryUnionOp; | |
import java.util.*; | |
import java.util.concurrent.Callable; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT old.column_name as column_1141, old.data_type as type_1141, new.column_name as column_1142, new.data_type as type_1142 | |
FROM | |
(SELECT * FROM information_schema.columns WHERE table_schema = 'old_schema' AND table_name = 'old_table') old | |
FULL OUTER JOIN | |
(SELECT * FROM information_schema.columns WHERE table_schema = 'new_schema' AND table_name = 'new_table') new | |
USING (column_name) | |
WHERE old.column_name IS DISTINCT FROM new.column_name | |
OR old.data_type != new.data_type | |
ORDER BY COALESCE(old.column_name, new.column_name) ASC; |