/// <summary> /// Get the list of selected features GUID from the layer /// </summary> /// <param name="fl">Layer</param> /// <param name="selectedFeatures">Selected features</param> /// <returns>List of GUID</returns> private static List <Guid> GetGuidFromLayer(BasicFeatureLayer fl, Selection selectedFeatures) { List <Guid> listIds = new List <Guid>(); // some data have restriction of element number in a clause IN, so we cut the in smaller list List <string> lEid = FormatOidToString(selectedFeatures.GetObjectIDs().ToList()); TableDefinition tbl = fl.GetTable().GetDefinition(); string FieldName = tbl.GetObjectIDField(); QueryFilter qf = new QueryFilter { SubFields = "*" }; foreach (string se in lEid) { qf.WhereClause = String.Format("{0} IN ({1})", FieldName, se); try { RowCursor rc = fl.Search(qf); while (rc.MoveNext()) { listIds.Add(rc.Current.GetGlobalID()); } } catch { } } return(listIds); }
private async Task<bool> ExecuteAddFieldTool(BasicFeatureLayer theLayer, KeyValuePair<string, string> field, string fieldType, int? fieldLength = null, bool isNullable = true) { try { return await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => { var inTable = theLayer.Name; var table = theLayer.GetTable(); var dataStore = table.GetDatastore(); var workspaceNameDef = dataStore.GetConnectionString(); var workspaceName = workspaceNameDef.Split('=')[1]; var fullSpec = System.IO.Path.Combine(workspaceName, inTable); System.Diagnostics.Debug.WriteLine($@"Add {field.Key} from {fullSpec}"); var parameters = Geoprocessing.MakeValueArray(inTable, field.Key, fieldType.ToUpper(), null, null, fieldLength, field.Value, isNullable ? "NULABLE" : "NON_NULLABLE"); var env = Geoprocessing.MakeEnvironmentArray(workspace: workspaceName); var cts = new CancellationTokenSource(); var results = Geoprocessing.ExecuteToolAsync("management.AddField", parameters, env, cts.Token, (eventName, o) => { System.Diagnostics.Debug.WriteLine($@"GP event: {eventName}"); }); return true; }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return false; } }
private async Task <bool> ExecuteAddFieldTool(BasicFeatureLayer theLayer, KeyValuePair <string, string> field, string fieldType, int?fieldLength = null, bool isNullable = true) { try { return(await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => { var inTable = theLayer.Name; var table = theLayer.GetTable(); var dataStore = table.GetDatastore(); var workspaceNameDef = dataStore.GetConnectionString(); var workspaceName = workspaceNameDef.Split('=')[1]; var fullSpec = System.IO.Path.Combine(workspaceName, inTable); System.Diagnostics.Debug.WriteLine($@"Add {field.Key} from {fullSpec}"); var parameters = Geoprocessing.MakeValueArray(fullSpec, field.Key, fieldType.ToUpper(), null, null, fieldLength, field.Value, isNullable ? "NULABLE" : "NON_NULLABLE"); var cts = new CancellationTokenSource(); var results = Geoprocessing.ExecuteToolAsync("management.AddField", parameters, null, cts.Token, (eventName, o) => { System.Diagnostics.Debug.WriteLine($@"GP event: {eventName}"); }); return true; })); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(false); } }
public static async Task <bool> ExecuteAddFieldTool(BasicFeatureLayer layer, string field, string fieldType, int?fieldLength = null, bool isNullable = true) { try { return(await QueuedTask.Run(() => { var layerName = layer.Name; var table = layer.GetTable(); var dataStore = table.GetDatastore(); var workspaceNameDef = dataStore.GetConnectionString(); var workspaceName = workspaceNameDef.Split('=')[1]; var fullSpec = System.IO.Path.Combine(workspaceName, layerName); Log($@"{field} added -> {fullSpec}"); var parameters = Geoprocessing.MakeValueArray(fullSpec, field, fieldType.ToUpper(), null, null, fieldLength, null, isNullable ? "NULLABLE" : "NON_NULLABLE"); var results = Geoprocessing.ExecuteToolAsync("management.AddField", parameters, null, new CancellationTokenSource().Token, (eventName, o) => { //OnProgressPos }); return true; })); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(false); } }
private async Task <bool> ExecuteDeleteFieldTool(BasicFeatureLayer theLayer, string fieldName) { try { return(await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => { var inTable = theLayer.Name; var table = theLayer.GetTable(); var dataStore = table.GetDatastore(); var workspaceNameDef = dataStore.GetConnectionString(); var workspaceName = workspaceNameDef.Split('=')[1]; var fullSpec = System.IO.Path.Combine(workspaceName, inTable); System.Diagnostics.Debug.WriteLine($@"Delete {fieldName} from {fullSpec}"); var parameters = Geoprocessing.MakeValueArray(fullSpec, fieldName); var cts = new CancellationTokenSource(); var results = Geoprocessing.ExecuteToolAsync("management.DeleteField", parameters, null, cts.Token, (eventName, o) => { System.Diagnostics.Debug.WriteLine($@"GP event: {eventName}"); if (eventName == "OnMessage") { System.Diagnostics.Debug.WriteLine($@"Msg: {o}"); } }); return true; })); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(false); } }
private static IEnumerable <Feature> GetFeatures([CanBeNull] BasicFeatureLayer layer, [NotNull] List <long> oids, bool recycling = false) { if (layer == null) { yield break; } // TODO: Use layer search (there might habe been an issue with recycling?!) var featureClass = layer.GetTable(); var filter = new QueryFilter { WhereClause = $"{featureClass.GetDefinition().GetObjectIDField()} IN ({StringUtils.Concatenate(oids, ", ")})" }; filter.OutputSpatialReference = layer.GetSpatialReference(); foreach (var feature in GdbQueryUtils.GetFeatures(featureClass, filter, recycling)) { yield return(feature); } }
public static GeodatabaseType?GetGeodatabaseType(this BasicFeatureLayer layer) { if (layer.ConnectionStatus == ConnectionStatus.Broken) { return(null); } GeodatabaseType?gdbType = GeodatabaseType.FileSystem; using (var dataset = layer.GetTable()) { using (var gdb = dataset.GetDatastore()) { //new at 2.3 if (gdb is PluginDatastore) { return(null); } //Note shapefile will be "FileSystemDatastore" if (gdb is Geodatabase) { gdbType = ((Geodatabase)gdb).GetGeodatabaseType(); } } } return(gdbType); }
private async Task <Geodatabase> GetGDBFromLyrAsync(BasicFeatureLayer lyr) { Geodatabase geodatabase = null; await QueuedTask.Run(() => geodatabase = (lyr.GetTable().GetDatastore() as Geodatabase)); return(geodatabase); }
/// <summary> /// Get GUID from Layer /// </summary> /// <param name="Fl">BasicFeatureLayer</param> /// <param name="SelectedFeatures">Selection</param> /// <returns></returns> private static List <Guid> GetGuidFromLayer(BasicFeatureLayer Fl, Selection SelectedFeatures) { List <Guid> listIds = new List <Guid>(); // Some SGDB having limitations on the list size when using WHERE IN clauses, the list is cut in smaller lists List <string> lEid = FormatOidToString(SelectedFeatures.GetObjectIDs().ToList()); TableDefinition tbl = Fl.GetTable().GetDefinition(); string FieldName = tbl.GetObjectIDField(); QueryFilter qf = new QueryFilter { SubFields = "*" }; //List<long> lselected = new List<long>(); foreach (string se in lEid) { qf.WhereClause = String.Format("{0} IN ({1})", FieldName, se); try { RowCursor rc = Fl.Search(qf); while (rc.MoveNext()) { listIds.Add(rc.Current.GetGlobalID()); } } catch { } } return(listIds); }
public static EditOperationType?GetEditOperationType(this BasicFeatureLayer layer) { if (layer.ConnectionStatus == ConnectionStatus.Broken) { return(null); } var gdbType = layer.GetGeodatabaseType(); var regType = layer.GetRegistrationType(); //Plugin - new at 2.3 if (gdbType == null) { return(null); } //FileSystem if (gdbType == GeodatabaseType.FileSystem) { return(EditOperationType.Long); } //LocalDatabase if (gdbType == GeodatabaseType.LocalDatabase) { return(EditOperationType.Long); } //RemoteDatabase, Versioned if (gdbType == GeodatabaseType.RemoteDatabase && ( regType == RegistrationType.Versioned || regType == RegistrationType.VersionedWithMoveToBase)) { return(EditOperationType.Long); } //RemoteDatabase, NonVersioned if (gdbType == GeodatabaseType.RemoteDatabase && regType == RegistrationType.Nonversioned) { return(EditOperationType.Short); } //Service, NonVersioned if (gdbType == GeodatabaseType.Service && regType == RegistrationType.Nonversioned) { return(EditOperationType.Short); } //Service, Versioned, Default EditOperationType forBranch = EditOperationType.Long; if (gdbType == GeodatabaseType.Service && regType == RegistrationType.Versioned) { using (var dataset = layer.GetTable()) using (var gdb = dataset.GetDatastore() as Geodatabase) using (var vmgr = gdb.GetVersionManager()) using (var vers = vmgr.GetCurrentVersion()) using (var parent = vers.GetParent()) { //non-default supports undo/redo and save/discard. Default does not forBranch = parent != null ? EditOperationType.Long : EditOperationType.Short; } } return(forBranch); }
private async Task <Geodatabase> GetGDBFromLayer(BasicFeatureLayer layer) { if (layer == null) { return(null); } Geodatabase geodatabase = null; await QueuedTask.Run(() => geodatabase = (layer.GetTable().GetDatastore() as Geodatabase)); return(geodatabase); }
/// <summary> /// Calculate viewpoint coordinates from vector points. /// </summary> /// <param name="viewpointLayer">Layer which contains the viewpoints.</param> /// <returns></returns> private HashSet <SpatialUtils.ViewpointProps> GetPoints(BasicFeatureLayer viewpointLayer) { HashSet <SpatialUtils.ViewpointProps> result = new HashSet <SpatialUtils.ViewpointProps>(); //using hash set to prevent duplicates, possible speed up with array Table table = viewpointLayer.GetTable(); string query = "POINT_X, POINT_Y"; if (!SettingsManager.Instance.CurrentSettings.OffsetGlobal) { query += ", OFFSET"; } if (SettingsManager.Instance.CurrentSettings.WeightedViewpoints) { query += ", WEIGHT"; } QueryFilter queryFilter = new QueryFilter { SubFields = query }; using (RowCursor rowCursor = table.Search(queryFilter, false)) { while (rowCursor.MoveNext()) { using (Row row = rowCursor.Current) { double pointX = Convert.ToDouble(row["POINT_X"]); double pointY = Convert.ToDouble(row["POINT_Y"]); Tuple <int, int> point = inputRaster.MapToPixel(pointX, pointY); double altOffset = 0; double weight = 1; if (!SettingsManager.Instance.CurrentSettings.OffsetGlobal) { altOffset = Convert.ToDouble(row["OFFSET"]); } if (SettingsManager.Instance.CurrentSettings.WeightedViewpoints) { weight = Convert.ToDouble(row["WEIGHT"]); } result.Add(new SpatialUtils.ViewpointProps() { X = point.Item1, Y = point.Item2, ElevationOffset = altOffset, Weight = weight }); } } } return(result); }
public static RegistrationType?GetRegistrationType(this BasicFeatureLayer layer) { if (layer.ConnectionStatus == ConnectionStatus.Broken) { return(null); } RegistrationType?regType = null; using (var dataset = layer.GetTable()) { regType = dataset.GetRegistrationType(); } return(regType); }
public static async Task <string> GetDataSource(BasicFeatureLayer theLayer) { try { return(await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => { var inTable = theLayer.Name; var table = theLayer.GetTable(); var dataStore = table.GetDatastore(); var workspaceNameDef = dataStore.GetConnectionString(); var workspaceName = workspaceNameDef.Split('=')[1]; var fullSpec = System.IO.Path.Combine(workspaceName, inTable); return fullSpec; })); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(string.Empty); } }
private async Task<bool> ExecuteDeleteFieldTool(BasicFeatureLayer theLayer, string fieldName) { try { return await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => { var inTable = theLayer.Name; var table = theLayer.GetTable(); var dataStore = table.GetDatastore(); var workspaceNameDef = dataStore.GetConnectionString(); var workspaceName = workspaceNameDef.Split('=')[1]; var fullSpec = System.IO.Path.Combine(workspaceName, inTable); System.Diagnostics.Debug.WriteLine($@"Delete {fieldName} from {fullSpec}"); var parameters = Geoprocessing.MakeValueArray(fullSpec, fieldName); var env = Geoprocessing.MakeEnvironmentArray(workspace: workspaceName); var cts = new CancellationTokenSource(); var results = Geoprocessing.ExecuteToolAsync("management.DeleteField", parameters, env, cts.Token, (eventName, o) => { System.Diagnostics.Debug.WriteLine($@"GP event: {eventName}"); if (eventName == "OnMessage") { System.Diagnostics.Debug.WriteLine($@"Msg: {o}"); } }); return true; }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return false; } }
//Using Inspector... internal async void UpdateTextString() { BasicFeatureLayer annoLayer = MapView.Active.Map.GetLayersAsFlattenedList().First() as BasicFeatureLayer; var oid = 1; #region Update Annotation Text via attribute. Caveat: The TEXTSTRING Anno attribute must exist //See "Change Annotation Text Graphic" for an alternative if TEXTSTRING is missing from the schema await QueuedTask.Run(() => { //annoLayer is ~your~ Annotation layer... // use the inspector methodology var insp = new Inspector(); insp.Load(annoLayer, oid); // make sure TextString attribute exists. //It is not guaranteed to be in the schema ArcGIS.Desktop.Editing.Attributes.Attribute att = insp.FirstOrDefault(a => a.FieldName == "TEXTSTRING"); if (att != null) { insp["TEXTSTRING"] = "Hello World"; //create and execute the edit operation EditOperation op = new EditOperation(); op.Name = "Update annotation"; op.Modify(insp); //OR using a Dictionary - again TEXTSTRING has to exist in the schema //Dictionary<string, object> newAtts = new Dictionary<string, object>(); //newAtts.Add("TEXTSTRING", "hello world"); //op.Modify(annoLayer, oid, newAtts); op.Execute(); } }); #endregion #region Rotate or Move the Annotation await QueuedTask.Run(() => { //Don't use 'Shape'....Shape is the bounding box of the annotation text. This is NOT what you want... // //var insp = new Inspector(); //insp.Load(annoLayer, oid); //var shape = insp["SHAPE"] as Polygon; //...wrong shape... //Instead, we must get the TextGraphic from the anno feature. //The TextGraphic shape will be the anno baseline... //At 2.1 the only way to retrieve this textLine is to obtain the TextGraphic from the AnnotationFeature QueryFilter qf = new QueryFilter() { WhereClause = "OBJECTID = 1" }; //annoLayer is ~your~ Annotation layer using (var rowCursor = annoLayer.Search(qf)) { if (rowCursor.MoveNext()) { using (var annoFeature = rowCursor.Current as ArcGIS.Core.Data.Mapping.AnnotationFeature) { var graphic = annoFeature.GetGraphic(); var textGraphic = graphic as CIMTextGraphic; var textLine = textGraphic.Shape as Polyline; // rotate the shape 90 degrees var origin = GeometryEngine.Instance.Centroid(textLine); Geometry rotatedPolyline = GeometryEngine.Instance.Rotate(textLine, origin, System.Math.PI / 2); //Move the line 5 "units" in the x and y direction //GeometryEngine.Instance.Move(textLine, 5, 5); EditOperation op = new EditOperation(); op.Name = "Change annotation angle"; op.Modify(annoLayer, oid, rotatedPolyline); op.Execute(); } } } }); #endregion #region Change Annotation Text Graphic await QueuedTask.Run(() => { EditOperation op = new EditOperation(); op.Name = "Change annotation graphic"; //At 2.1 we must use an edit operation Callback... op.Callback(context => { QueryFilter qf = new QueryFilter() { WhereClause = "OBJECTID = 1" }; //Cursor must be non-recycling. Use the table ~not~ the layer..i.e. "GetTable().Search()" //annoLayer is ~your~ Annotation layer using (var rowCursor = annoLayer.GetTable().Search(qf, false)) { if (rowCursor.MoveNext()) { using (var annoFeature = rowCursor.Current as ArcGIS.Core.Data.Mapping.AnnotationFeature) { //Get the graphic from the anno feature var graphic = annoFeature.GetGraphic(); var textGraphic = graphic as CIMTextGraphic; // change the text and the color textGraphic.Text = "hello world"; var symbol = textGraphic.Symbol.Symbol; symbol.SetColor(ColorFactory.Instance.RedRGB); textGraphic.Symbol = symbol.MakeSymbolReference(); // update the graphic annoFeature.SetGraphic(textGraphic); // store is required annoFeature.Store(); //refresh layer cache context.Invalidate(annoFeature); } } } }, annoLayer.GetTable()); op.Execute(); }); #endregion }
private async Task<Geodatabase> GetGDBFromLyrAsync(BasicFeatureLayer lyr) { Geodatabase geodatabase = null; await QueuedTask.Run(() => geodatabase = (lyr.GetTable().GetDatastore() as Geodatabase)); return geodatabase; }