Upload
others
View
13
Download
0
Embed Size (px)
Citation preview
ArcGIS Pro SDK for .NET: Layer Customization and Layout CustomizationWolfgang Kaiser
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.
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()
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));
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);…
}
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
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);
});
Feature Layer: Advanced renderers
• For more advanced renderers use the RendererDefinition classes
method.
• Many RendererDefintion classes are available.
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.
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);
Demo: Renderers• Simple Renderer• Unique Value renderer• Procedural symbol renderer
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
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
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);});
Add Labels to Polygon Feature Class
Admin project
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.
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
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;
});
Layout Elements• Page Layout contains Layout Elements• Created by using LayoutElementFactory• Layout Element Examples:
- MapFrame- Legend- NorthArrow- PictureElement- ScaleBar- TextElement- TableFrame
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");});
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);
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… …
Demo – Create a Layout with code• Layout Map Series Data
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
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
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
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
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);
Demo – Layout with Map Series• Layout Map Series Data
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
Thank You to Our Sponsors