I'm working on a script where I create a grid with the bounding box of a geodataframe, a width and a height (they might be equals for a square grid).
I don't know why but when I try to make a 10m square grid my script generate a 7m square grid.
All my process works with geodataframe in Pseudo Mercator (3857) who have meter for unit.
Here is the piece of script for the grid:
Xmin, Ymin, Xmax, Ymax = buffer_CH.total_bounds # coordonées de la bounding box du buffer de l'enveloppe concave
cols = abs(int((Xmax - Xmin) / W))+1 # nombre de colonnes
rows = abs(int((Ymin - Ymax) / H))+1 # nombre de lignes
XleftOri, XrightOri, Ybottom, Ytop = Xmin, Xmin+W, Ymin, Ymin+H
polygons = []
print(XleftOri, XrightOri, Ybottom, Ytop)
for r in range(rows):
Xleft = XleftOri
Xright = XrightOri
for c in range(cols):
polygon = Polygon([(Xleft,Ybottom),(Xright,Ybottom),(Xright,Ytop),(Xleft,Ytop)])
polygons.append(polygon)
Xleft = Xright
Xright += W
Ybottom = Ytop
Ytop += H
grid = gpd.GeoDataFrame({'geometry':polygons})
grid.crs = {'init': 'epsg:3857'}
grid.to_file("{0}/{1}_{2}_zonage-carre/{3}-grid.shp".format(os.chdir, date, folder_name, shp_name))
Issue seems to come from this operation:
rotate_grid = grid.rotate(angleinverse, origin=(0,0), use_radians=False) # Rotation
rotate_grid = gpd.GeoDataFrame(rotate_grid) # Conversion de la GeoSerie en GeoDataFrame
rotate_grid = rotate_grid.rename(columns={0:'geometry'}).set_geometry('geometry') # Identification de la colonne geometry
rotate_grid.crs = {'init': 'epsg:3857'} # attribution du crs
rotate_grid.to_file("{0}/{1}_{2}_zonage-carre/{3}-RotateGrid.shp".format(os.chdir, date, folder_name, shp_name))