public static IEnumerable <Feature> GetSelectedFeatures([CanBeNull] BasicFeatureLayer layer)
        {
            Selection selection = layer?.GetSelection();

            if (selection == null)
            {
                yield break;
            }

            RowCursor cursor = selection.Search(null, false);

            try
            {
                while (cursor.MoveNext())
                {
                    var feature = (Feature)cursor.Current;

                    yield return(feature);
                }
            }
            finally
            {
                cursor.Dispose();
            }
        }
        public SlotCursor GetSlotCursor(int col)
        {
            _host.CheckParam(0 <= col && col < _header.ColumnCount, nameof(col));
            var view = _entries[col].GetViewOrNull();

            if (view == null)
            {
                throw _host.ExceptParam(nameof(col), "Bad call to GetSlotCursor on untransposable column '{0}'",
                                        Schema.GetColumnName(col));
            }
            _host.CheckParam(0 <= col && col < _header.ColumnCount, nameof(col));
            // We don't want the type error, if there is one, to be handled by the get-getter, because
            // at the point we've gotten the interior cursor, but not yet constructed the slot cursor.
            ColumnType cursorType  = TransposeSchema.GetSlotType(col).ItemType;
            RowCursor  inputCursor = view.GetRowCursor(c => true);

            try
            {
                return(Utils.MarshalInvoke(GetSlotCursorCore <int>, cursorType.RawType, inputCursor));
            }
            catch (Exception)
            {
                // We've already verified the types so we shouldn't throw here, in principle, but just
                // be extra careful so we're sure to dispose the input cursor.
                if (inputCursor != null)
                {
                    inputCursor.Dispose();
                }
                throw;
            }
        }
 protected override void Dispose(bool disposing)
 {
     if (_disposed)
     {
         return;
     }
     if (disposing)
     {
         if (_state is IDisposable disposableState)
         {
             disposableState.Dispose();
         }
         if (_src is IDisposable disposableSrc)
         {
             disposableSrc.Dispose();
         }
         if (_dst is IDisposable disposableDst)
         {
             disposableDst.Dispose();
         }
         _input.Dispose();
     }
     _disposed = true;
     base.Dispose(disposing);
 }
Exemple #4
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _inputCursor.Dispose();
     }
     GC.SuppressFinalize(this);
 }
 public void Dispose()
 {
     if (!_disposed)
     {
         _input.Dispose();
         Ch.Dispose();
         _disposed = true;
     }
 }
Exemple #6
0
 protected override void Dispose(bool disposing)
 {
     if (_disposed)
     {
         return;
     }
     if (disposing)
     {
         _leadingCursor.Dispose();
         _trailingCursor.Dispose();
     }
     _disposed = true;
     base.Dispose(disposing);
 }
Exemple #7
0
        private string GetUSNGID_Point(MapPoint point)
        {
            SpatialQueryFilter filter = new SpatialQueryFilter()
            {
                FilterGeometry      = point,
                SpatialRelationship = SpatialRelationship.Intersects,
                SubFields           = "GRID1MIL,GRID100K"
            };
            RowCursor cursor = USNGLayer.Search(filter);

            cursor.MoveNext();
            Row    row      = cursor.Current;
            string grid1mil = (string)row["GRID1MIL"];
            string grid100k = (string)row["GRID100K"];

            cursor.Dispose();

            // this code is from gregs roads code: https://gist.github.com/gregbunce/1733a741d8b4343a7a60fc42acf5086b
            double dblMeterX = (double)point.X;
            double dblMeterY = (double)point.Y;

            // add .5 to so when we conver to long and the value gets truncated, it will still regain our desired value (if you need more info on this, talk to Bert)
            dblMeterX = dblMeterX + .5;
            dblMeterY = dblMeterY + .5;
            long lngMeterX = (long)dblMeterX;
            long lngMeterY = (long)dblMeterY;

            // trim the x and y meter values to get the needed four characters from each value
            string strMeterX_NoDecimal = lngMeterX.ToString();
            string strMeterY_NoDecimal = lngMeterY.ToString();

            // remove the begining characters
            strMeterX_NoDecimal = strMeterX_NoDecimal.Remove(0, 1);
            strMeterY_NoDecimal = strMeterY_NoDecimal.Remove(0, 2);

            //remove the ending characters
            strMeterY_NoDecimal = strMeterY_NoDecimal.Remove(strMeterY_NoDecimal.Length - 1);
            strMeterX_NoDecimal = strMeterX_NoDecimal.Remove(strMeterX_NoDecimal.Length - 1);

            // piece all the unique_id fields together
            return(grid1mil + grid100k + strMeterX_NoDecimal + strMeterY_NoDecimal);
        }
