I'm trying to create sites using lat/long or easting/northing; however, when creating using Python it doesn't make the Pie correctly and sometimes the code fails totally. Can someone please guide me how can I make it using Python? Below is the code I used.
```
def create_sector_pie(row):
try:
azimuth = row['AZIMUTH']
beamwidth = row['BW']
radius = row['Radius']
# Calculate sector angles
start_angle = azimuth - beamwidth / 2
end_angle = azimuth + beamwidth / 2
# Create a sector polygon as a pie shape
center = (row['EASTING'], row['NORTHING']) # Use Easting and
Northing
polygon_coords = [(center[0], center[1])]
angle_step = radians(0.5) # Increase this value for less
detailed sectors
for angle in np.arange(start_angle, end_angle, angle_step):
x = center[0] + radius * cos(angle)
y = center[1] + radius * sin(angle)
polygon_coords.append((x, y))
polygon_coords.append((center[0], center[1])) # Close the
polygon
# Create a sector polygon
polygon = Polygon(polygon_coords)
# Smaller angle step
angle_step = radians(0.5)
# Buffer
polygon = polygon.buffer(0.001)
# Simplify
polygon = polygon.simplify(tolerance=0.001)
# Increase radius
radius = radius * 3
if not polygon.is_valid:
polygon = polygon.buffer(0)
return polygon
except Exception as e:
# Print the error and the row causing the issue for debugging
print(f"Error: {e}")
print(f"Row data causing the issue:\n{row}")
return None
# Apply the create_sector_pie function
data['geometry'] = data.apply(create_sector_pie, axis=1)
# Filter out rows with None in the 'geometry' column
data = data.dropna(subset=['geometry'])
columns_to_convert = ['CSR', 'CELL_ID', 'SECTOR', 'MI_MYCOM_ID',
'GENERATION', 'CELL_TYPE',
'FDD', 'CELL_3G_CARRIER', 'EASTING', 'NORTHING',
'GROUND_HEIGHT', 'AZIMUTH',
'AREA', 'JV_ID', 'PCI', 'TAC', 'Band', 'BW',
'Radius']
data[columns_to_convert] = data[columns_to_convert].astype(str)
#print(data.dtypes)
# Create a GeoDataFrame
gdf = gpd.GeoDataFrame(data, geometry='geometry')
gdf.crs = 'EPSG:27700'
# Define the output file path including the folder
tab_file = os.path.join(output_folder, 'N5_sectors.tab')
# Save the GeoDataFrame as a MapInfo TAB file
gdf.to_file(tab_file, driver='MapInfo File')
```
Please check above code and guide me how to fix it.