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-boun...@lists.gispython.org [mailto:community-boun...@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-boun...@lists.gispython.org<mailto:community-boun...@lists.gispython.org> [mailto:community-boun...@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 <t...@42.dk<mailto:t...@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 On Tue, Feb 17, Oleksandr Huziy wrote: > Hi Jake: > > will your method work when the polygon sides are not parallel to the axes? > > Cheers > > 2015-02-17 9:22 GMT-05:00 Jake Wasserman > <jwasser...@gmail.com<mailto:jwasser...@gmail.com>>: > > > Hi Yuta, > > You can use the `bounds` property on Shapely geometry objects to help ( > > http://toblerity.org/shapely/manual.html#object.bounds). > > This should work: > > > > 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 > > > > > > > > On Tue, Feb 17, 2015 at 9:04 AM, Yuta Sato > > <yutaxs...@gmail.com<mailto:yutaxs...@gmail.com>> wrote: > > > >> Dear Shapely Developers and Users: > >> > >> I 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 Community@lists.gispython.org<mailto:Community@lists.gispython.org> http://lists.gispython.org/mailman/listinfo/community
_______________________________________________ Community mailing list Community@lists.gispython.org http://lists.gispython.org/mailman/listinfo/community