Apologies to all for the typos.
The first line of the second paragraphs should have read:
If you are thinking geographically and you are using longitude as your x dimension and latitude as your y dimension, then bounds() gives you the âwestmost, southmost, eastmost, and northmostâ values.
From: community-***@lists.gispython.org [mailto:community-***@lists.gispython.org] On Behalf Of Harasty, Daniel J
Sent: Tuesday, February 17, 2015 2:34 PM
To: gispython.org community projects
Subject: Re: [Community] Feature Request: Shapely Rectangle Diagonal
A few comments for Yuta:
Note the bounds() method returns four VALUES -- not four points. Thus, they are not properly a rectangle, or even a geometry of any sort. They are a list of four values: the minimum- and maximum- x and y values.
If you are thinking geographically and you are using longitude as your x dimension and latitude as your x, then bound() gives you the âwestmost, southmost, eastmost, and northmostâ values. Note it does NOT guarantee that the original geometry actually had a vertex at any of the corners of the box implied by those values.
Note that you made reference to a âgeographic coordinate systemâ. Shapely does its calculations on pure, abstract geometries. It is up to the user (you) to decide on a geographic system, and if Shapely geometric calculations are fit for your purpose. (For example, if you are using latitude and longitude as your âx and yâ values in Shapely, the measures of things like Shapelyâs âlengthâ and âareaâ wonât actually give you measures of geographic length and area, owing to the curvature of the earth and that latitude and longitude do not constitute a pure, 2-dimensional planar coordinate system.)
Lastly, to your original question (and desire) that youâd like Shapely to give you useful things like measures of rectangular width, height, and diagonal, note that âRECTANGLEâ is not a primitive Shapley shape â nor is it generally a primitive in most geometric processing APIs. A rectangle is an instance of one kind of polygon. Measures like width, height, and diagonal are not necessarily meaningful on arbitrary polygons. Thus it doesnât seem to me they SHOULD be defined in Shapely, at least not on any of the shapes it currently defines.
However you could â if you see fit â subclass shapely.geometry.Polygon, and add these calculations yourself, then still use all other Shapely operations on Polygons⊠because your Rectangle would be a Shapely polygon. You would have to decide in the design of this object if ârectanglesâ are parallel to the coordinate system, or could be âskewââŠ. and build constructors and accessors that enforce the constraints as you see fit.
Regards,
Dan Harasty
From: community-***@lists.gispython.org<mailto:community-***@lists.gispython.org> [mailto:community-***@lists.gispython.org] On Behalf Of Yuta Sato
Sent: Tuesday, February 17, 2015 1:47 PM
To: gispython.org community projects
Subject: Re: [Community] Feature Request: Shapely Rectangle Diagonal
I have a question: Does not "minx, miny, maxx, maxy" calculated by poly.bounds in a geographic coordinate system provide the rectangle sides parallel to the axes?
On Wed, Feb 18, 2015 at 1:09 AM, Kristian Thy <***@42.dk<mailto:***@42.dk>> wrote:
Hi Oleksandr,
Yes, if by "width" and "height" one means the geometric width in the
direction of the axes of the coordinate system.
If you want to measure the _mean_ width of the object, you need to
calculate a convex hull and inscribe it in a circle.
https://en.wikipedia.org/wiki/Mean_width
Cheers,
Kristian
Post by Oleksandr Huziywill your method work when the polygon sides are not parallel to the axes?
Cheers
Post by Jake WassermanHi Yuta,
You can use the `bounds` property on Shapely geometry objects to help (
http://toblerity.org/shapely/manual.html#object.bounds).
poly = shapely.geometry.Polygon([(0,0), (1,0), (1,3), (0, 3)])
minx, miny, maxx, maxy = poly.bounds
width = maxx - minx
height = maxy - miny
diagonal = math.hypot(width, height)
You can always wrap that into a function if you find yourself reusing it a
lot.
-Jake
Post by Yuta SatoI am a regular user of shapely.
I want to see more smarter shapely.
Meanwhile, could you add an ability to calculate length of height, width,
and diagonal of a rectangular polygon?
It would be great help if someone could write a function in Python using
existing shapely for that.
Thanks.
Yuta
_______________________________________________
Community mailing list
***@lists.gispython.org<mailto:***@lists.gispython.org>
http://lists.gispython.org/mailman/listinfo/community