Select to view content in your preferred language

Exporting MapFrame does NOT ignore width and height

420
3
Jump to solution
02-07-2024 07:46 AM
Asimov
by
New Contributor III

I am dealing with the task of exporting the content of a map frame to tif files, in order to use them as raster data. What I do is cycling through tile features and use them to clip the map, then set the camera on their extent and finally export the map frame with a TIFFFormat. 

Everywhere on API reference you can find that the ExportFormat Class ignores width and height when exporting a layout or map frame, but it's not what it actually happens to me (ArcGIS Pro 3.1).

Let's take this code snippet (assuming to be inside the cycle, with currentFeature and mapFrame instances already retrieved and within a QueuedTask.Run() statement):

 

//Setting new clip geometry
mapFrame.Map.ClearClipGeometry();
var currentFeatureGeometry = currentFeature.GetShape().Clone();
mapFrame.Map.SetClipGeometry(currentFeatureGeometry as Polygon, null);

//Setting camera on current feature extent
var def = mapFrame.GetDefinition() as CIMMapFrame;
def.View.Camera.Scale = 5000;
mapFrame.SetDefinition(def);
mapFrame.SetCamera(currentFeatureGeometry.Extent);

//Create TIFF format with appropriate settings
TIFFFormat TIFF = new TIFFFormat();
TIFF.Resolution = resolution; //This may vary, but in current test is 400 DPI
//TIFF.Height = height;
//TIFF.Width = width;
TIFF.ColorMode = TIFFColorMode.EightBitGrayScale;
TIFF.HasWorldFile = true;
TIFF.OutputFileName = Path.Combine(path, $"{idTile}");
TIFF.ImageCompression = TIFFImageCompression.Deflate;
TIFF.GeoReferenceMapFrameName = "CTR5 Map Frame";

//Export MapFrame
if (TIFF.ValidateOutputFilePath())
{
mapFrame.Export(TIFF);
}

 

Now, the ExportFormat reference page linked above (and pretty much every example and piece of information I was able to find) says that "When exporting a Layout or a MapFrame, the height and width are obtained from the size of the object in page units and the Height and Width properties are ignored. For example, if a MapFrame is 5 inches by 5 inches and the resolution is 300, the output image will be 1500 pixels by 1500 pixels and remain 5 inches by 5 inches."

What I actually get after exporting the Map Frame with the above code is an image centered on the Map Frame, with 960px width and height (960 is the default value for both properties), containing just a small part of the view. Morevover, If I set any other values for width and height, they are actually reflected into the resulting tif file, so they are definitely not ignored at all.

Currently the only way I found to solve the issue is to calculate image width and height starting from the extent. This is a workaround and it leads to other issues (i.e. for some tiles the calculated dimensions are a little bit smaller than the actual extent and I cannot really understand why).

Before going on with a full implementation of a workaround I'd like to understand whether the issue I'm facing is an actual bug of the Export method (at least for a MapFrame) or I missed something about it.

Any contribute is appreciated, thanks in advance.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JeffBarrette
Esri Regular Contributor

@Asimov I was able to reproduce on Pro 3.1 but NOT on Pro 3.2 (and even Pro 3.3).

Would you be able to test this against 3.2?

Jeff - Layout (SDK) and arcpy.mp teams.

View solution in original post

3 Replies
JeffBarrette
Esri Regular Contributor

@Asimov I was able to reproduce on Pro 3.1 but NOT on Pro 3.2 (and even Pro 3.3).

Would you be able to test this against 3.2?

Jeff - Layout (SDK) and arcpy.mp teams.

Asimov
by
New Contributor III

Hello @JeffBarrette, thanks for taking time to look into this. 

Before upgrading to 3.2 I need to check with the client if it's ok for them to upgrade. In the meantime I've been working on another project and I may not be able to get back to this before next week, but I will surely give you some feedback as soon as I can.

0 Kudos
Asimov
by
New Contributor III

Hi @JeffBarrette

I was finally able to upgrade to Pro 3.2 and I can confirm that the issue is gone: now Export function behaves as on documentation and ignores width and height, printing the extent with requested resolution.

Thanks for your support!

0 Kudos