[R-sig-Geo] Polygon width

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Wed Apr 25 13:27:19 CEST 2018


Do you want great-circle distance or is your space small enough that you
can use planar coordinates?

Are your polygons all single rings or are there islands and/or holes? Does
that matter?

The straightforward way would be to coerce the polygons to points, compute
the distance matrix, then take the maximum. Depending on if you are reading
your shapefile into sp or sf classes, the functions would be a bit
different. You should try and implement the straightforward way, test it
for correctness, and then worry about the "best way" if the straightforward
way isn't what you need. Its often the case that "best" ways need fancy
data structures or complex algorithms with more opportunity for bugs. Start
simple, work up.

For example, using sf, here's the max distance between any points in the
first feature of `pcs`

> max(st_distance(st_cast(st_geometry(pcs[1,]),"POINT")))
172.556 m

loop from 1 to N or otherwise apply over the features, and you're done.

Barry



On Wed, Apr 25, 2018 at 11:26 AM, Paulo Flores Ribeiro <
paulo.flores.mail at gmail.com> wrote:

> Hello,
>
> I have a shapefile with ca. 25000 polygons. Each polygon has an average of
> 40 vertices (nodes). I would like to extract, for each polygon, the
> distance separating the two most distant vertices (aka "polygon diagonal"
> or "maximum polygon width"). It is not important whether the polygon is
> convex or concave, so the lines connecting the vertices can be inside or
> outside the polygon. The desired result would be a two-column array, with a
> number of rows equal to the number of polygons, and where the first column
> is the id of the polygons, and the second the "maximum width" of the
> corresponding polygon.
>
> What would be the best way to do this, considering that the calculation
> will probably require frequent updates (e.g. due to changes in the shape of
> the polygons)?
>
> Thanks in advance,
>
> PauloFR
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list