Apologize for the question but i am a beginner in programming.
I am trying to write a script in Python and automatically download and crop a specific area using gdalwarp (I tried with the clip tool without success: https://developers.planet.com/apis/orders/tools/#using-tools).
Although being able to get a clipped image, this is simply a black thumbnail (840KB).
The final goal would be just to download the cropped part.
At the moment I am downloading the full image and it creates the thumbnail mentioned above.
The coordinates were extracted with the geojson.io tool
Could be the problem related with the coordinate system (although the clipped image is quite small and let me think the issue is something else).
Â
Could you please advice what am I doing wrong?
Â
Below the code section:
# Clip the image using gldalwarp
clip_output_image = os.path.join(save_folder, "clipped_" + filename)
input_coordinates = "33.282952632083095, 34.94060635659089, 33.282952632083095, 34.94060635659089"
# Define the target coordinate system (UTM 36N)
target_srs = "EPSG:32636"
# Check if the file already exists, if yes, skip the clipping step
if os.path.exists(clip_output_image):
print("Clipped image already exists. Skipping gdalwarp.")
else:
cmd = =
gdalwarp_path,
"-te", *input_coordinates.split(","),
"-ts", "1000", "1000",
"-t_srs", target_srs, # Specify the target UTM coordinate system
save_path,
clip_output_image
]
# Construct the gdalwarp command
cmd = f"gdalwarp -te {input_coordinates} -ts 1000 1000 -t_srs {target_srs} {save_path} {clip_output_image}"
try:
# Execute the gdalwarp command using subprocess
exit_code = subprocess.run(cmd, check=True)
if exit_code.returncode == 0:
# gdalwarp command executed successfully
print("Image clipped and saved to:", clip_output_image)
else:
# gdalwarp command failed
print("gdalwarp command execution failed.")
except subprocess.CalledProcessError as e:
# Handle the error if the command fails
print(f"Error occurred while executing gdalwarp command: {e}")
print("Image was not clipped.")
Â