public static IObjectClass OpenObjectClass( [NotNull] IFeatureWorkspace workspace, [NotNull] string gdbDatasetName, [CanBeNull] string oidFieldName = null, [CanBeNull] SpatialReferenceDescriptor spatialReferenceDescriptor = null) { return((IObjectClass)OpenTable(workspace, gdbDatasetName, oidFieldName, spatialReferenceDescriptor)); }
public override IObjectClass OpenObjectClass(IObjectDataset dataset) { Assert.ArgumentNotNull(dataset, nameof(dataset)); SpatialReferenceDescriptor spatialReferenceDescriptor = (dataset.Model as Model)?.SpatialReferenceDescriptor; return((IObjectClass)ModelElementUtils.OpenTable( FeatureWorkspace, GetGdbElementName(dataset), dataset.GetAttribute(AttributeRole.ObjectID)?.Name, spatialReferenceDescriptor)); //return (IObjectClass) _workspaceProxy.OpenTable( // GetGdbElementName(dataset), // dataset.GetAttribute(AttributeRole.ObjectID)?.Name, // spatialReferenceDescriptor); }
public static ITable OpenTable( [NotNull] IFeatureWorkspace workspace, [NotNull] string gdbDatasetName, [CanBeNull] string oidFieldName = null, [CanBeNull] SpatialReferenceDescriptor spatialReferenceDescriptor = null) { Assert.ArgumentNotNull(workspace, nameof(workspace)); Assert.ArgumentNotNull(gdbDatasetName, nameof(gdbDatasetName)); var sqlWorksace = workspace as ISqlWorkspace; if (sqlWorksace == null || DatasetUtils.IsRegisteredAsObjectClass((IWorkspace)workspace, gdbDatasetName)) { return(DatasetUtils.OpenTable(workspace, gdbDatasetName)); } IQueryDescription queryDescription; try { string query = $"SELECT * FROM {gdbDatasetName}"; queryDescription = sqlWorksace.GetQueryDescription(query); } catch (Exception ex) { _msg.WarnFormat( "Unable to get query description for unregistered table {0}: {1}", gdbDatasetName, ex.Message); return(DatasetUtils.OpenTable(workspace, gdbDatasetName)); } bool hasUnknownSref = queryDescription.SpatialReference == null || queryDescription.SpatialReference is IUnknownCoordinateSystem; bool hasUnknownOid = StringUtils.IsNullOrEmptyOrBlank(queryDescription.OIDColumnName) || queryDescription.IsOIDMappedColumn; if (!hasUnknownOid && (!hasUnknownSref || !queryDescription.IsSpatialQuery)) { return(DatasetUtils.OpenTable(workspace, gdbDatasetName)); } if (hasUnknownOid) { if (StringUtils.IsNotEmpty(oidFieldName)) { queryDescription.OIDFields = oidFieldName; } else { IField uniqueIntegerField = GetUniqueIntegerField(workspace, gdbDatasetName); if (uniqueIntegerField != null) { queryDescription.OIDFields = uniqueIntegerField.Name; } } } if (hasUnknownSref && queryDescription.IsSpatialQuery) { queryDescription.SpatialReference = spatialReferenceDescriptor.SpatialReference; } try { // NOTE: the unqualified name of the query class must start with a '%' string queryLayerName = DatasetUtils.GetQueryLayerClassName(workspace, gdbDatasetName); _msg.DebugFormat("Opening query layer with name {0}", queryLayerName); ITable queryClass = sqlWorksace.OpenQueryClass(queryLayerName, queryDescription); // NOTE: the query class is owned by the *connected* user, not by the owner of the underlying table/view string queryClassName = DatasetUtils.GetName(queryClass); _msg.DebugFormat("Name of opened query layer class: {0}", queryClassName); _tableNamesByQueryClassNames[queryClassName] = gdbDatasetName; return(queryClass); } catch (Exception ex) { _msg.WarnFormat( "Unable to open unregistered table {0} as query layer: {1}", gdbDatasetName, ex.Message); return(DatasetUtils.OpenTable(workspace, gdbDatasetName)); } }