Пример #1
0
        public override void Dispose()
        {
            base.Dispose();
            if (_queryInfo != null)
            {
                _queryInfo.Dispose();
                _queryInfo = null;
            }

            if (_stream != null)
            {
                _stream.Free();
                _stream = null;
            }

            if (_connection != null)
            {
                try
                {
                    _connection.Close();
                }
                catch { }
                _connection = null;
            }
        }
Пример #2
0
 public IDatasetElement this[string title]
 {
     get
     {
         SE_LAYERINFO layerInfo = new SE_LAYERINFO();
         try
         {
             SdeFeatureClass fc = null;
             //SdeConnection connection = _sConnection.AllocConnection();
             using (ArcSdeConnection connection = new ArcSdeConnection(_connStr))
             {
                 if (connection.Open(this))
                 {
                     if (Wrapper10.SE_layerinfo_create(new SE_COORDREF(), ref layerInfo) != 0)
                     {
                         return(null);
                     }
                     if (Wrapper10.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 != IntPtr.Zero)
             {
                 Wrapper10.SE_layerinfo_free(layerInfo);
             }
         }
     }
 }
Пример #3
0
        public SdeFeatureCursor(SdeDataset dataset, ITableClass tc, IQueryFilter filter)
            : base((tc is IFeatureClass) && ((IFeatureClass)tc).SpatialReference != null ?
                   ((IFeatureClass)tc).SpatialReference : filter.ContextLayerDefaultSpatialReference,
                   (filter != null) ? filter.FeatureSpatialReference : null)
        {
            try
            {
                if (filter != null && !filter.SubFields.Contains("*"))
                {
                    filter.AddField(tc.IDFieldName, false);
                }
                filter.fieldPrefix  = tc.Name + ".";
                filter.fieldPostfix = "";

                if (filter is ISpatialFilter &&
                    (((ISpatialFilter)filter).SpatialRelation != spatialRelation.SpatialRelationMapEnvelopeIntersects))
                {
                    if (tc is IFeatureClass)
                    {
                        filter.AddField(((IFeatureClass)tc).ShapeFieldName);
                    }
                    _spatialFilter = (ISpatialFilter)filter;
                }

                Int32 err_no = 0;

                _dataset = dataset;
                if (_dataset == null)
                {
                    return;
                }

                //_connection = _dataset.AllocConnection();
                _connection = new ArcSdeConnection(dataset.ConnectionString);
                if (!_connection.Open(this._dataset))
                {
                    return;
                }

                _queryInfo = new SdeQueryInfo(_connection, tc, filter);
                if (_queryInfo.ErrorMessage != "")
                {
                    Dispose();
                    return;
                }

                //if (Wrapper10.SE_stream_create(_connection.SeConnection, ref _stream) != 0)
                //{
                //    Dispose();
                //    return;
                //}

                //_connection.ResetStream();

                _stream = _connection.CreateStream();

                // SE_stream_set_state sollte auch aufgerufen werden (siehe mapsde.c von UMN)
                if (Wrapper10.SE_stream_set_state(
                        _stream.SeStream,
                        CONST.SE_DEFAULT_STATE_ID,
                        CONST.SE_DEFAULT_STATE_ID,
                        CONST.SE_STATE_DIFF_NOCHECK) != 0)
                {
                    Dispose();
                    return;
                }

                if ((err_no = Wrapper10.SE_stream_query_with_info(_stream.SeStream, _queryInfo.SeQueryInfo)) != 0)
                {
                    Dispose();
                    return;
                }

                if (_queryInfo.IsSpatial)
                {
                    SE_FILTER se_filter = _queryInfo.Filter_Shape;
                    if ((err_no = Wrapper10.SE_stream_set_spatial_constraints(_stream.SeStream, CONST.SE_SPATIAL_FIRST, false, 1, ref se_filter)) != 0)
                    {
                        _errMsg = Wrapper10.GetErrorMsg(_connection.SeConnection, err_no);
                        Dispose();
                        return;
                    }
                }
                else
                {
                    /*
                     * SE_FILTER se_filter = _queryInfo.Filter_Id;
                     * if (Wrapper10.SE_stream_set_spatial_constraints(_stream, CONST.SE_SPATIAL_FIRST, false, 1, ref se_filter) != 0)
                     * {
                     *  Release();
                     *  return;
                     * }
                     * */
                }

                if (Wrapper10.SE_stream_execute(_stream.SeStream) != 0)
                {
                    Dispose();
                    return;
                }

                _queryFields = _queryInfo.QueryFields;
                _queryInfo.Dispose();
                _queryInfo = null;
            }
            catch (Exception ex)
            {
                _errMsg = ex.Message + "\n" + ex.StackTrace;
                Dispose();
            }
        }
Пример #4
0
        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 coordRef  = ((SdeDataset)tc.Dataset).GetSeCoordRef(connection, tc.Name, ((IFeatureClass)tc).ShapeFieldName, ref maxExtent);
                    if (((SdeDataset)tc.Dataset).lastErrorMsg != "")
                    {
                        return;
                    }

                    _isSpatial = true;
                    _err_no    = Wrapper10.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 = Wrapper10.SE_shape_generate_rectangle(ref seEnvelope, _shape);
                    _err_no = gView.SDEWrapper.a10.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 */

                    switch (((ISpatialFilter)filter).SpatialRelation)
                    {
                    /*case spatialRelation.SpatialRelationMapEnvelopeIntersects:
                     *  _seFilter.method = CONST.SM_ENVP_BY_GRID;
                     *  break;
                     * */
                    case spatialRelation.SpatialRelationEnvelopeIntersects:
                        _seFilter.method = CONST.SM_ENVP;
                        break;

                    default:
                        _seFilter.method = CONST.SM_AI;
                        break;
                    }


                    _seFilter.filter_type = CONST.SE_SHAPE_FILTER;
                    _seFilter.truth       = true; // True;
                }

                _err_no = Wrapper10.SE_queryinfo_create(ref _queryInfo);
                if (_err_no != 0)
                {
                    return;
                }

                _err_no = Wrapper10.SE_queryinfo_set_tables(_queryInfo, 1, new string[] { tc.Name }, null);
                if (_err_no != 0)
                {
                    return;
                }

                string [] fields;
                if (filter.SubFields == "" || filter.SubFields.Contains("*") || filter.SubFields == null)
                {
                    StringBuilder subFields = new StringBuilder();
                    foreach (IField field in tc.Fields.ToEnumerable())
                    {
                        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)
                        {
                            if (filter.IgnoreUndefinedFields)
                            {
                                continue;
                            }

                            _errMsg = "Can't get Field " + fname;
                            Cleanup();
                            return;
                        }
                        _queryFields.Add(field);
                    }
                }

                _err_no = Wrapper10.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 = Wrapper10.SE_queryinfo_set_where_clause(_queryInfo, where);
                    if (_err_no != 0)
                    {
                        return;
                    }
                }

                _err_no = Wrapper10.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 = Wrapper10.GetErrorMsg(new SE_CONNECTION(), _err_no);
                    Cleanup();
                }
            }
        }
