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]
Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
till Kadabra
  • 471
  • 6
  • 15

1 Answers1

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.

GforGIS
  • 3,126
  • 3
  • 19
  • 38