You can do it easily with "arcpy" module in Python:
The important thing is that you have to read the spatial georeference system of the input raster, and create a polygon feature with the same spatial georeference system. You read the corners of the raster and add points to a polygon shape. Then you add the shape to your feature class.
This is the code for doing it.
import arcpy
import sys
import os
fp_inp = "C:\\raster\\raster.tif"
fp_out_dir, fp_out_name = "C:\\raster", "polygon.shp"
fp_out = os.path.join(fp_out_dir, fp_out_name)
if arcpy.Exists(fp_inp):
desc = arcpy.Describe(fp_inp)
spatialName, spatRef = "Unkown", None
if hasattr(desc, 'spatialReference'):
spatRef = desc.spatialReference
spatialName = desc.spatialReference.name
if spatialName != "" and spatialName != "Unkown":
arcpy.env.workspace = fp_out_dir
try:
arcpy.CreateFeatureclass_management(fp_out_dir, fp_out_name, 'POLYGON', spatial_reference=spatRef)
polygonSuc = True
except:
print("ERROR (126401236004)")
print(arcpy.GetMessages())
fieldsOk = False
if polygonSuc:
try:
arcpy.AddField_management(fp_out, "src", "TEXT", "", "", 254, "src",
"NULLABLE")
fieldsOk = True
except:
msg01 = "\n" + arcpy.GetMessages()
print(msg01)
corners = ["lowerLeft", "lowerRight", "upperRight", "upperLeft"]
ras = arcpy.Raster(fp_inp)
points_array = arcpy.Array()
for corner in corners:
pt = arcpy.Point(getattr(ras.extent, "%s" % corner).X, getattr(ras.extent, "%s" % corner).Y)
points_array.add(pt)
polygon_shape = arcpy.Polygon(points_array)
if fieldsOk:
with arcpy.da.InsertCursor(fp_out,
["SHAPE@", "src"]) as cursor:
cursor.insertRow([polygon_shape, "your raster name goes here"])
print("Inserted polygon into shapefile: " + fp_out)
points_array.removeAll()
array = None
else:
print("Input raster does not exist.")