0

I have a raster data set I imported to ArcGIS from a netCDF file. ArcGIS doesn't read the projection or extent correctly due to issues with the input file. However, I have the correct values for these parameters. Using the Define Projection tool, I am able to set the coordinate system without issue. However, the raster appears in the wrong place on the map (centered at (0,0)).

Map of CONUS appears centered at (0,0)

I am looking for an ArcPy tool that would allow me to define the extent of the raster manually in the same way that I can define the projection using Define Projection.

What I have tried:

  • I can manually edit the extent in the properties window. However, I need to update the extent for 100s of these files, so need a scriptable/arcpy solution.
  • I looked at the Set Raster Properties tool. Although the Get Raster Properties tool can access the extent values (Top, Left, Right, Bottom), it does not appear that Set Raster Properties allows the extent properties to be modified.
  • The Shift tool alone won't work because the dimensions of the raster need to be adjusted in addition to location.

Edit:

I was using the wrong projection definition. When I use the right one, the map is displayed in the correct location. Among other clues, a curved Canadian border on a Mercator projection (ugg) is pretty obviously wrong, in retrospect.

enter image description here

7
  • If the dataset doesn't have any readable metadata, then I have to wonder it you really ought to try to re-obtain the information. It shouldn't be this hard to use. If you have to define and shift every file, what else is about to become an issue?
    – Vince
    Commented May 25, 2022 at 12:42
  • This is a custom netCDF output from another process, and the projection/extent errors are a known issue that should be addressed upstream, but that's going to take longer to address and would involve redoing some significant computation. I'm hoping there is an easier workaround in the meantime.
    – nrp1000
    Commented May 25, 2022 at 12:47
  • You can use Shift to shift location.
    – Vince
    Commented May 25, 2022 at 12:54
  • Ha, thanks, I found that as well and I was just editing my question to reflect that I don't think that alone will work. Perhaps it can be combined with Scale, though? It really feels like there should be an analog here for Define Projection for the extent.
    – nrp1000
    Commented May 25, 2022 at 12:57
  • 1
    Again, it shouldn't be this hard, and most folks don't need to work this much get their data usable.
    – Vince
    Commented May 25, 2022 at 13:34

2 Answers 2

0

This turned out to be a case of a projection issue (see my edits). As noted by Vince, this shouldn't be this hard. Nevertheless, I was interested to see whether I could use ArcPy to achieve the same results as editing the extent manually in the raster properties window. I was able to do so using the Shift and Rescale tools.

in_rast = "my_raster.tif"
out_rast_temp = "my_raster_temp.tif"
out_rast_extent = "my_raster_extent.tif"

top_correct = 6728275.583
left_correct =-14246503.87
right_correct = -7270751.753
bottom_correct = 2654659.006

x_dim_correct = right_correct - left_correct
y_dim_correct = top_correct - bottom_correct

top_wrong = float(arcpy.GetRasterProperties_management(in_rast, "TOP").getOutput(0))
left_wrong = float(arcpy.GetRasterProperties_management(in_rast, "LEFT").getOutput(0))
right_wrong = float(arcpy.GetRasterProperties_management(in_rast, "RIGHT").getOutput(0))
bottom_wrong = float(arcpy.GetRasterProperties_management(in_rast, "BOTTOM").getOutput(0))

x_dim_wrong = right_wrong - left_wrong
y_dim_wrong = top_wrong - bottom_wrong

x_shift = left_correct - left_wrong
y_shift = bottom_correct - bottom_wrong

x_scale = x_dim_correct/x_dim_wrong
y_scale = y_dim_correct/y_dim_wrong

arcpy.Shift_management(in_raster=in_rast, out_raster=out_rast_temp, x_value=x_shift, y_value=y_shift, in_snap_raster="")
arcpy.Rescale_management(in_raster=out_rast_temp, out_raster=out_rast_extent, x_scale=x_scale, y_scale=y_scale)

Result after running Shift:

Shift result

Result after running Rescale:

Rescale result

The result has an extent that is identical to the input "correct" extent.

Output extent

Again, this is probably the wrong way to go 90% of the time (vs. checking for upstream issues), but perhaps this can be useful in some situations.

0

Two things:

  1. Thanks, nrp1000 for your solution. I had been trying to write a script to automate georeferencing of 100+ .tiff files and this workflow slotted in just about perfectly.

  2. For anyone that comes along with a similar problem that they need to batch/loop process, you'll need to get extents, Rescale, get new extents, and then Shift.

1
  • Welcome to GIS SE. This section is only meant for answers. Please avoid thanking in answers. Your post is appropriate as a comment. Once you have sufficient reputations you can comment.
    – Padmanabha
    Commented Aug 11, 2023 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.