32
ArcGIS Pro SDK for .NET: Layer Customization and Layout Customization Wolfgang Kaiser

ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

  • Upload
    others

  • View
    25

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

ArcGIS Pro SDK for .NET: Layer Customization and Layout CustomizationWolfgang Kaiser

Page 2: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Session Overview• Feature Layer

- Feature Layer Creation- Feature Layer Renderers

- Simple Renderer- Unique Value Renderer- Procedural Symbol Renderer

- Feature Layer Labelling• Creating Layouts using the ArcGIS Pro API

- Using the Layout class to create a Page Layout- Using Layout Elements to provide Page Layout content.

Page 3: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Map and Feature Layer

• Map is a container of Layers and Tables.• Map has properties and methods to access Layers and Tables.

• FeatureLayer is derived from Layer. - Based on vector geographic data- Allows you to draw the underlying features

var layers = map.Layers;var tables = map.StandaloneTables;

//Convenience method to return all layers without group layerslayers = map.GetLayersAsFlattenedList()

Page 4: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Feature Layer Creation: Layer Factory• Create and Add Layer to Active Map: LayerFactory class

• Layers can be created with Renderers all in one shot with the LayerFactory

var map = MapView.Active.Map;return QueuedTask.Run(() => {

LayerFactory.CreateFeatureLayer(new Uri(@"c:\data\countydata.gdb\counties"), map,layerName: "Population Density (sq mi) Year 2010",rendererDefinition: new GraduatedColorsRendererDefinition("POP10_SQMI"));

});

/* string url = @"c:\data\project.gdb\DEM"; //Raster File GDB* string url = @"c:\connections\mySDEConnection.sde\roads"; //SDE FeatureClass* string url = @"c:\data\roads.shp"; //Shapefile* string url = @"https://...arcgisonline.com/../services/LandMarks/FeatureServer/0"; */string url = @"c:\data\project.gdb\roads"; //File GDB FeatureClassUri uri = new Uri(url);await QueuedTask.Run(() => LayerFactory.Instance.CreateLayer(uri, MapView.Active.Map));

Page 5: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Feature Layer Renderer• Feature layers have a renderer. • The renderer controls the layer symbology and how it is applied

when the layer is displayed.

public class FeatureLayer : BasicFeatureLayer {…

public FeatureClass GetFeatureClass();…

public CIMRenderer CreateRenderer(RendererDefinition rendererDefinition);public CIMRenderer GetRenderer();public void RecalculateRenderer();public void SetRenderer(CIMRenderer updatedRenderer);…

}

Page 6: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Feature Layer Renderers

• API provides various methods to create renderers.• This session focuses on the following renderers:

- Simple renderer- Advanced renderers:

- Unique value renderer- Procedural Symbols

Page 7: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Feature Layer Renderer: Simple Renderer

• Create a simple renderer (same symbol for all features):

await QueuedTask.Run(() => {CIMStroke outline = SymbolFactory.ConstructStroke(

ColorFactory.BlueRGB, 2.0, SimpleLineStyle.Solid);CIMPolygonSymbol fillWithOutline = SymbolFactory.ConstructPolygonSymbol(

ColorFactory.RedRGB, SimpleFillStyle.Solid, outline);

CIMSimpleRenderer simpleRenderer = layer.GetRenderer() as CIMSimpleRenderer;

//Update the symbol of the current simple renderersimpleRenderer.Symbol = fillWithOutline.MakeSymbolReference();

//Update the feature layer rendererlayer.SetRenderer(simpleRenderer);

});

Page 8: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Feature Layer: Advanced renderers

• For more advanced renderers use the RendererDefinition classes

method.

• Many RendererDefintion classes are available.

Page 9: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Feature Layer Renderer: Unique Value Renderer

await QueuedTask.Run(() => {//construct unique value renderer definitionUniqueValueRendererDefinition uvr = new

UniqueValueRendererDefinition() {ValueFields = new string[] {"Parcel type"},ColorRamp = colorRamp.ColorRamp

};

//set the renderer to the feature layerlayer.SetRenderer(layer.CreateRenderer(uvr));

});

• Define a new RendererDefinition.

• Call Feature Layer’s CreateRenderer method with the

RendererDefinition to get a CIMRenderer.

• Call SetRenderer on Feature Layer with the CIMRenderer.

