I have been trying to convert one of Sentinel-5P (Sentinel-5P Data) dataset (viz. 'methane_mixing_ratio_precision') to GeoTIFF file. The plot of one of its dataset viz. 'methane_mixing_ratio_precision' using the below code is methane_mixing_ratio_precision:
import xarray
import matplotlib.pyplot as plt
netcdf_fname = r'C:\Users\User\Desktop\NC Files\CH4_1.nc'
xds = xarray.open_dataset(netcdf_fname, group='PRODUCT')
plt.figure(figsize=(14,8))
ax = plt.axes()
xds.methane_mixing_ratio_precision[0].plot.pcolormesh(ax=ax, x='longitude', y='latitude',add_colorbar=True, cmap='jet');
Till now I have successfully created a point shapefile (Point Shapefile) of the above mentioned dataset. Now I want to convert this point shapefile to polygon shapefile which then I can rasterize to get GeoTIFF file as shown in methane_mixing_ratio_precision.
Using @gene suggestion, I was successfully able to create a buffer (7Km x 7Km) around each point geometry using geopandas:
import geopandas as gpd
points = gpd.read_file(r'C:\Users\User\Desktop\NC Files\methane_mixing_ratio_precision_points.shp')
points.geometry= points.geometry.apply(lambda x: x.buffer(0.063, cap_style = 3))
points.to_file(r'C:\Users\User\Desktop\NC Files\methane_mixing_ratio_precision_points_buffer.shp')
What I basically want is to create a grid (inclined in nature) of (5.5 Km * 3.5 Km) around each point geometry and that grid should like Section of Methane Plot.
1 Answer 1
When you buffer the points GeoDataFrame with buffer = points.buffer
the columns of the original points are not preserved
points.head(3)
Param Lat Lon geometry
0 3.964342 5.185295 71.578270 POINT (71.57827 5.18530)
1 3.910507 5.206082 71.648300 POINT (71.64830 5.20608)
2 3.990862 5.226586 71.717873 POINT (71.71787 5.22659)
buffer = points.buffer(0.126, cap_style = 3)
buffer.head(3)
0 POLYGON ((71.70427 5.31130, 71.70427 5.05930, ...
1 POLYGON ((71.77430 5.33208, 71.77430 5.08008, ...
2 POLYGON ((71.84387 5.35259, 71.84387 5.10059, ...
A solution
# copy the original GeoDataFrame to preserve the columns
buffer = points.copy()
buffer.geometry= buffer.geometry.apply(lambda x: x.buffer(0.126, cap_style = 3))
buffer.head(3)
Param Lat Lon geometry
0 3.964342 5.185295 71.578270 POLYGON ((71.70427 5.31130, 71.70427 5.05930, ...
1 3.910507 5.206082 71.648300 POLYGON ((71.77430 5.33208, 71.77430 5.08008, ...
2 3.990862 5.226586 71.717873 POLYGON ((71.84387 5.35259, 71.84387 5.10059, ...
buffer.plot(column='Param')
-
Hi @gene. "from shapely.geometry import buffer" is throwing following error: "ImportError: cannot import name 'buffer' from 'shapely.geometry' (C:\Users\User\Anaconda3\envs\Sentinel-5P\lib\site-packages\shapely\geometry_init_.py)".RRSC NGP– RRSC NGP2022年05月25日 04:33:56 +00:00Commented May 25, 2022 at 4:33
-
-
@RRSCNGP What should I do when someone answers my question?Bera– Bera2025年06月01日 06:59:18 +00:00Commented Jun 1 at 6:59