Example #1
0
        public IDataset2 EmptyCopy()
        {
            SdeDataset dataset = new SdeDataset();

            dataset.ConnectionString = this.ConnectionString;
            dataset.Open();

            return(dataset);
        }
Example #2
0
        public SdeFeatureClass(SdeDataset dataset, SE_CONNECTION connection, SE_LAYERINFO 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.Int32 status = Wrapper92.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.SE_layerinfo_get_envelope(layerInfo, ref sdeEnvelope);
            if (status == 0)
            {
                _envelope = new Envelope(sdeEnvelope.minx, sdeEnvelope.miny, sdeEnvelope.maxx, sdeEnvelope.maxy);
            }

            System.Int32 shape_types = 0;
            status = Wrapper92.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.SE_reginfo_create(ref regInfo);
            if (status == 0)
            {
                try
                {
                    if (Wrapper92.SE_registration_get_info(connection, _name, regInfo) == 0)
                    {
                        byte[]       buffer    = new byte[CONST.SE_MAX_COLUMN_LEN];
                        System.Int32 idColType = 0;
                        if (Wrapper92.SE_reginfo_get_rowid_column(regInfo, buffer, ref idColType) == 0)
                        {
                            _idFieldName = Functions.GetASCIIString(buffer);
                        }
                    }
                }
                catch { }
                Wrapper92.SE_reginfo_free(regInfo);
            }

            // Felder auslesen
            _fields = new Fields();

            IntPtr ptr = new IntPtr(0);

            System.Int16 numFields = 0;

            status = Wrapper92.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 colDef = (SE_COLUMN_DEF)Marshal.PtrToStructure((IntPtr)columnDefs, typeof(SE_COLUMN_DEF));

                            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.SE_table_free_descriptions(ptr);
            }
        }
Example #3
0
        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 = "";

                Int32 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.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.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.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.SE_stream_set_spatial_constraints(_connection.SeStream, CONST.SE_SPATIAL_FIRST, false, 1, ref se_filter)) != 0)
                    {
                        _errMsg = Wrapper92.GetErrorMsg(_connection.SeConnection, err_no);
                        Dispose();
                        return;
                    }
                }
                else
                {
                    /*
                     * SE_FILTER se_filter = _queryInfo.Filter_Id;
                     * if (Wrapper92.SE_stream_set_spatial_constraints(_stream, CONST.SE_SPATIAL_FIRST, false, 1, ref se_filter) != 0)
                     * {
                     *  Release();
                     *  return;
                     * }
                     * */
                }

                if (Wrapper92.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();
            }
        }