Select to view content in your preferred language

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

625
1
02-25-2020 09:10 AM
JamalWest2
Regular 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;
mapFrameMap.SetCustomFullExtent(selectionEnvelope2);
mapFrame.SetCamera(selectionEnvelope2);

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
1 Reply
Asimov
by
Regular Contributor

I know it's an old topic, just in case someone ends up here: I think you just missed the actual call to Map.SetClipGeometry(), just before setting full extent. To put it in the same context of the example:

// Process the feature. For example...
var pin = feature[RTSNUM].ToString();
Geometry geo2 = feature.GetShape().Clone();
var selectionEnvelope2 = geo2.Extent;
mapFrameMap.SetClipGeometry(geo2 as Polygon, null);
mapFrameMap.SetCustomFullExtent(selectionEnvelope2);
mapFrame.SetCamera(selectionEnvelope2);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

0 Kudos