/// <summary> /// Selects the requested features from the specified layer and immediately disposes /// the selection to avoid selection and immediate de-selection (for selection method XOR) /// because it is called in 2 threads. /// </summary> /// <param name="featureLayer"></param> /// <param name="combinationMethod"></param> /// <param name="objectIds"></param> public static void SelectFeatures([NotNull] BasicFeatureLayer featureLayer, SelectionCombinationMethod combinationMethod, [NotNull] IReadOnlyList <long> objectIds) { var queryFilter = new QueryFilter { ObjectIDs = objectIds }; using (Selection selection = featureLayer.Select(queryFilter, combinationMethod)) { if (_msg.IsVerboseDebugEnabled) { _msg.VerboseDebug( $"Selected OIDs {StringUtils.Concatenate(selection.GetObjectIDs(), ", ")} " + $"from {featureLayer.Name}"); } } }
private async static void Visualize(BasicFeatureLayer dam3dLayer, BasicFeatureLayer reservoirVisLayer, BasicFeatureLayer reservoirSurfacesLayer, BasicFeatureLayer damLayer) { SharedFunctions.DeleteAllFeatures(reservoirVisLayer); SharedFunctions.DeleteAllFeatures(dam3dLayer); List <long> damIDs = new List <long>(); var reservoirPairsLayer = MapView.Active.Map.FindLayers("ReservoirPairs").FirstOrDefault(); if (reservoirPairsLayer != null && ((BasicFeatureLayer)reservoirPairsLayer).SelectionCount > 0) { var reservoirPairsCursor = ((BasicFeatureLayer)reservoirPairsLayer).GetSelection().Search(); while (reservoirPairsCursor.MoveNext()) { using (Row row = reservoirPairsCursor.Current) { int damId = (int)row["LowerDamId"]; if (!damIDs.Contains(damId)) { damIDs.Add(damId); } damId = (int)row["UpperDamId"]; if (!damIDs.Contains(damId)) { damIDs.Add(damId); } } } } if (damLayer.SelectionCount > 0) { var damCursor = damLayer.GetSelection().Search(); while (damCursor.MoveNext()) { using (Row row = damCursor.Current) { int damId = (int)row["ObjectID"]; if (!damIDs.Contains(damId)) { damIDs.Add(damId); } } } } List <CandidateDam> candidates = new List <CandidateDam>(); SharedFunctions.LoadDamCandidatesFromLayer(candidates, damLayer); foreach (var dam in candidates.Where(c => damIDs.Contains(c.ObjectID)).ToList()) { double contourHeight = dam.ContourHeight; try { MapPoint startPoint = dam.StartPoint; MapPoint endPoint = dam.EndPoint; double damHeight = (double)dam.DamHeight; double damLength = (double)dam.Length; Coordinate3D coord1 = startPoint.Coordinate3D; int factor = ((startPoint.Y <endPoint.Y && startPoint.X> endPoint.X) || (startPoint.Y > endPoint.Y && startPoint.X < endPoint.X) ) ? 1 : -1; Coordinate3D coord2 = new Coordinate3D(coord1.X + factor * damHeight / damLength * Math.Abs(startPoint.Y - endPoint.Y) //X , coord1.Y + damHeight / damLength * Math.Abs(startPoint.X - endPoint.X) //Y , coord1.Z - damHeight); //Z Coordinate3D coord3 = new Coordinate3D(coord1.X - factor * damHeight / damLength * Math.Abs(startPoint.Y - endPoint.Y) //X , coord1.Y - damHeight / damLength * Math.Abs(startPoint.X - endPoint.X) //Y , coord1.Z - damHeight); //Z //Workaround for Bug in ArcGIS Pro 2.4.1: if values are equal, extrusion will fail coord2.X += 0.1; coord2.Y += 0.1; coord3.X += 0.1; coord3.Y += 0.1; List <Coordinate3D> coords = new List <Coordinate3D>(); coords.Add(coord1); coords.Add(coord2); coords.Add(coord3); var newPolygon3D = PolygonBuilder.CreatePolygon(coords, SpatialReference); Coordinate3D coord = new Coordinate3D(endPoint.X - startPoint.X, endPoint.Y - startPoint.Y, 0.1); var multipatch = GeometryEngine.Instance.ConstructMultipatchExtrudeAlongVector3D(newPolygon3D, coord); var attributes2 = new Dictionary <string, object> { { "Shape", multipatch }, { "DamID", (long)dam.ObjectID } }; var createOperation2 = new EditOperation() { Name = "Create multipatch", SelectNewFeatures = false }; createOperation2.Create(dam3dLayer, attributes2); await createOperation2.ExecuteAsync(); //add SurfacePolygon to Visualization: var queryFilter = new QueryFilter { WhereClause = string.Format("DamID = {0}", dam.ObjectID) }; var surfaceCursor = reservoirSurfacesLayer.Select(queryFilter).Search(); if (surfaceCursor.MoveNext()) { using (Row row = surfaceCursor.Current) { var polygon = (row as Feature).GetShape() as Polygon; attributes2 = new Dictionary <string, object> { { "Shape", polygon }, { "DamID", (long)dam.ObjectID } }; var createOperationSurface = new EditOperation() { Name = "Create surface", SelectNewFeatures = false }; createOperationSurface.Create(reservoirVisLayer, attributes2); await createOperationSurface.ExecuteAsync(); } } } catch (Exception ex) { SharedFunctions.Log("Error for 3D Dam with DamID " + dam.ObjectID + ": " + ex.Message); } SharedFunctions.Log("3D Dam created for Dam " + dam.ObjectID); } await Project.Current.SaveEditsAsync(); }