Page 10: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Feature Layer Renderer: Procedural Symbols

• Create a symbol reference with a procedural symbol layer for a rule package.

//Creating a procedural symbol using the rulepackage - new method at 1.4var symbolReference = SymbolFactory.ConstructProceduralSymbol(_rulePkgPath,

Module1.Layer, primitiveOverrides.ToArray());

CIMPolygonSymbol polygonSymbol = symbolReference.Symbol as CIMPolygonSymbol;

//Set symbol's real world setting to be the same as that of the feature layerpolygonSymbol.SetRealWorldUnits(Module1.Layer.UsesRealWorldSymbolSizes);

//Set the current renderer to the new procedural symbol's CIMSymbolReferencerenderer.Symbol = polygonSymbol.MakeSymbolReference();

//Set the Building footprint layer's render. Module1.Layer.SetRenderer(renderer);

Page 11: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Demo: Renderers• Simple Renderer• Unique Value renderer• Procedural symbol renderer

Page 12: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Feature Layer: Labels• FeatuerLayer contains a CIMFeatureLayer

• CIM= Cartographic Information Model

• FeatuerLayer exposes the most commonly used aspects of a

feature layer as properties and methods, the remaining properties

and methods are available via CIMFeatureLayer

• How to access CIMFeatureLayer• FeatureLayer.GetDefinition () to get CIMFeatureLayer

• FeatureLayer.SetDefinition (CIMFeatureLayer) to apply changes

Page 13: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Feature Layer: Labels• CIMLabelClass to make changes to Labeling

• CIMFeatureLayer.LabelClasses to access array of labels

• CIMLabelClass.ExpressionEngine sets the ‘language’

• CIMLabelClass.Expression sets the label expression

• FeatureLayer. SetLabelVisibility turns labels on

https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-

Labeling

Page 14: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Feature Layer: Set ‘Arcade’ label expression

• Label change must run on the MCT – Main CIM Thread, hence we use QueuedTaskQueuedTask.Run(() => {//Get the layer's definitionvar lyrDefn = featLyr.GetDefinition() as CIMFeatureLayer;if (lyrDefn == null) return;//Get the first label class and update itvar labelClass = lyrDefn.LabelClasses[0];//set the label class Expression to use the Arcade expressionlabelClass.ExpressionEngine = LabelExpressionEngine.Arcade;labelClass.Expression = @"return $feature.STATE_NAME + TextFormatting.NewLine

+ 'Population:' + $feature.POP2000;";//Set the label definition back to update the feature layerfeatLyr.SetDefinition(lyrDefn);

// turn labelling onfeatLyr.SetLabelVisibility(true);});

Page 15: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Add Labels to Polygon Feature Class

Admin project

Page 16: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Creating Layouts using the ArcGIS Pro API• What is a layout?

- A page layout (aka layout) is a collection of one or more map elements organized on a virtual page designed for map printing.

- Layouts also include supporting elements, such as a title, a legend, and descriptive text.

Page 17: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Layout class• Layout class represents a Page Layout in a Project

• Created by using LayoutFactory.Instance.CreateLayout

• Layout Class provides access to basic layout properties- Page information (page dimensions like size, unit)- Layout Element management (add, delete elements like text, map)

- Export methods

Page 18: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Layout Class Creation• Pattern to create a new Layout

- With page size, unit, and layout name

Layout layout = await QueuedTask.Run<Layout>(() =>{

Layout lyt = LayoutFactory.Instance.CreateLayout (8.5, 11, LinearUnit.Inches);lyt.SetName ("Layout sample");return lyt;

});

Page 19: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Layout Elements• Page Layout contains Layout Elements• Created by using LayoutElementFactory• Layout Element Examples:

- MapFrame- Legend- NorthArrow- PictureElement- ScaleBar- TextElement- TableFrame

Page 20: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Layout Element Creation• Using LayoutElementFactory class to create any Element• Create MapFrame: LayoutElementFactory.Instance.CreateMapFrame

LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("My Layout"));

QueuedTask.Run(() => {Layout layout = layoutItem.GetLayout();// Build envelope geometry for map frameEnvelope mf_env = EnvelopeBuilder.CreateEnvelope(new Coordinate2D(6.0, 8.5),

new Coordinate2D(8.0, 10.5));// Reference map, create MF and add to layoutMapProjectItem mapPrjItem = Project.Current.GetItems<MapProjectItem>().

FirstOrDefault(item => item.Name.Equals("Map"));Map mfMap = mapPrjItem.GetMap();

MapFrame mfElm = LayoutElementFactory.Instance.CreateMapFrame(layout, mf_env, mfMap);

mfElm.SetName("New Map Frame");});

