private string GetDisplayField(FeatureClass featureClass) { string displayField = ""; Map map = MapView.Active.Map; if (map == null) { return(displayField); } //Get flattened layers from Map. If the feature class exists in the map, get that feature Layer and its display field. If not, return null. var layer = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(lyr => lyr.GetFeatureClass().GetName() == featureClass.GetName()); if (layer == null) { return(""); } CIMFeatureLayer currentCIMFeatureLayer = layer.GetDefinition() as CIMFeatureLayer; CIMFeatureTable cimFeatureTable = currentCIMFeatureLayer.FeatureTable; displayField = cimFeatureTable.DisplayField; return(displayField); }
private void GetLayerNode(Layer lyr, XmlDocument doc) { Layer plyr = MapView.Active.Map.FindLayer(lyr.URI, true); MapMember mm = lyr; XmlNode lnd; lnd = doc.SelectSingleNode("//Layers/String[text()='" + lyr.URI + "']"); CIMService cs = new MapMemberService((MapMember)lyr); //var xmlLayer = GetlayerDefinitionAsync(lyr); var xmlLayer = cs.GetDefinitionAsync(); XmlDocumentFragment xfrag = doc.CreateDocumentFragment(); xfrag.InnerXml = xmlLayer.Result; XmlNode nd = xfrag.FirstChild; switch (lyr.GetType().Name) { case "GroupLayer": lnd.AppendChild(xfrag); GroupLayer glyr = (GroupLayer)lyr; foreach (var layer in glyr.Layers) { lnd = doc.SelectSingleNode("//Layers/String[text()='" + lyr.URI + "']"); GetLayerNode(layer, doc); } break; case "FeatureLayer": var cfl = CIMFeatureLayer.FromXml(xmlLayer.Result); GetRenderer(cfl.Renderer, nd, ReportDir); lnd.AppendChild(nd); break; case "RasterLayer": var crl = CIMRasterLayer.FromXml(xmlLayer.Result); //GetRenderer(crl., nd, ReportDir); lnd.AppendChild(nd); break; case "StandaloneTable": lnd = doc.SelectSingleNode("//StandaloneTables/String[text()='" + lyr.URI + "']"); lnd.AppendChild(nd); break; default: lnd.AppendChild(nd); break; } }
private Task saveReport(string xml, string outputDir) { return(QueuedTask.Run(() => { var doc = new XmlDocument(); try { doc.LoadXml(xml); XmlNodeList nodelist = doc.ChildNodes; string str = ""; foreach (XmlNode node in nodelist) { XmlNode nd = node.SelectSingleNode("URI"); string _URIPath = nd.InnerText.Replace("CIMPATH=", ""); string _outPath = System.IO.Path.Combine(outputDir, System.IO.Path.GetDirectoryName(_URIPath)); string _URIFileName = System.IO.Path.GetFileNameWithoutExtension(_URIPath); string _URIimgPath = System.IO.Path.Combine(_outPath, "img\\" + _URIFileName); //string fname = nd.InnerText.Replace("CIMPATH=", "").Replace("/", "_").Replace(".xml", ""); switch (node.Name) { case "CIMFeatureLayer": var cfl = CIMFeatureLayer.FromXml(xml); GetRenderer(cfl.Renderer, node, outputDir); str = TransformDocument(doc.InnerXml, System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), @"Stylesheet\CIMFeatureLayer.xslt"), System.IO.Path.Combine(_outPath, _URIFileName)); break; case "CIMMap": str = TransformDocument(xml, System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), @"Stylesheet\CIMMap.xslt"), System.IO.Path.Combine(_outPath, _URIFileName)); exportMapContent(xml, outputDir); break; case "CIMGroupLayer": str = TransformDocument(xml, System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), @"Stylesheet\CIMGroupLayer.xslt"), System.IO.Path.Combine(_outPath, _URIFileName)); break; default: str = TransformDocument(xml, System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), @"Stylesheet\CIMFeatureLayer.xslt"), System.IO.Path.Combine(_outPath, _URIFileName)); break; } } return doc; } catch (System.Xml.XmlException xmle) { return null; } })); }
/// <summary> /// Create a label for the weather feature layer. /// </summary> /// <param name="weatherLayer"></param> public static void SetLabeling(FeatureLayer weatherLayer) { // Get the CIMFeatureLayer definition. CIMFeatureLayer weatherLayerDefinition = weatherLayer.GetDefinition() as CIMFeatureLayer; // Get the label classes - we need the first one CIMLabelClass weatherLabelClass = weatherLayerDefinition.LabelClasses.FirstOrDefault(); if (weatherLabelClass != null) { // Create a new Arcade label expression. if (DamlSettings.Default.Celius) { weatherLabelClass.Expression = "$feature.Temperature + \" c \\r\" +$feature.Humidity + \" % \""; } else { weatherLabelClass.Expression = "(($feature.Temperature * 1.8) + 32)+ \" F \\r\" +$feature.Humidity + \" % \""; } // Create a polygon symbol for the halo CIMPolygonSymbol textHalo = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.WhiteRGB, SimpleFillStyle.Solid); // Create text symbol using the halo polygon CIMTextSymbol weatherTextSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 14, "Corbel", "Regular"); weatherTextSymbol.HaloSymbol = textHalo; weatherTextSymbol.HaloSize = 1; weatherTextSymbol.HaloSymbol.SetOutlineColor(ColorFactory.Instance.WhiteRGB); // Set the text symbol weatherLabelClass.TextSymbol.Symbol = weatherTextSymbol; // Update the layer definition weatherLayer.SetDefinition(weatherLayerDefinition); } }
/// <summary> /// Finds all related children /// </summary> public HierarchyRow GetRelationshipChildren(Layer member, Geodatabase gdb, string featureClassName, long objectID, string rcException = "") { if (!QueuedTask.OnWorker) { throw new CalledOnWrongThreadException(); } string displayValue = ""; if (member != null) { if (string.IsNullOrEmpty(_displayFieldName)) { CIMFeatureLayer currentCIMFeatureLayer = member.GetDefinition() as CIMFeatureLayer; _displayFieldName = currentCIMFeatureLayer?.FeatureTable.DisplayField ?? ""; } var inspector = new Inspector(); inspector.Load(member, objectID); if (!string.IsNullOrEmpty(_displayFieldName)) { displayValue = $"{inspector[_displayFieldName]?.ToString() ?? ""}"; } } //Did the display value get set? if (string.IsNullOrEmpty(displayValue)) { displayValue = $"OID: {objectID.ToString()}"; } var newHRow = new HierarchyRow() { name = displayValue, type = $"{featureClassName}" }; //Check the layer for any relationships var children = GetRelationshipChildrenFromLayer(member as BasicFeatureLayer, objectID); if (children.Count > 0) { newHRow.children = children; return(newHRow);//Give layer related precedence over GDB related } //If we are here we do not have any relates on the layer //See if we have relates in the GDB var relationshipClassDefinitions = GetRelationshipClassDefinitionsFromFeatureClass(gdb, featureClassName); foreach (var relationshipClassDefinition in relationshipClassDefinitions) { var rcName = relationshipClassDefinition.GetName(); //get the name if (rcException == rcName) //exception so we don't go in circles { continue; } //Alternate way of getting the features classes in the relationship (new at 1.3): //IReadOnlyList<Definition> definitions = GetRelatedDefinitions(relationshipClassDefinition, DefinitionRelationshipType.DatasetsRelatedThrough); var relationshipClass = gdb.OpenDataset <RelationshipClass>(rcName); //open the relationship class var origin = relationshipClassDefinition.GetOriginClass(); //get the origin of the relationship class var destination = relationshipClassDefinition.GetDestinationClass(); //get the destination of the relationship class string displayName; if (origin == featureClassName) { //the feature class is the origin. So we need the rows in the destination related to the origin var oids = new List <long> { objectID }; IReadOnlyList <Row> relatedOriginRows = relationshipClass.GetRowsRelatedToOriginRows(oids); if (relatedOriginRows.Count > 0) { displayName = string.Format("{0}: {1}", rcName, destination); var childHRow = new HierarchyRow() { name = displayName, type = rcName }; foreach (var row in relatedOriginRows) { //var lyr = GetRelationshipClassDefinitionsFromFeatureClass(); //childHRow.children.Add(GetRelationshipChildren(lyr, gdb, destination, row.GetObjectID(), rcName)); //recursive: to get the attributes of the related feature } newHRow.children.Add(childHRow); continue; } } IReadOnlyList <Row> relatedDestinationRows = relationshipClass.GetRowsRelatedToDestinationRows(new List <long> { objectID }); //Feature class is the destination so get the rows related to it if (relatedDestinationRows.Count > 0) { displayName = string.Format("{0}: {1}", rcName, origin); var childHRow = new HierarchyRow() { name = displayName, type = rcName }; foreach (var row in relatedDestinationRows) { //childHRow.children.Add(GetRelationshipChildren(null, gdb, origin, row.GetObjectID(), rcName)); } newHRow.children.Add(childHRow); } } return(newHRow); }