Skip to content

Instantly share code, notes, and snippets.

@dlebauer
Created May 17, 2017 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlebauer/f586e380fa4cfadc25551cd1df487b7d to your computer and use it in GitHub Desktop.
Save dlebauer/f586e380fa4cfadc25551cd1df487b7d to your computer and use it in GitHub Desktop.
Split plots into east and west. Required some find/replace and sorting in google spreadsheet to generate insert statements
with foo as
(WITH season1 AS (select id, sitename, geometry as geom from sites where sitename like '%Season 1%' and geometry is not null)
SELECT
sitename,
geom,
blade
FROM
season1
CROSS JOIN LATERAL (
SELECT
ST_xMin (geom) + (
ST_xMax (geom) - ST_xMin (geom)
) / 2
) AS axis (x)
CROSS JOIN LATERAL ST_MakeLine (
ST_MakePoint (axis.x, ST_yMin(geom), 353),
ST_MakePoint (axis.x, ST_yMax(geom), 353)
) AS blade
) SELECT
/* ST_AsText (ST_SetSRID(geom, 4326)),
ST_AsText (ST_SetSRID(blade, 4326)), */
sitename,
ST_DUMP(ST_Split(ST_SetSRID(geom, 4326), st_setsrid(blade, 4326))) as g
FROM
foo;
@dlebauer
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment