internal void FreeSeCoordRef(SE_COORDREF_64 coordRef) { if (coordRef.handle != 0) { Wrapper92_64.SE_coordref_free(coordRef); } coordRef.handle = 0; }
private void CloseConnection(SdeConnection sdeConnection) { sdeConnection.FreeStream(); if (sdeConnection.SeConnection.handle != 0) { Wrapper92_64.SE_connection_free(sdeConnection.SeConnection); sdeConnection.SeConnection.handle = 0; } }
public void ResetStream() { if (_stream.handle == 0) { return; } Wrapper92_64.SE_stream_close(_stream, true); }
internal void FreeStream() { if (_stream.handle != 0) { Wrapper92_64.SE_stream_close(_stream, true); Wrapper92_64.SE_stream_free(_stream); _stream.handle = 0; } }
private short FetchSmallInteger(System.Int16 index) { System.Int16 val = 0; System.Int64 err_no = Wrapper92_64.SE_stream_get_smallint(_connection.SeStream, index, ref val); if (err_no == 0) { return(val); } return(0); }
private double FetchDouble(System.Int16 index) { System.Double val = 0; System.Int64 err_no = Wrapper92_64.SE_stream_get_double(_connection.SeStream, index, ref val); if (err_no == 0) { return(val); } return(0); }
private int FetchInteger(System.Int16 index) { System.Int32 val = 0; System.Int64 err_no = Wrapper92_64.SE_stream_get_integer(_connection.SeStream, index, ref val); if (err_no == 0) { return(val); } return(0); }
private void Cleanup() { if (_shape.handle != 0) { Wrapper92_64.SE_shape_free(_shape); _shape.handle = 0; } if (_queryInfo.handle != 0) { Wrapper92_64.SE_queryinfo_free(_queryInfo); _queryInfo.handle = 0; } }
protected override void CloseConnection(SdeConnection connection) { if (connection == null) { return; } if (connection.SeConnection.handle != 0) { Wrapper92_64.SE_connection_free(connection.SeConnection); connection.SeConnection.handle = 0; } }
private float FetchFloat(System.Int16 index) { float val = 0; System.Int64 err_no = Wrapper92_64.SE_stream_get_float(_connection.SeStream, index, ref val); if (err_no == 0) { return(val); } return(0); }
private DateTime?FetchDate(System.Int16 index) { tm TM = new tm(); System.Int64 err_no = Wrapper92_64.SE_stream_get_date(_connection.SeStream, index, ref TM); if (err_no == -1004) { return(null); } if (err_no != 0) { return(new DateTime(1, 1, 1)); } return(new DateTime( TM.tm_year + 1900, TM.tm_mon + 1, TM.tm_mday)); }
private string FetchNString(System.Int16 index, int size) { try { byte[] buffer = new byte[(size + 1) * 2]; System.Int64 err_no = Wrapper92_64.SE_stream_get_nstring(_connection.SeStream, index, buffer); if (err_no == -1004) { return(String.Empty); //return null; } if (err_no != 0) { return("<ERROR>:" + Wrapper92_64.GetErrorMsg(_connection.SeConnection, err_no)); } return(System.Text.Encoding.Unicode.GetString(buffer).Replace("\0", "")); } catch (Exception ex) { return("<EXCEPTION>:" + ex.Message); } }
private bool OpenConnection(SdeConnection SdeConnection) { if (SdeConnection.SeConnection.handle != 0) { CloseConnection(SdeConnection); } string server = ConfigTextStream.ExtractValue(_connectionString, "server"); string instance = ConfigTextStream.ExtractValue(_connectionString, "instance"); string database = ConfigTextStream.ExtractValue(_connectionString, "database"); string username = ConfigTextStream.ExtractValue(_connectionString, "usr"); string password = ConfigTextStream.ExtractValue(_connectionString, "pwd"); SE_ERROR_64 error = new SE_ERROR_64(); try { if (Wrapper92_64.SE_connection_create( server, instance, database, username, password, ref error, ref SdeConnection.SeConnection) != 0) { _errMsg = Wrapper92_64.GetErrorMsg(SdeConnection.SeConnection, error); return(false); } } catch (Exception ex) { _errMsg = "SDE ERROR: " + ex.Message; return(false); } return(true); }
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); } } } }
protected override SdeConnection OpenConnection() { _errMsg = ""; SdeConnection connection = new SdeConnection(); string server = ConfigTextStream.ExtractValue(_connectionString, "server"); string instance = ConfigTextStream.ExtractValue(_connectionString, "instance"); string database = ConfigTextStream.ExtractValue(_connectionString, "database"); string username = ConfigTextStream.ExtractValue(_connectionString, "usr"); string password = ConfigTextStream.ExtractValue(_connectionString, "pwd"); SE_ERROR_64 error = new SE_ERROR_64(); try { if (Wrapper92_64.SE_connection_create( server, instance, database, username, password, ref error, ref connection.SeConnection) != 0) { _errMsg = Wrapper92_64.GetErrorMsg(connection.SeConnection, error); return(null); } } catch (Exception ex) { _errMsg = "SDE ERROR: " + ex.Message; return(null); } return(connection); }
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); } }
public SdeQueryInfo(ArcSdeConnection connection, ITableClass tc, IQueryFilter filter) { if (tc == null) { return; } try { if (filter is ISpatialFilter && ((ISpatialFilter)filter).Geometry != null && tc is IFeatureClass && tc.Dataset is SdeDataset) { SE_ENVELOPE maxExtent = new SE_ENVELOPE(); SE_COORDREF_64 coordRef = ((SdeDataset)tc.Dataset).GetSeCoordRef(connection, tc.Name, ((IFeatureClass)tc).ShapeFieldName, ref maxExtent); if (((SdeDataset)tc.Dataset).lastErrorMsg != "") { return; } _isSpatial = true; _err_no = Wrapper92_64.SE_shape_create(coordRef, ref _shape); ((SdeDataset)tc.Dataset).FreeSeCoordRef(coordRef); if (_err_no != 0) { return; } //IEnvelope env = ((ISpatialFilter)filter).Geometry.Envelope; //SE_ENVELOPE seEnvelope = new SE_ENVELOPE(); //seEnvelope.minx = Math.Max(env.minx, maxExtent.minx); //seEnvelope.miny = Math.Max(env.miny, maxExtent.miny); //seEnvelope.maxx = Math.Min(env.maxx, maxExtent.maxx); //seEnvelope.maxy = Math.Min(env.maxy, maxExtent.maxy); //if (seEnvelope.minx == seEnvelope.maxx && seEnvelope.miny == seEnvelope.maxy) //{ // /* fudge a rectangle so we have a valid one for generate_rectangle */ // /* FIXME: use the real shape for the query and set the filter_type // to be an appropriate type */ // seEnvelope.minx = seEnvelope.minx - 0.001; // seEnvelope.maxx = seEnvelope.maxx + 0.001; // seEnvelope.miny = seEnvelope.miny - 0.001; // seEnvelope.maxy = seEnvelope.maxy + 0.001; //} //_err_no = Wrapper92_64.SE_shape_generate_rectangle(ref seEnvelope, _shape); _err_no = gView.SDEWrapper.x64.Functions.SE_GenerateGeometry(_shape, ((ISpatialFilter)filter).Geometry, maxExtent); if (_err_no != 0) { return; } _seFilter.shape = _shape; /* set spatial constraint column and table */ _seFilter.table = tc.Name.PadRight(CONST.SE_QUALIFIED_TABLE_NAME, '\0');; _seFilter.column = ((IFeatureClass)tc).ShapeFieldName.PadRight(CONST.SE_MAX_COLUMN_LEN, '\0'); /* set a couple of other spatial constraint properties */ _seFilter.method = (((ISpatialFilter)filter).SpatialRelation == spatialRelation.SpatialRelationEnvelopeIntersects) ? CONST.SM_ENVP_BY_GRID /*CONST.SM_AI*/ : CONST.SM_AI; _seFilter.filter_type = CONST.SE_SHAPE_FILTER; _seFilter.truth = true; // True; } _err_no = Wrapper92_64.SE_queryinfo_create(ref _queryInfo); if (_err_no != 0) { return; } _err_no = Wrapper92_64.SE_queryinfo_set_tables(_queryInfo, 1, new string[] { tc.Name }, null); if (_err_no != 0) { return; } string [] fields; if (filter.SubFields == "" || filter.SubFields == "*" || filter.SubFields == null) { StringBuilder subFields = new StringBuilder(); foreach (IField field in tc.Fields) { if (subFields.Length != 0) { subFields.Append(" "); } subFields.Append(tc.Name + "." + field.name); _queryFields.Add(field); } fields = subFields.ToString().Split(' '); } else { fields = filter.SubFields.Split(' '); foreach (string fieldname in fields) { string fname = fieldname; if (fieldname.ToLower().IndexOf("distinct(") == 0) { fname = fieldname.Substring(9, fieldname.IndexOf(")") - 9); } IField field = tc.FindField(fname); if (field == null) { _errMsg = "Can't get Field " + fname; Cleanup(); return; } _queryFields.Add(field); } } _err_no = Wrapper92_64.SE_queryinfo_set_columns(_queryInfo, fields.Length, fields); if (_err_no != 0) { return; } string where = ""; if (filter != null) { if (filter is IRowIDFilter) { where = ((IRowIDFilter)filter).RowIDWhereClause; } else { where = filter.WhereClause; } } if (where != "") { _err_no = Wrapper92_64.SE_queryinfo_set_where_clause(_queryInfo, where); if (_err_no != 0) { return; } } _err_no = Wrapper92_64.SE_queryinfo_set_query_type(_queryInfo, CONST.SE_QUERYTYPE_JSFA); if (_err_no != 0) { return; } } catch (Exception ex) { _errMsg = "SeQueryInfo:" + ex.Message + "\n" + ex.StackTrace; _err_no = -1; } finally { if (_err_no != 0) { _errMsg = Wrapper92_64.GetErrorMsg(new SE_CONNECTION_64(), _err_no); Cleanup(); } } }
public SdeFeatureCursor(SdeDataset dataset, ITableClass tc, IQueryFilter filter) : base((tc is IFeatureClass) ? ((IFeatureClass)tc).SpatialReference : null, (filter != null) ? filter.FeatureSpatialReference : null) { try { if (filter != null && filter.SubFields != "*") { filter.AddField(tc.IDFieldName); } filter.fieldPrefix = tc.Name + "."; filter.fieldPostfix = ""; Int64 err_no = 0; _dataset = dataset; if (_dataset == null) { return; } //_connection = _dataset.AllocConnection(); _connection = new ArcSdeConnection(dataset.ConnectionString); if (!_connection.Open()) { return; } _queryInfo = new SdeQueryInfo(_connection, tc, filter); if (_queryInfo.ErrorMessage != "") { Dispose(); return; } //if (Wrapper92_64.SE_stream_create(_connection.SeConnection, ref _stream) != 0) //{ // Dispose(); // return; //} _connection.ResetStream(); // SE_stream_set_state sollte auch aufgerufen werden (siehe mapsde.c von UMN) if (Wrapper92_64.SE_stream_set_state( _connection.SeStream, CONST.SE_DEFAULT_STATE_ID, CONST.SE_DEFAULT_STATE_ID, CONST.SE_STATE_DIFF_NOCHECK) != 0) { Dispose(); return; } if ((err_no = Wrapper92_64.SE_stream_query_with_info(_connection.SeStream, _queryInfo.SeQueryInfo)) != 0) { Dispose(); return; } if (_queryInfo.IsSpatial) { SE_FILTER se_filter = _queryInfo.Filter_Shape; if ((err_no = Wrapper92_64.SE_stream_set_spatial_constraints(_connection.SeStream, CONST.SE_SPATIAL_FIRST, false, 1, ref se_filter)) != 0) { _errMsg = Wrapper92_64.GetErrorMsg(_connection.SeConnection, err_no); Dispose(); return; } } else { /* * SE_FILTER se_filter = _queryInfo.Filter_Id; * if (Wrapper92_64.SE_stream_set_spatial_constraints(_stream, CONST.SE_SPATIAL_FIRST, false, 1, ref se_filter) != 0) * { * Release(); * return; * } * */ } if (Wrapper92_64.SE_stream_execute(_connection.SeStream) != 0) { Dispose(); return; } _queryFields = _queryInfo.QueryFields; _queryInfo.Dispose(); _queryInfo = null; } catch (Exception ex) { _errMsg = ex.Message + "\n" + ex.StackTrace; Dispose(); } }
private IGeometry FetchShape(System.Int16 index) { unsafe { System.Int64 err_no = 0; SE_SHAPE_64 shape_val = new SE_SHAPE_64(); System.Int32 *part_offsets = null; System.Int32 *subp_offsets = null; SE_POINT * points = null; try { err_no = Wrapper92_64.SE_shape_create(new SE_COORDREF_64(), ref shape_val); if (err_no != 0) { return(null); } err_no = Wrapper92_64.SE_stream_get_shape(_connection.SeStream, index, shape_val); if (err_no != 0) { return(null); } Int64 shapeType = 0, numPoints = 0, numParts = 0, numSubparts = 0; err_no = Wrapper92_64.SE_shape_get_type(shape_val, ref shapeType); if (err_no != 0 || shapeType == CONST.SG_NIL_SHAPE) { return(null); } err_no = Wrapper92_64.SE_shape_get_num_points(shape_val, 0, 0, ref numPoints); if (err_no != 0) { return(null); } err_no = Wrapper92_64.SE_shape_get_num_parts(shape_val, ref numParts, ref numSubparts); if (err_no != 0) { return(null); } part_offsets = (System.Int32 *)Marshal.AllocHGlobal(((int)numParts + 1) * sizeof(System.Int32)); subp_offsets = (System.Int32 *)Marshal.AllocHGlobal(((int)numSubparts + 1) * sizeof(System.Int32)); points = (SE_POINT *)Marshal.AllocHGlobal((int)numPoints * sizeof(SE_POINT)); part_offsets[numParts] = (int)numSubparts; subp_offsets[numSubparts] = (int)numPoints; err_no = Wrapper92_64.SE_shape_get_all_points( shape_val, SE_ROTATION_TYPE.SE_DEFAULT_ROTATION, (IntPtr)part_offsets, (IntPtr)subp_offsets, (IntPtr)points, (IntPtr)null, (IntPtr)null); if (err_no != 0) { return(null); } IGeometry ret = null; switch (shapeType) { case CONST.SG_POINT_SHAPE: if (numPoints == 1) { ret = new Point(points[0].x, points[0].y); } else if (numPoints > 1) { MultiPoint mPoint_ = new MultiPoint(); for (int i = 0; i < numPoints; i++) { mPoint_.AddPoint(new Point(points[i].x, points[i].y)); } ret = mPoint_; } break; case CONST.SG_MULTI_POINT_SHAPE: MultiPoint mPoint = new MultiPoint(); for (int i = 0; i < numPoints; i++) { mPoint.AddPoint(new Point(points[i].x, points[i].y)); } ret = mPoint; break; case CONST.SG_LINE_SHAPE: case CONST.SG_SIMPLE_LINE_SHAPE: case CONST.SG_MULTI_LINE_SHAPE: case CONST.SG_MULTI_SIMPLE_LINE_SHAPE: Polyline polyline = new Polyline(); for (int s = 0; s < numSubparts; s++) { Path path = new Path(); int to = subp_offsets[s + 1]; for (int i = subp_offsets[s]; i < to; i++) { path.AddPoint(new Point(points[i].x, points[i].y)); } polyline.AddPath(path); } ret = polyline; break; case CONST.SG_AREA_SHAPE: case CONST.SG_MULTI_AREA_SHAPE: Polygon polygon = new Polygon(); for (int s = 0; s < numSubparts; s++) { Ring ring = new Ring(); int to = subp_offsets[s + 1]; for (int i = subp_offsets[s]; i < to; i++) { ring.AddPoint(new Point(points[i].x, points[i].y)); } polygon.AddRing(ring); } ret = polygon; break; } return(ret); } catch { return(null); } finally { if (part_offsets != null) { Marshal.FreeHGlobal((System.IntPtr)part_offsets); } if (subp_offsets != null) { Marshal.FreeHGlobal((System.IntPtr)subp_offsets); } if (points != null) { Marshal.FreeHGlobal((System.IntPtr)points); } if (shape_val.handle != 0) { Wrapper92_64.SE_shape_free(shape_val); } } } }
/* * 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); } } }