Skip to content

Instantly share code, notes, and snippets.

@zhangxu
Last active August 29, 2015 14:06
Show Gist options
  • Save zhangxu/479e383296a7b0078b21 to your computer and use it in GitHub Desktop.
Save zhangxu/479e383296a7b0078b21 to your computer and use it in GitHub Desktop.
PostGIS functions
\set p1 '\'' 'POLYGON((0 0, 0 3, 3 3, 3 0, 0 0))' '\''
\set p2 '\'' 'POLYGON((1 1, 1 2, 2 2, 2 1, 1 1))' '\''
\set p3 '\'' 'POLYGON((-1 -1, -1 1, 1 1, 1 -1, -1 -1))' '\''
\set p4 '\'' 'POLYGON((-2 0, -1 0, -1 -1, -2 -1, -2 0))' '\''
\set p5 '\'' 'POLYGON((0 0, 0 3, 1.5 3.5, 3 3, 3 0, 0 0))' '\''
\set p6 '\'' 'POLYGON((9473678.20883554 1181106.57122879,9473678.20915479 1181106.57199719,9473678.21065819 1181106.57712958,9473678.21207348 1181106.58209349,9473678.2081223 1181106.58868023,9473678.20795089 1181106.58826838,9473678.20606889 1181106.57622375,9473678.20883554 1181106.57122879))' '\''
\set p7 '\'' 'SRID=3857;POLYGON ((-121.7917486242956 36.87756646920572, -121.7896991290737 36.87551268040243, -121.7864477199712 36.87768243547166, -121.7884120600693 36.87976431594564, -121.7917486242956 36.87756646920572))' '\''
\set p8 '\'' 'POLYGON((-120.7196010461798 37.29983125684954,-120.7195417733233 37.30292145606124,-120.7195094300227 37.30614240853466,-120.7208900281683 37.30615432208558,-120.7220952383513 37.30616122448719,-120.7231384964464 37.30616697202531,-120.7238441507191 37.30617364484905,-120.7239044114531 37.30607952315337,-120.7239221875663 37.30531777870133,-120.7239296104501 37.30446797516031,-120.7239155293253 37.30365369346188,-120.7239465584854 37.30284524393439,-120.7239603670485 37.30155174370989,-120.723966531088 37.3012039050179,-120.7239709621679 37.30076929490036,-120.7239718478445 37.30052590236532,-120.7239833702432 37.29995509446012,-120.7239222041949 37.29992629189364,-120.7238714180838 37.29988136135938,-120.7234676007041 37.29988507119413,-120.7226947181768 37.29987330648249,-120.7226268307691 37.29986922940459,-120.7226447081706 37.29980016707749,-120.7221240805201 37.29979598462473,-120.7218640317808 37.29979187142418,-120.7217605317787 37.29979193190215,-120.7216837375324 37.29981232781512,-120.7215380622202 37.2997800027233,-120.7213619463215 37.29980027912468,-120.7212573865634 37.29979602288232,-120.7211886898516 37.29973925746594,-120.7209394492553 37.29972697774448,-120.7208252606818 37.29971477307225,-120.7205978005931 37.29973085883243,-120.7202980082693 37.29971900236162,-120.7201272518445 37.29973521426771,-120.7200549876601 37.29970290403527,-120.7200241618549 37.29966661925262,-120.7196734736802 37.29967853101748,-120.7197249675492 37.29967856156245,-120.7197868286676 37.29967858311846,-120.7198538399747 37.29967861925025,-120.7198795842074 37.29967864946043,-120.7199311269583 37.29967869656542,-120.7199259628567 37.29967869598464,-120.7198795842074 37.29967864946043,-120.7198693171066 37.29967460971991,-120.719828121412 37.29967456958594,-120.7197868688526 37.29967455595364,-120.71974560762 37.29967454886968,-120.7196941086324 37.29967451944214,-120.7196786628433 37.29967451061002,-120.7196010461798 37.29983125684954))' ''\'
select ST_PolygonFromText(:p1);
select ST_contains(st_polygonFromText(:p1), st_polygonFromText(:p2)); // t
select st_polygonFromText(:p1) &<| st_polygonFromText(:p2); // f
select ST_overlaps(st_polygonFromText(:p1), st_polygonFromText(:p2)); // f
select st_asText(ST_union(st_polygonFromText(:p1), st_polygonFromText(:p2)));
select st_asText(ST_union(st_polygonFromText(:p1), st_polygonFromText(:p3)));
select st_asText(ST_union(st_polygonFromText(:p4), st_polygonFromText(:p2)));
select st_asText(ST_SimplifyPreserveTopology(st_polygonFromText(:p5), 1));
select st_asText(ST_SimplifyPreserveTopology(st_polygonFromText(:p6), 1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment