Clipping the Data Frame by ArcObjects

558
4
01-20-2011 09:49 PM
PetrPokorny
New Contributor
Hi.
I would like to implement map clipping functionality. There is a simple way to do it in ArcMap as described here.
Do you now what is the right ArcObjects interface which sets the clipping shape? I have been looking the documentation back and forth but I can't find it.
Thanks.
0 Kudos
4 Replies
NeilClemmons
Regular Contributor III
I believe IDisplay.ClipGeometry is what you're looking for but I've never tried it.
0 Kudos
PetrPokorny
New Contributor
Neil, thanks for your idea. I will try it ASAP.

By the time I have found out IMap.ClipGeometry. I don't know how I could miss it for the first time.

However I am not able to get it working. Whatever geometry I set, the returned image is still the same and no clipping is applied. Does any one know what else needs to be done? Unfortunately the documentation promises example but doesn't provide any.

Here is the important piece of my code.

ESRI.ArcGIS.Carto.IMapServer mapServer = (ESRI.ArcGIS.Carto.IMapServer)serverContext.ServerObject;
ESRI.ArcGIS.Carto.IMapServerObjects2 mapServerObjects = (ESRI.ArcGIS.Carto.IMapServerObjects2)mapServer;
string mapName = mapServer.DefaultMapName;
ESRI.ArcGIS.Carto.IMap map = mapServerObjects.get_Map(mapName);
map.ClipGeometry = GetClippingGeometry();
mapServerObjects.RefreshServerObjects();

ESRI.ArcGIS.Carto.IImageType imageType = serverContext.CreateObject("esriCarto.ImageType") as ESRI.ArcGIS.Carto.IImageType;
ESRI.ArcGIS.Carto.IImageDescription imageDescription = serverContext.CreateObject("esriCarto.ImageDescription") as ESRI.ArcGIS.Carto.ImageDescription;
ESRI.ArcGIS.Carto.IImageDisplay imageDisplay = serverContext.CreateObject("esriCarto.ImageDisplay") as ESRI.ArcGIS.Carto.ImageDisplay;

imageType.Format = ESRI.ArcGIS.Carto.esriImageFormat.esriImagePNG;
imageType.ReturnType = ESRI.ArcGIS.Carto.esriImageReturnType.esriImageReturnMimeData;
imageDisplay.Height = 800;
imageDisplay.Width = 60;
imageDisplay.DeviceResolution = 96;
imageDescription.Display = imageDisplay;
imageDescription.Type = imageType;

ESRI.ArcGIS.Carto.IMapServerInfo mapServerInfo = mapServer.GetServerInfo(mapServer.DefaultMapName);
ESRI.ArcGIS.Carto.IMapDescription aoMapDescription = mapServerInfo.DefaultMapDescription; 
ESRI.ArcGIS.Carto.IImageResult mapImage = mapServer.ExportMapImage(aoMapDescription, imageDescription);
return mapImage.MimeData;
0 Kudos
PetrPokorny
New Contributor
Do you know how to easily use IDisplay to affect the image exported from IMapServer? I can see that it only works with IImageDisplay which doesn't have any property like IDisplay.ClipGeometry.

Btw. I would like to add a small comment to the code in my previous post.
If I specify the clipping geometry in ArcMap and publish the service then the images are clipped by that geometry. Of course I have to drop these two lines of code.
map.ClipGeometry = GetClippingGeometry();
mapServerObjects.RefreshServerObjects();

But if I do not set the clipping geometry via ArcMap, create the service and uncomment those two lines then the clipping is not applied.
This makes me believe that the drawing part is correct and the problem is in those two lines.
0 Kudos
johannesuhl
New Contributor
Hey there,
just in order to complete the thread:
Clipping the data frame works fine for me passing an IPolygon object to IMap.ClipGeometry using pMxDoc.ActiveView.Refresh() afterwards.

pmap = pMxDoc.FocusMap
pmap.ClipGeometry = pClipGeom
pMxDoc.ActiveView.Refresh()

Cheers,
Johannes
0 Kudos