Page 21: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Layout Element Coordinates

// Build envelope geometry for map frameEnvelope mf_env = EnvelopeBuilder.CreateEnvelope

(new Coordinate2D(4.0, 4.5),new Coordinate2D(8.0, 10.5));

// Add map frame to layoutMapFrame mfElm = LayoutElementFactory.

Instance.CreateMapFrame(layout, mf_env, mfMap);

Page 22: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Layout Element CreationLayout Element Method to create Layout ElementMapFrame LayoutElementFactory.Instance.CreateMapFrameLegend LayoutElementFactory.Instance.CreateLegendNorthArrow LayoutElementFactory.Instance.CreateNorthArrowPictureElement LayoutElementFactory.Instance.CreatePictureElementScaleBar LayoutElementFactory.Instance.CreateScaleBarTextElement LayoutElementFactory.Instance.CreateTextElementTableFrame LayoutElementFactory.Instance.CreateTableFrame… …

Page 23: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Demo – Create a Layout with code• Layout Map Series Data

Page 24: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Layout Creation using a Spatial Map Series• What is a Spatial Map Series?

- Collection of map pages built from a single layout that represents a geographic area

LayoutData

IndexLayer

Map Pages

Page 25: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Layout Creation using a Spatial Map Series• Spatial Map Series used in the next demo

- Collection of ‘service area’ map pages built from a single layout that follow the course of railroad tracks

Page 26: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Layout class & CIMLayout class• Layout contains a CIMLayout

- Layout exposes the most commonly used aspects of a layout page as properties and methods, the remaining properties and methods are available via CIMLayout

• Access to CIMLayout- Use Layout.GetDefinition () to get the CIMLayout- Use Layout.SetDefintion (changed CIMLayout) to update the CIMLayout

Page 27: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

CIMSpatialMapSeries class• The CIMLayout.CIMSpatialMapSeries property is used to define a spatial map series

• Define a spatial map series:- Create a new CIMSpatialMapSeries instance with the following

minimal settings- IndexLayerURI: used to define the CIMPath for the index polygon for the

series (example: "CIMPATH=map/railroadmaps.xml“)- SortField: sequence and sort field (in IndexLayerURI) to uniquely define

each page in the series- CurrentPageId: current page of the map series displayed in layout view

using the IndexLayerURI.SortField values- RotationField: name of field in IndexLayerURI used to ‘rotate’ each page

in map series

Page 28: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Layout: Enable Spatial Map Series• Sample snippet to create a map series for a layout

var CimSpatialMapSeries = new CIMSpatialMapSeries(){

Enabled = true,StartingPageNumber = 1,CurrentPageID = 1,IndexLayerURI = "CIMPATH=map/railroadmaps.xml",SortField = "SeqId",RotationField = "Angle",…

};// set the map series definition in the layoutCIMLayout layCIM = layout.GetDefinition();layCIM.MapSeries = CimSpatialMapSeries;layout.SetDefinition(layCIM);

Page 29: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Demo – Layout with Map Series• Layout Map Series Data

Page 30: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

ArcGIS Pro SDK for .NET Tech Sessions

Date Time Technical Session Location

Tue, 23. Oct13:00 – 13:45 Beginning Pro Customization and Extensibility B 07 - B 08

15:00 – 15:45 Map Interaction and MVVM B 05

Wed, 24. Oct

09:00 – 09:45 Beginning Editing B 05

10:00 – 10:45 Advanced Editing B 05

13:00 – 13:45 Layer Customization and Layout Customization B 07 - B 08

14:00 – 14:45 Advanced Pro Customization and Extensibility A 03 - A 04

Thu, Mar 0810:00 – 10:45 Beginning Pro Customization and Extensibility A 03 - A 04

15:00 – 16:00 Road Ahead C 01

Page 31: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’

Thank You to Our Sponsors

Page 32: ArcGIS Pro SDK for .NET: Layer Customization and Layout ......Layout Creation using a Spatial Map Series • Spatial Map Series used in the next demo - Collection of ‘service area’