Public Function GetFields() As IReadOnlyList(Of Field)
public IReadOnlyList<Field> GetFields()
Return Value
The collection of fields in the Table.
Public Function GetFields() As IReadOnlyList(Of Field)
public IReadOnlyList<Field> GetFields()
| Exception | Description |
|---|---|
| ArcGIS.Core.Data.Exceptions.GeodatabaseException | A geodatabase-related exception has occurred. |
{
//Url examples for (federated) feature services
//(by "ref" online):
var url =
@"https://sampleserver6.arcgisonline.com/arcgis/rest/services/SF311/FeatureServer";
//(federated by ref on portal)
//https://portal.example.com/server/rest/services/FeatureServiceName/FeatureServer");
//(federated by value - Hosted - on portal)
//https://portal.example.com/server/rest/services/Hosted/FeatureServiceName/FeatureServer");
await QueuedTask.Run(() =>
{
var uri = new Uri(url, UriKind.Absolute);
using (var fs_db = new ArcGIS.Core.Data.Geodatabase(new ServiceConnectionProperties(uri)))
{
//Assuming that id 0 is a FeatureClass for the given service
FeatureClassDefinition featureClassDefinition =
fs_db.GetDefinition<FeatureClassDefinition>("0");
string shapeField = featureClassDefinition.GetShapeField();
IReadOnlyList<Field> fields = featureClassDefinition.GetFields();
//Assuming that id 1 is a Table for the given service
TableDefinition tableDefinition =
fs_db.GetDefinition<TableDefinition>("1");
string objectIDField = tableDefinition.GetObjectIDField();
}
});
}
{
//Must be called within QueuedTask.Run()
RowCursor SortWorldCities(FeatureClass worldCitiesTable)
{
using (FeatureClassDefinition featureClassDefinition = worldCitiesTable.GetDefinition())
{
Field countryField = featureClassDefinition.GetFields()
.First(x => x.Name.Equals("COUNTRY_NAME"));
Field cityNameField = featureClassDefinition.GetFields()
.First(x => x.Name.Equals("CITY_NAME"));
// Create SortDescription for Country field
SortDescription countrySortDescription = new SortDescription(countryField);
countrySortDescription.CaseSensitivity = CaseSensitivity.Insensitive;
countrySortDescription.SortOrder = SortOrder.Ascending;
// Create SortDescription for City field
SortDescription citySortDescription = new SortDescription(cityNameField);
citySortDescription.CaseSensitivity = CaseSensitivity.Insensitive;
citySortDescription.SortOrder = SortOrder.Ascending;
// Create our TableSortDescription
TableSortDescription tableSortDescription = new TableSortDescription(
new List<SortDescription>() { countrySortDescription, citySortDescription });
return worldCitiesTable.Sort(tableSortDescription);
}
}
}
{
// Must be called within QueuedTask.Run
void RemoveFieldTableSnippet(Geodatabase geodatabase)
{
// Removing all fields from 'Parcels' table except following
// Tax_Code
// Parcel_Address
// The table to remove fields
string tableName = "Parcels";
TableDefinition tableDefinition = geodatabase.GetDefinition<TableDefinition>(tableName);
IReadOnlyList<Field> fields = tableDefinition.GetFields();
// Existing fields from 'Parcels' table
Field taxCodeField = fields.First(f => f.Name.Equals("Tax_Code"));
Field parcelAddressField = fields.First(f => f.Name.Equals("Parcel_Address"));
FieldDescription taxFieldDescription = new FieldDescription(taxCodeField);
FieldDescription parcelAddressFieldDescription = new FieldDescription(parcelAddressField);
// Fields to retain in modified table
List<FieldDescription> fieldsToBeRetained = new List<FieldDescription>()
{
taxFieldDescription, parcelAddressFieldDescription
};
// New description of the 'Parcels' table with the 'Tax_Code' and 'Parcel_Address' fields
TableDescription modifiedTableDescription = new TableDescription(tableName, fieldsToBeRetained);
SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
// Remove all fields except the 'Tax_Code' and 'Parcel_Address' fields
schemaBuilder.Modify(modifiedTableDescription);
schemaBuilder.Build();
}
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)