public IDatasetElement this[string title] { get { SE_LAYERINFO_64 layerInfo = new SE_LAYERINFO_64(); try { SdeFeatureClass fc = null; //SdeConnection connection = _sConnection.AllocConnection(); using (ArcSdeConnection connection = new ArcSdeConnection(_connStr)) { if (connection.Open()) { if (Wrapper92_64.SE_layerinfo_create(new SE_COORDREF_64(), ref layerInfo) != 0) { return(null); } if (Wrapper92_64.SE_layer_get_info(connection.SeConnection, title, "", layerInfo) != 0) { return(null); } fc = new SdeFeatureClass(this, connection.SeConnection, layerInfo); } connection.Close(); } //_sConnection.FreeConnection(); return(new DatasetElement(fc)); } finally { if (layerInfo.handle != 0) { Wrapper92_64.SE_layerinfo_free(layerInfo); } } } }
public SdeFeatureClass(SdeDataset dataset, SE_CONNECTION_64 connection, SE_LAYERINFO_64 layerInfo) { _dataset = dataset; byte[] tableName = new byte[CONST.SE_QUALIFIED_TABLE_NAME]; byte[] columnName = new byte[CONST.SE_MAX_COLUMN_LEN]; byte[] shapeColumnName = new byte[CONST.SE_MAX_COLUMN_LEN]; System.Int64 status = Wrapper92_64.SE_layerinfo_get_spatial_column(layerInfo, tableName, shapeColumnName); if (status != 0) { return; } _name = Functions.GetASCIIString(tableName); //_shapeFildName mit den Felder abfragen, weils sonst oft Probleme mit Groß/Kleinschreibung der Felder gibt... //_shapeFieldName = Functions.GetASCIIString(shapeColumnName); SE_ENVELOPE sdeEnvelope = new SE_ENVELOPE(); status = Wrapper92_64.SE_layerinfo_get_envelope(layerInfo, ref sdeEnvelope); if (status == 0) { _envelope = new Envelope(sdeEnvelope.minx, sdeEnvelope.miny, sdeEnvelope.maxx, sdeEnvelope.maxy); } System.Int64 shape_types = 0; status = Wrapper92_64.SE_layerinfo_get_shape_types(layerInfo, ref shape_types); if (status == 0) { if ((shape_types & CONST.SE_NIL_TYPE_MASK) != 0) { _geomType = geometryType.Unknown; } if ((shape_types & CONST.SE_POINT_TYPE_MASK) != 0) { _geomType = geometryType.Point; } if ((shape_types & CONST.SE_LINE_TYPE_MASK) != 0) { _geomType = geometryType.Polyline; } if ((shape_types & CONST.SE_SIMPLE_LINE_TYPE_MASK) != 0) { _geomType = geometryType.Polyline; } if ((shape_types & CONST.SE_AREA_TYPE_MASK) != 0) { _geomType = geometryType.Polygon; } //if ((shape_types & CONST.SE_UNVERIFIED_SHAPE_MASK) != 0) //{ // _geomType = geometryType.Unknown; //} //if ((shape_types & CONST.SE_MULTIPART_TYPE_MASK) != 0) //{ // _geomType = geometryType.Aggregate; //} } // IDField IntPtr regInfo = new IntPtr(0); status = Wrapper92_64.SE_reginfo_create(ref regInfo); if (status == 0) { try { if (Wrapper92_64.SE_registration_get_info(connection, _name, regInfo) == 0) { byte[] buffer = new byte[CONST.SE_MAX_COLUMN_LEN]; System.Int64 idColType = 0; if (Wrapper92_64.SE_reginfo_get_rowid_column(regInfo, buffer, ref idColType) == 0) { _idFieldName = Functions.GetASCIIString(buffer); } } } catch { } Wrapper92_64.SE_reginfo_free(regInfo); } // Felder auslesen _fields = new Fields(); IntPtr ptr = new IntPtr(0); System.Int16 numFields = 0; status = Wrapper92_64.SE_table_describe(connection, _name, ref numFields, ref ptr); if (status == 0) { try { unsafe { byte *columnDefs = (byte *)ptr; for (int i = 0; i < numFields; i++) { SE_COLUMN_DEF_64 colDef = (SE_COLUMN_DEF_64)Marshal.PtrToStructure((IntPtr)columnDefs, typeof(SE_COLUMN_DEF_64)); string colName = Functions.GetASCIIString(colDef.column_name); FieldType colType = FieldType.unknown; switch (colDef.sde_type) { case CONST.SE_SMALLINT_TYPE: colType = FieldType.smallinteger; break; case CONST.SE_INTEGER_TYPE: colType = FieldType.integer; break; case CONST.SE_FLOAT_TYPE: colType = FieldType.Float; break; case CONST.SE_DOUBLE_TYPE: colType = FieldType.Double; break; case CONST.SE_STRING_TYPE: colType = FieldType.String; break; case CONST.SE_NSTRING_TYPE: colType = FieldType.NString; break; case CONST.SE_BLOB_TYPE: colType = FieldType.binary; break; case CONST.SE_DATE_TYPE: colType = FieldType.Date; break; case CONST.SE_SHAPE_TYPE: colType = FieldType.Shape; if (String.IsNullOrEmpty(_shapeFieldName)) { _shapeFieldName = colName; } break; case CONST.SE_RASTER_TYPE: break; default: colType = FieldType.unknown; break; } if (colName == _idFieldName) { colType = FieldType.ID; } _fields.Add(new Field(colName, colType, (int)colDef.size, (int)colDef.decimal_digits)); columnDefs += Marshal.SizeOf(colDef); } } } catch (Exception ex) { _errMsg = ex.Message; } if (String.IsNullOrEmpty(_shapeFieldName)) // nur wenn bei den Felder nix gefunden wurde... { _shapeFieldName = Functions.GetASCIIString(shapeColumnName); } Wrapper92_64.SE_table_free_descriptions(ptr); } }
/* * internal SdeConnection AllocConnection() * { * if (_sConnection == null) return null; * return _current = _sConnection.AllocConnection(); * } * * internal void FreeConnection() * { * if (_sConnection == null) return; * _current = null; * _sConnection.FreeConnection(); * } */ internal SE_COORDREF_64 GetSeCoordRef(ArcSdeConnection connection, string table, string spatialColumnName, ref SE_ENVELOPE envelope) { _errMsg = ""; if (connection == null || connection.SeConnection.handle == 0) { _errMsg = "GetSeCoordRef:\n No Connection allocated!"; return(new SE_COORDREF_64()); } SE_COORDREF_64 coordRef = new SE_COORDREF_64(); SE_LAYERINFO_64 layerInfo = new SE_LAYERINFO_64(); Int64 _err_no = 0; try { _err_no = Wrapper92_64.SE_coordref_create(ref coordRef); if (_err_no != 0) { return(new SE_COORDREF_64()); } _err_no = Wrapper92_64.SE_layerinfo_create(coordRef, ref layerInfo); if (_err_no != 0) { return(new SE_COORDREF_64()); } _err_no = Wrapper92_64.SE_layer_get_info(connection.SeConnection, table, spatialColumnName, layerInfo); if (_err_no != 0) { return(new SE_COORDREF_64()); } _err_no = Wrapper92_64.SE_layerinfo_get_coordref(layerInfo, coordRef); if (_err_no != 0) { return(new SE_COORDREF_64()); } _err_no = Wrapper92_64.SE_coordref_get_xy_envelope(coordRef, ref envelope); if (_err_no != 0) { return(new SE_COORDREF_64()); } return(coordRef); } catch (Exception ex) { _errMsg = "GetSeCoordRef:\n " + ex.Message + "\n" + ex.StackTrace; return(new SE_COORDREF_64()); } finally { if (layerInfo.handle != 0) { Wrapper92_64.SE_layerinfo_free(layerInfo); } if (_err_no != 0) { if (coordRef.handle != 0) { Wrapper92_64.SE_coordref_free(coordRef); } _errMsg = Wrapper92_64.GetErrorMsg(new SE_CONNECTION_64(), _err_no); } } }