# [postgis-users] Getting dimensions of polygon sides

Bruce Rindahl rindahl at lrcwe.com
Wed Jun 11 13:24:55 PDT 2008

```Regina
After looking closely at your code I think you are doing exactly the
same as I suggested.  I had to add the intermediate steps because my
method needed to find the line (distance) between 2 arbitrary points on
the polygon where you are always looking at two adjacent ones.
The only thing I see is your last line.  Will changing :

FROM dnd.rems_survey ap  ) p) As b
CROSS JOIN generate_series(1, 1000) n
WHERE n < b.nump;

to:

FROM dnd.rems_survey ap  ) p) As b
CROSS JOIN generate_series(1, b.nump - 1) n;

be any faster? It should avoid a WHERE test in each iteration.

Bruce

Obe, Regina wrote:
>  Bruce,
>
> Thanks for the below.  I think it will take me a while to digest what
> you are doing.  I think I learned a couple of things off the bat.
>
> 1) I may need the Right Hand Rule call since I was assuming things were
> already ordered correctly and my simple spot check seems to suggest that
> it is but you never know.
>
> 2) I'm confused between ST_Boundary and ST_ExteriorRing and when to use
> one over the other.  I assume ST_Boundary takes into consideration holes
> where as ST_ExteriorRing just gives you the outer ring.  Now I'm
> thinking about it I probably should replace my ST_Boundary with
> ST_ExteriorRing.
>
> In case anyone is curious.  Attached is a snapshot of what I get when I
> use my simple 2 point assumption.  It works in most cases but in others
> where they used more than 2 points to describe each corner, I get extra
> measures.
> Not the dimok is my ideal case and the dimalmost okay - see how I have
> an extra measure.
>
>  You think Simplifying before I extract would fix that.
>
> My final query and updates look like this - seems to run fairly fast for
> the 5000 parcel list I care about.
>
>   INSERT INTO assessing.parcdimstime_2008(pid, pid_year, the_geom)
> 	SELECT b.pid, b.pid_year, ST_MakeLine(ST_PointN(the_boundary,n),
> ST_PointN(the_boundary, n + 1)) As the_side
> 	FROM (SELECT pid, pid_year, the_boundary,
> ST_NumPoints(the_boundary) As nump
> 		FROM (SELECT ap.parcelid as pid, 2008 as pid_year,
> ST_Boundary(ap.the_geom) As
> the_boundary
> 			FROM dnd.rems_survey ap  ) p) As b
> 				CROSS JOIN generate_series(1, 1000) n
> 	WHERE n < b.nump;
>
>
> UPDATE assessing.parcdimstime_2008 SET side_length =
> CAST(ST_Length(the_geom) As numeric(8,2));
>
>
>

```

More information about the postgis-users mailing list