void SetMosaicRule(MosaicLayer mosaicLayer, FeatureLayer footprintLayer, List <long> selectedItems) { ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => { // Check if overviews are supposed to be excluded from the selection. string objectIDs = null; if (excludeOverviews) { // Get the selected rows from the feature layer. RowCursor selectedRows = footprintLayer.GetSelection().Search(); if (selectedRows.MoveNext()) { using (var selectedRow = selectedRows.Current) { // Get the value for the Category field. int tag = Convert.ToInt32(selectedRow.GetOriginalValue(selectedRows.FindField("Category"))); // For each row, if Category is not 2 (2 = overview), then add the object id to the list of items to lock to. if (tag != 2) { objectIDs = selectedRow.GetOriginalValue(selectedRows.FindField("OBJECTID")).ToString(); } while (selectedRows.MoveNext()) { tag = Convert.ToInt32(selectedRow.GetOriginalValue(selectedRows.FindField("Category"))); if (tag != 2) { objectIDs += "," + selectedRow.GetOriginalValue(selectedRows.FindField("OBJECTID")).ToString(); } } } } } // Get the mosaic rule of the image sub-layer of the mosaic layer. ImageServiceLayer imageLayer = mosaicLayer.GetImageLayer() as ImageServiceLayer; CIMMosaicRule newMosaicRule = imageLayer.GetMosaicRule(); // If there is no saved mosaic rule, then save the original mosaic rule of the mosaic layer. if (mosaicRule == null) { mosaicRule = newMosaicRule; // Then create a new mosaic rule. newMosaicRule = new CIMMosaicRule(); } // Set the Mosaic Method to 'Lock Raster' newMosaicRule.MosaicMethod = RasterMosaicMethod.LockRaster; // Set the object id's to lock to. if (excludeOverviews) { newMosaicRule.LockRasterID = objectIDs; } else { newMosaicRule.LockRasterID = string.Join(",", selectedItems); } // Update the mosaic layer with the changed mosaic rule. imageLayer.SetMosaicRule(newMosaicRule); }); }
public async void LoadFile(MapPoint point) { if (await CheckRequirements()) { await QueuedTask.Run(() => { SpatialQueryFilter spatialFilter = new SpatialQueryFilter(); spatialFilter.FilterGeometry = point; spatialFilter.SpatialRelationship = SpatialRelationship.Intersects; using (RowCursor cursor = _selectedFeatureLayer.GetFeatureClass().Search(spatialFilter, false)) { int fieldindex = cursor.FindField(_selectedField); while (cursor.MoveNext()) { using (Row row = cursor.Current) { string rowValue = Convert.ToString(row.GetOriginalValue(fieldindex)); string filePath = _fileWorkspace + @"\" + AddPrefixAndSuffix(rowValue) + _fileExtension; if (!File.Exists(filePath)) { MessageBox.Show("File Does Not Exist", "Hmm..."); return; } SaveFileExtensionsToDisk(_fileExtension); Process.Start(filePath); } return; } MessageBox.Show("Select a feature from the '" + _selectedFeatureLayer.Name + "' feature layer", "Woah Woah Woah"); } }); } }
// Set range for feature layer // Map Exploration Team Routine private Task SetRangeProperties(FeatureLayer ftrLyr, string fieldName, bool hasCustomRange = false, double customMin = 0, double customMax = 1, bool inSingleValueMode = false, int rangeStepCount = 0) { return(QueuedTask.Run(() => { //Get min/max values for the field double minValue = 0; double maxValue = 0; //Calculate min/max if custom range is not defined if (!hasCustomRange) { int ftrCount = 0; RowCursor rows = ftrLyr.Search(null); while (rows.MoveNext()) { ftrCount++; } double[] fieldVals = new double[ftrCount]; rows = ftrLyr.Search(null); //Looping through to count int i = 0; while (rows.MoveNext()) { using (var currentRow = rows.Current) { object origVal = currentRow.GetOriginalValue(rows.FindField(fieldName)); if (!(origVal is DBNull)) { fieldVals[i] = System.Convert.ToDouble(origVal); } i++; } } if (fieldVals.Count() > 0) { minValue = fieldVals.Min(); maxValue = fieldVals.Max(); } } else { minValue = customMin; maxValue = customMax; } CIMBasicFeatureLayer baseLyr = (CIMBasicFeatureLayer)ftrLyr.GetDefinition(); CIMFeatureTable ftrTable = baseLyr.FeatureTable; //CIMRange theRange = new CIMRange(); CIMRangeDefinition[] rangeDefn = new CIMRangeDefinition[1]; rangeDefn[0] = new CIMRangeDefinition(); rangeDefn[0].FieldName = fieldName; rangeDefn[0].Name = fieldName; rangeDefn[0].CustomFullExtent = new CIMRange(); rangeDefn[0].CustomFullExtent.Min = minValue; rangeDefn[0].CustomFullExtent.Max = maxValue; //Set current range with either step count == 1 OR for some cases with step count == 0 rangeDefn[0].CurrentRange = new CIMRange(); rangeDefn[0].CurrentRange.Min = minValue; //rangeDefn[0].CurrentRange.Max = (rangeStepCount == 1) ? minValue + 1 : minValue; //set range step to 0 if in single value mode and to rangeStepCount otherwise rangeDefn[0].CurrentRange.Max = (inSingleValueMode) ? minValue : minValue + rangeStepCount; //rangeDefn[0].CurrentRange.Max = maxValue; ftrTable.RangeDefinitions = rangeDefn; ftrTable.ActiveRangeName = fieldName; baseLyr.FeatureTable = ftrTable; ftrLyr.SetDefinition(baseLyr); })); }
/// <summary> /// Generates File List /// </summary> private async Task GenerateFileList() { _FileList.Clear(); switch (_FileLoadingMethod) { // All Features will be Processed case EnumFileLoadingMethod.All: await QueuedTask.Run(() => { using (RowCursor cursor = _selectedFeatureLayer.GetFeatureClass().Search(null, false)) { int fieldIndex = cursor.FindField(_selectedField); while (cursor.MoveNext()) { using (Row row = cursor.Current) { String value = Convert.ToString(row.GetOriginalValue(fieldIndex)); if (!_FileList.ContainsKey(value)) { _FileList.Add(value, true); } } } } }); break; // Only Selected Features will be Processed case EnumFileLoadingMethod.Selected: await QueuedTask.Run(() => { Selection selection = _selectedFeatureLayer.GetSelection(); IReadOnlyList <long> oidset = selection.GetObjectIDs(); FeatureClass featureclass = _selectedFeatureLayer.GetFeatureClass(); using (RowCursor cursor = featureclass.Search(null, false)) { // Get Users Selected Field From Feature Class int fieldIndex = cursor.FindField(_selectedField); // TODO: Cycle through all features... This can be slow update when sdk updates while (cursor.MoveNext()) { using (Row row = cursor.Current) { long oid = row.GetObjectID(); // Check if current feature is in selected feature OID set if (oidset.Contains(oid)) { String value = Convert.ToString(row.GetOriginalValue(fieldIndex)); if (!_FileList.ContainsKey(value)) { _FileList.Add(value, true); } } } } } }); break; // Exhaust The Enumerator case EnumFileLoadingMethod.None: break; } }
/// <summary> /// Internal execution fonction to toggle switches /// </summary> /// <returns>An error comment if needed, empty of no error</returns> private static string ToggleSwitchesExecute() { bool canUpdate = false; // Load all Diagram Element and selection if (!IsDiagramUsable(GetAllElements: false, GetSelection: true)) { return(""); } if (GlobalSelectedJunctionIDs.Count == 0) { return("There are no junction selected"); } Dictionary <long, List <Guid> > guidBySourceId = new Dictionary <long, List <Guid> >(); // retrieve the junctions GlobalId foreach (long oid in GlobalSelectedJunctionIDs) { DiagramJunctionElement junctionElement = GlobalDiagramJunctionElements.FirstOrDefault(a => a.ObjectID == oid); if (junctionElement != null) { if (!guidBySourceId.TryGetValue(junctionElement.AssociatedSourceID, out List <Guid> guidList)) { guidList = new List <Guid>(); guidBySourceId.Add(junctionElement.AssociatedSourceID, guidList); } if (!guidList.Contains(junctionElement.AssociatedGlobalID)) { guidList.Add(junctionElement.AssociatedGlobalID); } } } IReadOnlyList <NetworkSource> theSources = GlobalUtilityNetwork.GetDefinition().GetNetworkSources(); List <string> searchFields = new List <string> { cDeviceStatusFieldName, "ObjectId", "AssetGroup" }; foreach (NetworkSource source in theSources) { if (guidBySourceId.TryGetValue(source.ID, out List <Guid> guidList)) { // Get a cursor of guid list, get the qualified fields name using (RowCursor sel = GetRowCursorFromSourceNameAndGuidList(SourceName: source.Name.Replace(" ", ""), SearchGuid: guidList, ListSearchFields: searchFields, WhereField: "GlobalId", FieldsName: out List <Tuple <string, string> > FieldsName)) { int deviceStatusIndex = -1; int assetGroupIndex = -1; // retrieved the fields indexes foreach (Tuple <string, string> findTuple in FieldsName) { if (findTuple.Item1 == cDeviceStatusFieldName) { deviceStatusIndex = sel.FindField(findTuple.Item2); } else if (findTuple.Item1 == "AssetGroup") { assetGroupIndex = sel.FindField(findTuple.Item2); } } if (deviceStatusIndex >= 0) // run only if there is a device status { var modifyStringsOperation = new EditOperation { Name = String.Format("Modify string field '{0}' in source {1}.", cDeviceStatusFieldName, source.Name) }; ICollection <long> oidSet = new List <long>(); while (sel.MoveNext()) { string AssetGroupValue = sel.Current[assetGroupIndex].ToString(); // verify if the Asset Group is correct if (!String.IsNullOrEmpty(AssetGroupValue) && AssetGroupValue == cAssetGroupFieldValue) { string deviceStatus = sel.Current[deviceStatusIndex]?.ToString(); Guid globalIdValue = sel.Current.GetGlobalID(); long oid = sel.Current.GetObjectID(); // set up a new dictionary with fields to modify var modifiedAttributes = new Dictionary <string, object> { // add the name of the string field and the new attribute value to the dictionary { cDeviceStatusFieldName, deviceStatus == "2" ? 1 : 2 } }; // put the modify operation on the editor stack modifyStringsOperation.Modify(sel.Current, modifiedAttributes); oidSet.Add(oid); } } if (oidSet.Count > 0) { // execute the modify operation to apply the changes modifyStringsOperation.Execute(); canUpdate = true; } else { modifyStringsOperation.Abort(); } } } } } return(canUpdate ? "" : "This command only applies to medium voltage switches. Please make sure there is at least one selected medium voltage switch in the active diagram before its execution."); }
public void MainMethodCode() { using (Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\LocalGovernment.gdb")))) using (Table table = fileGeodatabase.OpenDataset <Table>("EmployeeInfo")) { QueryFilter anotherQueryFilter = new QueryFilter { WhereClause = "COSTCTRN = 'Information Technology'" }; using (Selection itFolks = table.Select(anotherQueryFilter, SelectionType.ObjectID, SelectionOption.Normal)) { // Search with a null or a QueryFilter with an empty where clause will return all the Rows for the ObjectIds. // This can be used to obtain the rows for all the ObjectIds in the selection. using (RowCursor rowCursor = itFolks.Search(null, false)) { while (rowCursor.MoveNext()) { using (Row row = rowCursor.Current) { // Process the row. } } } } } // Opening a Non-Versioned SQL Server instance. DatabaseConnectionProperties connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer) { AuthenticationMode = AuthenticationMode.DBMS, // Where testMachine is the machine where the instance is running and testInstance is the name of the SqlServer instance. Instance = @"testMachine\testInstance", // Provided that a database called LocalGovernment has been created on the testInstance and geodatabase has been enabled on the database. Database = "LocalGovernment", // Provided that a login called gdb has been created and corresponding schema has been created with the required permissions. User = "******", Password = "******", Version = "dbo.DEFAULT" }; using (Geodatabase geodatabase = new Geodatabase(connectionProperties)) using (FeatureClass featureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.SchoolBoundary")) { QueryFilter indianPrairieFilter = new QueryFilter { WhereClause = "DISTRCTNAME = 'Indian Prairie School District 204'" }; using (Selection indianPrairieSelection = featureClass.Select(indianPrairieFilter, SelectionType.ObjectID, SelectionOption.Normal)) { // Using SpatialQueryFilter with Selection.Search. SpatialQueryFilter spatialQueryFilter = new SpatialQueryFilter { FilterGeometry = new PolygonBuilder(new List <Coordinate2D> { new Coordinate2D(1021880, 1867396), new Coordinate2D(1028223, 1870705), new Coordinate2D(1031165, 1866844), new Coordinate2D(1025373, 1860501), new Coordinate2D(1021788, 1863810) }).ToGeometry(), SpatialRelationship = SpatialRelationship.Intersects }; // Note that we are using Recycling. using (RowCursor spatialSearch = indianPrairieSelection.Search(spatialQueryFilter, true)) { // Note that we are calling the FindField outside the loop because this searches all the fields. There is no point in performing it for every Row. int nameFieldIndex = spatialSearch.FindField("NAME"); while (spatialSearch.MoveNext()) { using (Row row = spatialSearch.Current) { Console.WriteLine(row[nameFieldIndex]); } } } QueryFilter queryFilter = new QueryFilter { WhereClause = "NAME LIKE '///%Elementary///%'" }; using (Selection elementarySelection = featureClass.Select(queryFilter, SelectionType.ObjectID, SelectionOption.Normal)) { // Note that the cursor will contain only those rows which match "NAME LIKE '%Elementary%'" and "DISTRCTNAME = 'Indian Prairie School District 204'". // This is to illustrate that the seach will only happen on the object Ids in the selection. using (RowCursor cursor = elementarySelection.Search(indianPrairieFilter, false)) { while (cursor.MoveNext()) { using (Feature feature = (Feature)cursor.Current) { // Process feature. } } } } using (Selection onlyOneIndianPrairie = indianPrairieSelection.Select(null, SelectionOption.OnlyOne)) { QueryFilter napervilleFilter = new QueryFilter { WhereClause = "DISTRCTNAME LIKE '///%Naperville///%'" }; using (RowCursor napervilleSearch = onlyOneIndianPrairie.Search(napervilleFilter, false)) { // This will be false because there are no object ids in onlyOneIndianPrairie which have NaperVille in their DistrictName. bool hasRow = napervilleSearch.MoveNext(); using (Selection emptySelection = indianPrairieSelection.Select(null, SelectionOption.Empty)) using (RowCursor searchOnEmptySelection = emptySelection.Search(napervilleFilter, false)) { // Again, this will be false because there are no object ids in emptySelection. hasRow = searchOnEmptySelection.MoveNext(); } } } } } }