Пример #5
0
        /*
         * 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 GetSeCoordRef(ArcSdeConnection connection, string table, string spatialColumnName, ref SE_ENVELOPE envelope)
        {
            _errMsg = "";
            if (connection == null || connection.SeConnection.handle == IntPtr.Zero)
            {
                _errMsg = "GetSeCoordRef:\n No Connection allocated!";
                return(new SE_COORDREF());
            }

            SE_COORDREF  coordRef  = new SE_COORDREF();
            SE_LAYERINFO layerInfo = new SE_LAYERINFO();
            Int32        _err_no   = 0;

            try
            {
                _err_no = Wrapper10.SE_coordref_create(ref coordRef);
                if (_err_no != 0)
                {
                    return(new SE_COORDREF());
                }

                _err_no = Wrapper10.SE_layerinfo_create(coordRef, ref layerInfo);
                if (_err_no != 0)
                {
                    return(new SE_COORDREF());
                }

                _err_no = Wrapper10.SE_layer_get_info(connection.SeConnection, table, spatialColumnName, layerInfo);
                if (_err_no != 0)
                {
                    return(new SE_COORDREF());
                }

                _err_no = Wrapper10.SE_layerinfo_get_coordref(layerInfo, coordRef);
                if (_err_no != 0)
                {
                    return(new SE_COORDREF());
                }

                _err_no = Wrapper10.SE_coordref_get_xy_envelope(coordRef, ref envelope);
                if (_err_no != 0)
                {
                    return(new SE_COORDREF());
                }

                return(coordRef);
            }
            catch (Exception ex)
            {
                _errMsg = "GetSeCoordRef:\n " + ex.Message + "\n" + ex.StackTrace;
                return(new SE_COORDREF());
            }
            finally
            {
                if (layerInfo.handle != IntPtr.Zero)
                {
                    Wrapper10.SE_layerinfo_free(layerInfo);
                }

                if (_err_no != 0)
                {
                    if (coordRef.handle != IntPtr.Zero)
                    {
                        Wrapper10.SE_coordref_free(coordRef);
                    }
                    _errMsg = Wrapper10.GetErrorMsg(new SE_CONNECTION(), _err_no);
                }
            }
        }
Пример #6
0
 public void Dispose()
 {
     ArcSdeConnection.DisposePool(_connStr, this);
     _elements.Clear();
     GC.SuppressFinalize(this);
 }