1

I want to create rectangular polygons from points. Actually I have a GeoPandas point DataFrame and the distance in X & Y direction to form the polygon. The distances are equal for every point. I know it is possible to use QGIS or ArcMap, but I look for a method in Python without using this software.

EDIT: it is not a duplicate as far as I can see because the other questions are looking for a square buffer I look for a rectangular buffer with a different size in x, y directions.

EDIT 2: Here is what I have so far

import shapely as spl
test_point = [(8.54253101348877, 49.53561782836914)]
distance_lon = 0.010373115539550781 
distance_lat = 0.011997222900390625
spl_polygons = [spl.geometry.Polygon([(x - distance_lon, y - distance_lat), (x + distance_lon, y + distance_lat), (x - distance_lon, y + distance_lat), (x + distance_lon, y - distance_lat)]) for x,y in test_point]

The problem is the output looks like:

enter image description here

not like a rectangular polygon? What am I doing wrong?

Edit 3: The point which form the polygon have to be in the format of (lower left, lower right, upper right, upper left). Now I got the polygon in rectangular format.

Correction of last line:

spl_polygons = [spl.geometry.Polygon([(x - distance_lon, y - distance_lat), (x + distance_lon, y - distance_lat), (x + distance_lon, y + distance_lat), (x - distance_lon, y + distance_lat)]) for x,y in test_point]
7
  • 1
    please post at least a bit of code to show what you have tried
    – Leo
    Commented Feb 21, 2020 at 13:05
  • 1
    Does this answer your question? Creating square buffers around points using shapely?
    – Leo
    Commented Feb 21, 2020 at 13:06
  • No because I don't want a square polygon ;) Commented Feb 21, 2020 at 13:11
  • Buffer twice then envelope both buffers.
    – Bera
    Commented Feb 21, 2020 at 13:17
  • 1
    4th line- you've typed 'sitance ' instead of 'distance'
    – Ofir
    Commented Feb 21, 2020 at 13:47

1 Answer 1

1

You just need to create the bounding box of each feature you are creating. Take a look at this thread there is a sample on how to achieve that.

Find bounding box for multiple features using PyQGIS?

You could achieve that by creating top right point (Xmax,Ymax) and (Xmin,Ymin) and return the bounding box of the collection of the two points. This is the method I would use. However since you have started something and got results just use that resulting object to generate the bounding box.

Not the answer you're looking for? Browse other questions tagged or ask your own question.