ArcGIS Pro2.8插入公里网
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ArcGIS.Core.CIM; using ArcGIS.Core.Data; using ArcGIS.Core.Geometry; using ArcGIS.Desktop.Catalog; using ArcGIS.Desktop.Core; using ArcGIS.Desktop.Editing; using ArcGIS.Desktop.Extensions; using ArcGIS.Desktop.Framework; using ArcGIS.Desktop.Framework.Contracts; using ArcGIS.Desktop.Framework.Dialogs; using ArcGIS.Desktop.Framework.Threading.Tasks; using ArcGIS.Desktop.Layouts; using ArcGIS.Desktop.Mapping; namespace test { internal class addGrid : Button { protected override void OnClick() { //Given by UMA esri arcgis pro developer - better to customize accordingly var activeLayout = LayoutView.Active.Layout; QueuedTask.Run(() => { var layoutDefn = activeLayout.GetDefinition(); var gridLinesEastWest = new CIMGridLine { Name = "GridLines", ElementType = GridElementType.Line, GridLineOrientation = GridLineOrientation.EastWest, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), Pattern = new CIMGridPattern { Interval = 30, Start = 0, Stop = 1, Gap = 0 } }; var gridLinesNorthSouth = new CIMGridLine { Name = "GridLines", ElementType = GridElementType.Line, GridLineOrientation = GridLineOrientation.NorthSouth, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), Pattern = new CIMGridPattern { Interval = 30, Start = 0, Stop = 1, Gap = 0 } }; var gridTicksNorthSouth = new CIMGridLine { Name = "Ticks", ElementType = GridElementType.Tick, GridLineOrientation = GridLineOrientation.NorthSouth, Pattern = new CIMGridPattern { Interval = 30, Start = 0, Stop = 1, Gap = 0 }, FromTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), }, ToTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), }, }; var gridTicksEastWest = new CIMGridLine { Name = "Ticks", ElementType = GridElementType.Tick, GridLineOrientation = GridLineOrientation.EastWest, Pattern = new CIMGridPattern { Interval = 30, Start = 0, Stop = 1, Gap = 0 }, FromTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), }, ToTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), }, }; var gridTicksSmallEastWest = new CIMGridLine { Name = "Ticks 1", ElementType = GridElementType.Tick, GridLineOrientation = GridLineOrientation.EastWest, Pattern = new CIMGridPattern { Interval = 5, Start = 1, Stop = 6, Gap = 0 }, FromTick = new CIMExteriorTick { Length = 0.0277, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), }, ToTick = new CIMExteriorTick { Length = 0.0277, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), }, }; var gridTicksSmallNorthSouth = new CIMGridLine { Name = "Ticks 1", ElementType = GridElementType.Tick, GridLineOrientation = GridLineOrientation.NorthSouth, Pattern = new CIMGridPattern { Interval = 5, Start = 1, Stop = 6, Gap = 0 }, FromTick = new CIMExteriorTick { Length = 0.0277, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), }, ToTick = new CIMExteriorTick { Length = 0.0277, Offset = 0, IsVisible = true, Symbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), }, }; var gridLabelsEastWest = new CIMGridLine { Name = "Labels", ElementType = GridElementType.Label, GridLineOrientation = GridLineOrientation.EastWest, Pattern = new CIMGridPattern { Interval = 30, Start = 0, Stop = 1, Gap = 0 }, FromTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, GridEndpoint = new CIMGridEndpoint { GridLabelTemplate = new CIMSimpleGridLabelTemplate { DynamicStringTemplate = "<dyn type=\"grid\" units=\"dms\" decimalPlaces=\"0\" showDirections=\"True\" showZeroMinutes=\"False\" showZeroSeconds=\"False\"/>", //TODO Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 7, "Tahoma", "Regular")).MakeSymbolReference() }, Offset = 0.083, Position = 2, LineSelection = 7 } }, ToTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, GridEndpoint = new CIMGridEndpoint { GridLabelTemplate = new CIMSimpleGridLabelTemplate { DynamicStringTemplate = "", //TODO Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 0.5, "Tahoma", "Regular")).MakeSymbolReference() }, Offset = 0.083, Position = 2, LineSelection = 7 } } }; var gridLabelsNorthSouth = new CIMGridLine { Name = "Labels", ElementType = GridElementType.Label, GridLineOrientation = GridLineOrientation.NorthSouth, Pattern = new CIMGridPattern { Interval = 30, Start = 0, Stop = 1, Gap = 0 }, FromTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, GridEndpoint = new CIMGridEndpoint { GridLabelTemplate = new CIMSimpleGridLabelTemplate { DynamicStringTemplate = "<dyn type=\"grid\" units=\"dms\" decimalPlaces=\"0\" showDirections=\"True\" showZeroMinutes=\"False\" showZeroSeconds=\"False\"/>", //TODO Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 7, "Tahoma", "Regular")).MakeSymbolReference() }, Offset = 0.083, Position = 2, LineSelection = 7 } }, ToTick = new CIMExteriorTick { Length = 0.0694, Offset = 0, IsVisible = true, GridEndpoint = new CIMGridEndpoint { GridLabelTemplate = new CIMSimpleGridLabelTemplate { DynamicStringTemplate = "", //TODO Symbol = (SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 0.5, "Tahoma", "Regular")).MakeSymbolReference() }, Offset = 0.083, Position = 2, LineSelection = 7 } } }; var layoutGrid = new List<CIMMapGrid>(); var mapGrid = new CIMGraticule { Name = "Black Horizontal Label Graticule", IsVisible = true, MaxInteriorAngle = 150, EdgeMinimumLength = 1, GridLines = new CIMGridLine[] { gridLinesEastWest, gridLinesNorthSouth, gridTicksEastWest, gridTicksNorthSouth, gridTicksSmallEastWest, gridTicksSmallNorthSouth, gridLabelsEastWest, gridLabelsNorthSouth }, NeatlineSymbol = (SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 0.5, SimpleLineStyle.Solid)).MakeSymbolReference(), //Internal GeographicCoordinateSystem = new ArcGIS.Core.Internal.CIM.GeographicCoordinateSystem { WKT = "GEOGCS[\"GCS_North_American_1983\",DATUM[\"D_North_American_1983\",SPHEROID[\"GRS_1980\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433],AUTHORITY[\"EPSG\",4269]]", XOrigin = -400, YOrigin = -400, XYScale = 11258999068426.238, ZOrigin = -10000, ZScale = 10000, MOrigin = -10000, MScale = 10000, XYTolerance = 8.9831528411952133E-09, ZTolerance = 0.001, MTolerance = 0.001, HighPrecision = true, LeftLongitude = -180, WKID = 4269, LatestWKID = 4269 } }; var mapFrameElement = layoutDefn.Elements[0] as CIMMapFrame; //My layout has only one element mapFrameElement.Grids = new CIMMapGrid[] { mapGrid }; activeLayout.SetDefinition(layoutDefn); }); } } }