Skip to content

Instantly share code, notes, and snippets.

@johnniehard
Last active July 28, 2018 20:48
Show Gist options
  • Save johnniehard/00dc9d6abea5a58d80bda262ca5e931c to your computer and use it in GitHub Desktop.
Save johnniehard/00dc9d6abea5a58d80bda262ca5e931c to your computer and use it in GitHub Desktop.
Getting the orientation of the longest straight line distance across a polygon.

Some quick and dirty PostGIS:

Get the longest line for your polygons

create table test.tatortlongestline as
select st_longestline(t.geom, t.geom) as geom, t.tatort
from indata.tatort as t
where lanskod = '01';

Get the orientation of those lines

create table test.tatortlongestangle as
select tl.geom, st_azimuth(st_startpoint(tl.geom), st_endpoint(tl.geom))
from test.tatortlongestline as tl;

A little bit shortened:

drop table if exists test.tatortlongestangle2;
create table test.tatortlongestangle2 as
select tl.*, st_azimuth(st_startpoint(tl.geom), st_endpoint(tl.geom)) as orientation
from (
	select st_longestline(t.geom, t.geom) as geom, t.tatort
	from indata.tatort as t
	where lanskod = '01'
) as tl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment