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

            // Felder auslesen
            _fields = new Fields();

            IntPtr ptr = new IntPtr(0);

            System.Int16 numFields = 0;

            status = Wrapper10.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.ToLower() == _idFieldName.ToLower())
                            {
                                colType = FieldType.ID;
                                colName = _idFieldName;
                            }
                            _fields.Add(new Field(colName, colType, (int)colDef.size, (int)colDef.decimal_digits));

                            columnDefs += Marshal.SizeOf(colDef);
                        }
                    }

                    // Not so good -> no datum transformation
                    // Better set it NULL and transform layer automatically if nessessary by the Map.LayerDefaultSpatialReference (this is used for all layers with SRef==NULL
                    //this.SpatialReference = _dataset.GetLayerSpatialReference(connection, this.Name, this.ShapeFieldName);
                }
                catch (Exception ex)
                {
                    _errMsg = ex.Message;
                }

                if (String.IsNullOrEmpty(_shapeFieldName)) // nur wenn bei den Felder nix gefunden wurde...
                {
                    _shapeFieldName = Functions.GetASCIIString(shapeColumnName);
                }

                if (String.IsNullOrWhiteSpace(_idFieldName))
                {
                    // If there is no ID (Views), try to find a UNIQUE integer field
                    foreach (var field in _fields)
                    {
                        if (field.type == FieldType.integer)
                        {
                            QueryFilter qFilter = new QueryFilter();
                            qFilter.SubFields = field.name;

                            List <int> ids = new List <int>();
                            using (IFeatureCursor cursor = this.GetFeatures(qFilter))
                            {
                                IFeature feature;
                                while ((feature = cursor.NextFeature) != null)
                                {
                                    int id = Convert.ToInt32(feature[field.name]);
                                    ids.Add(id);
                                }
                            }

                            if (ids.Count > 0 && ids.Count == ids.Distinct().Count())  // Check if Unique
                            {
                                _idFieldName        = field.name;
                                ((Field)field).type = FieldType.ID;
                                break;
                            }
                        }
                    }
                }

                Wrapper10.SE_table_free_descriptions(ptr);
            }
        }