Is there a way to clip map to features via sdk?

02-25-2020 09:10 AM
Occasional Contributor

I am looking for a solution to a problem I have found. I want to clip my map to the shape of a feature that is either selected or a layer created with just one feature via query. I have found that when using feature.shape.clone() and then setting my map extent to that of the feature. The extent is slightly larger than the feature. If you open the Map properties in pro and clip to feature it will give a different extent.

Here is the code used.

LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Standard"));
Layout layout = layoutItem.GetLayout();
MapFrame mapFrame = layout.FindElement("FrameName") as MapFrame;
//Get map
var mapFrameMap = mapFrame.Map;
//Get the specific layer you want from the map
var lyrOfInterest = mapFrameMap.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();

using (RowCursor jCursor1 = ExtentFeatureClass.Search(queryFilter, true))
while (jCursor1.MoveNext())

var RTSNUM = "RTSNumber";
using (Feature feature = (Feature)jCursor1.Current)
// Process the feature. For example...
var pin = feature[RTSNUM].ToString();
Geometry geo2 = feature.GetShape().Clone();
var selectionEnvelope2 = geo2.Extent;

Below is the resulting map with the feature on top. As you can see the map extent is larger than the feature shape.

When using clip to shape in the map properties gui this is what I get. There is no data showing outside of the boundary. I need to know f there is a way to achieve this via sdk coding?

0 Kudos
0 Replies