Exemple #8
0
        public void MainMethodCode()
        {
            using (Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\LocalGovernment.gdb"))))
                using (Table table = fileGeodatabase.OpenDataset <Table>("EmployeeInfo"))
                {
                    QueryFilter queryFilter = new QueryFilter
                    {
                        WhereClause = "COSTCTRN = 'Information Technology'"
                    };

                    using (Selection selection = table.Select(queryFilter, SelectionType.ObjectID, SelectionOption.Normal))
                    {
                        // The result is a mapping between those object ids which failed validation and the reason why the validation failed (a string message).
                        IReadOnlyDictionary <long, string> validationResult = table.Validate(selection);

                        RowCursor  rowCursor = table.Search(queryFilter, false);
                        List <Row> rows      = new List <Row>();

                        try
                        {
                            while (rowCursor.MoveNext())
                            {
                                rows.Add(rowCursor.Current);
                            }

                            // This is equivalent to the validation performed using the selection.
                            IReadOnlyDictionary <long, string> equivalentValidationResult = table.Validate(rows);

                            // Again this is equivalent to both the above results.
                            IReadOnlyDictionary <long, string> anotherEquivalentResult = table.Validate(queryFilter);
                        }
                        finally
                        {
                            rowCursor.Dispose();
                            Dispose(rows);
                        }
                    }
                }

            // 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 (Table enterpriseTable = geodatabase.OpenDataset <Table>("LocalGovernment.GDB.piCIPCost"))
                {
                    QueryFilter openCutFilter = new QueryFilter {
                        WhereClause = "ACTION = 'Open Cut'"
                    };

                    using (Selection openCutSelection = enterpriseTable.Select(openCutFilter, SelectionType.ObjectID, SelectionOption.Normal))
                    {
                        // Remember that validation cost is directly proprtional to the number of Rows validated. So, select the set of rows to be validated
                        // judiciously.  This will be empty because all the rows in the piCIPCost table are valid.
                        IReadOnlyDictionary <long, string> emptyDictionary = enterpriseTable.Validate(openCutSelection);

                        // We are adding an invalid row to illustrate a case where the validation result is not empty.

                        long invalidRowObjectID = -1;

                        EditOperation editOperation = new EditOperation();
                        editOperation.Callback(context =>
                        {
                            RowBuffer rowBuffer = null;
                            Row row             = null;

                            try
                            {
                                TableDefinition tableDefinition = enterpriseTable.GetDefinition();

                                rowBuffer = enterpriseTable.CreateRowBuffer();

                                rowBuffer["ASSETNA"] = "wMain";
                                rowBuffer["COST"]    = 700;
                                rowBuffer["ACTION"]  = "Open Cut";
                                // Note that this is an invalid subtype value.
                                rowBuffer[tableDefinition.GetSubtypeField()] = 4;

                                row = enterpriseTable.CreateRow(rowBuffer);

                                //To Indicate that the attribute table has to be updated
                                context.Invalidate(row);

                                invalidRowObjectID = row.GetObjectID();
                            }
                            catch (GeodatabaseException exObj)
                            {
                                Console.WriteLine(exObj);
                            }
                            finally
                            {
                                if (rowBuffer != null)
                                {
                                    rowBuffer.Dispose();
                                }

                                if (row != null)
                                {
                                    row.Dispose();
                                }
                            }
                        }, enterpriseTable);

                        editOperation.Execute();

                        // This will have one keypair value for the invalid row that was added.
                        IReadOnlyDictionary <long, string> result = enterpriseTable.Validate(openCutFilter);

                        // This will say "invalid subtype code".
                        string errorMessage = result[invalidRowObjectID];
                    }
                }
        }
 public override void Dispose()
 {
     _leadingCursor.Dispose();
     _trailingCursor.Dispose();
     base.Dispose();
 }
Exemple #10
0
        /// <summary>
        /// Since the LocalGovernment Geodatabase does not have AttributedRelationshipClasses, the following method illustrates the behavior
        /// if such a dataset existed.
        /// </summary>
        public async Task MainMethodCode()
        {
            // 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 (AttributedRelationshipClass attributedRelationshipClass = geodatabase.OpenDataset <AttributedRelationshipClass>("LocalGovernment.GDB.ParcelToBuilding"))
                    using (FeatureClass parcelFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.Parcel"))
                        using (FeatureClass buildingFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.Building"))
                        {
                            RowCursor parcelsCursor = parcelFeatureClass.Search(new QueryFilter {
                                WhereClause = "APN = 5678"
                            }, false);
                            parcelsCursor.MoveNext();
                            Row parcelFeature = parcelsCursor.Current;

                            RowCursor buildingsCursor = buildingFeatureClass.Search(new QueryFilter {
                                WhereClause = "BUILDID = 4321"
                            }, false);
                            buildingsCursor.MoveNext();
                            Row buildingFeature = buildingsCursor.Current;

                            try
                            {
                                EditOperation editOperation = new EditOperation();
                                editOperation.Callback(context =>
                                {
                                    // Assuming such a relationship exists.
                                    attributedRelationshipClass.DeleteRelationship(parcelFeature, buildingFeature);
                                }, attributedRelationshipClass);

                                bool executeResult = editOperation.Execute();

                                bool saveResult = await Project.Current.SaveEditsAsync();

                                IReadOnlyList <AttributedRelationship> relationshipsForOriginRows = attributedRelationshipClass.GetRelationshipsForOriginRows(
                                    new List <long> {
                                    parcelFeature.GetObjectID()
                                });

                                // This will be null.
                                AttributedRelationship newlyAddedRelationship = relationshipsForOriginRows.FirstOrDefault(relationship =>
                                                                                                                          relationship.GetDestinationRow().GetObjectID() == buildingFeature.GetObjectID());
                            }
                            finally
                            {
                                parcelsCursor.Dispose();

                                if (parcelFeature != null)
                                {
                                    parcelFeature.Dispose();
                                }

                                buildingsCursor.Dispose();

                                if (buildingFeature != null)
                                {
                                    buildingFeature.Dispose();
                                }
                            }
                        }
        }
        public void MainMethodCode()
        {
            using (Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\LocalGovernment.gdb"))))
                using (FeatureClass featureClass = fileGeodatabase.OpenDataset <FeatureClass>("PollingPlace"))
                {
                    QueryFilter queryFilter = new QueryFilter {
                        WhereClause = "CITY = 'Plainfield'"
                    };
                    Selection selection = featureClass.Select(queryFilter, SelectionType.ObjectID, SelectionOption.Normal);

                    // The result is a mapping between those object ids which failed validation and the reason why the validation failed (a string message).
                    IReadOnlyDictionary <long, string> validationResult = featureClass.Validate(selection);

                    RowCursor      rowCursor = featureClass.Search(queryFilter, false);
                    List <Feature> features  = new List <Feature>();

                    try
                    {
                        while (rowCursor.MoveNext())
                        {
                            features.Add(rowCursor.Current as Feature);
                        }

                        // This is equivalent to the validation performed using the selection.
                        IReadOnlyDictionary <long, string> equivalentValidationResult = featureClass.Validate(features);

                        // Again this is equivalent to both the above results.
                        IReadOnlyDictionary <long, string> anotherEquivalentResult = featureClass.Validate(queryFilter);

                        SpatialQueryFilter spatialQueryFilter = new SpatialQueryFilter
                        {
                            FilterGeometry = new EnvelopeBuilder(
                                new MapPointBuilder(1052803, 1812751).ToGeometry(),
                                new MapPointBuilder(1034600, 1821320).ToGeometry()).ToGeometry(),

                            SpatialRelationship = SpatialRelationship.Within
                        };

                        IReadOnlyDictionary <long, string> spatialFilterBasedValidationResult = featureClass.Validate(spatialQueryFilter);
                    }
                    finally
                    {
                        rowCursor.Dispose();
                        Dispose(features);
                    }
                }

            // 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 enterpriseFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.FacilitySite"))
                {
                    QueryFilter parkFilter = new QueryFilter {
                        WhereClause = "FCODE = 'Park'"
                    };
                    Selection parkSelection = enterpriseFeatureClass.Select(parkFilter, SelectionType.ObjectID, SelectionOption.Normal);

                    // Remember that validation cost is directly proprtional to the number of Features validated. So, select the set of features to be
                    // validated judiciously.  This will be empty because all the Park Features are valid.
                    IReadOnlyDictionary <long, string> emptyDictionary = enterpriseFeatureClass.Validate(parkSelection);

                    // We are adding an invalid feature to illustrate a case where the validation result is not empty.

                    long invalidFeatureObjectID = -1;

                    EditOperation editOperation = new EditOperation();
                    editOperation.Callback(context =>
                    {
                        RowBuffer rowBuffer = null;
                        Feature feature     = null;

                        try
                        {
                            FeatureClassDefinition facilitySiteDefinition = enterpriseFeatureClass.GetDefinition();

                            rowBuffer = enterpriseFeatureClass.CreateRowBuffer();

                            rowBuffer["FACILITYID"] = "FAC-400";
                            rowBuffer["NAME"]       = "Griffith Park";
                            rowBuffer["OWNTYPE"]    = "Municipal";
                            rowBuffer["FCODE"]      = "Park";
                            // Note that this is an invalid subtype value.
                            rowBuffer[facilitySiteDefinition.GetSubtypeField()] = 890;
                            rowBuffer[facilitySiteDefinition.GetShapeField()]   = new PolygonBuilder(new List <Coordinate2D>
                            {
                                new Coordinate2D(1021570, 1880583),
                                new Coordinate2D(1028730, 1880994),
                                new Coordinate2D(1029718, 1875644),
                                new Coordinate2D(1021405, 1875397)
                            }).ToGeometry();

                            feature = enterpriseFeatureClass.CreateRow(rowBuffer);

                            invalidFeatureObjectID = feature.GetObjectID();
                        }
                        catch (GeodatabaseException exObj)
                        {
                            Console.WriteLine(exObj);
                        }
                        finally
                        {
                            if (rowBuffer != null)
                            {
                                rowBuffer.Dispose();
                            }

                            if (feature != null)
                            {
                                feature.Dispose();
                            }
                        }
                    }, enterpriseFeatureClass);

                    editOperation.Execute();

                    // This will have one keypair value for the invalid row that was added.
                    IReadOnlyDictionary <long, string> result = enterpriseFeatureClass.Validate(parkFilter);

                    // This will say "invalid subtype code".
                    string errorMessage = result[invalidFeatureObjectID];
                }
        }