Пример #1
0
        public gView.Framework.Data.ISelectionSet Select(gView.Framework.Data.IQueryFilter filter)
        {
            if (filter is IBufferQueryFilter)
            {
                ISpatialFilter sFilter = BufferQueryFilter.ConvertToSpatialFilter(filter as IBufferQueryFilter);
                if (sFilter == null)
                {
                    return(null);
                }
                return(Select(sFilter));
            }

            filter.SubFields = this.IDFieldName;

            IFeatureCursor cursor = (IFeatureCursor)(new ShapeFeatureCursor(this, _file, filter, _tree));
            IFeature       feat;

            IDSelectionSet selSet = new IDSelectionSet();

            while ((feat = cursor.NextFeature) != null)
            {
                selSet.AddID((int)((uint)feat.OID));
            }
            cursor.Dispose();

            return(selSet);
        }
Пример #2
0
        async static public Task <string> ToXml(ITableClass fc, IQueryFilter filter)
        {
            if (filter is IBufferQueryFilter)
            {
                filter = await BufferQueryFilter.ConvertToSpatialFilter((IBufferQueryFilter)filter);
            }
            MemoryStream ms = new MemoryStream();
            StreamWriter sw = new StreamWriter(ms, Encoding.UTF8);

            sw.WriteLine("<Filter>");
            if (filter is IRowIDFilter)
            {
                if (fc.IDFieldName == String.Empty)
                {
                    CreateRowIDFilter(fc, filter as IRowIDFilter, sw);
                }
                else
                {
                    ParseInWhereClause(((IRowIDFilter)filter).RowIDWhereClause, sw);
                }
            }
            else if (filter is IQueryFilter)
            {
                if (filter.WhereClause.ToLower().Contains(" in ("))
                {
                    ParseInWhereClause(filter.WhereClause, sw);
                }
                else
                {
                    ParseWhereClause(filter.WhereClause, sw);
                }
            }
            sw.WriteLine("</Filter>");

            sw.Flush();

            ms.Position = 0;
            byte[] bytes = new byte[ms.Length];
            ms.Read(bytes, 0, (int)ms.Length);
            sw.Close();

            string ret = Encoding.UTF8.GetString(bytes).Trim();

            //            ret = @"<ogc:Filter>
            //   <ogc:PropertyIsLike wildCard=""%"" singleChar=""?"" escape=""ESC"">
            //      <ogc:PropertyName>
            //         item_plz
            //      </ogc:PropertyName>
            //      <ogc:Literal>
            //         53111
            //      </ogc:Literal>
            //   </ogc:PropertyIsLike>
            //</ogc:Filter>";

            return(ret);
        }
Пример #3
0
        public IFeatureCursor GetFeatures(IQueryFilter filter)
        {
            _lastException = null;
            if (filter is IBufferQueryFilter)
            {
                ISpatialFilter sFilter = BufferQueryFilter.ConvertToSpatialFilter(filter as IBufferQueryFilter);
                if (sFilter == null)
                {
                    return(null);
                }

                return(GetFeatures(sFilter));
            }

            return(new OgcSpatialFeatureCursor(this, filter));
        }
Пример #4
0
        async public Task <IFeatureCursor> GetFeatures(IQueryFilter filter)
        {
            _lastException = null;
            if (filter is IBufferQueryFilter)
            {
                ISpatialFilter sFilter = await BufferQueryFilter.ConvertToSpatialFilter(filter as IBufferQueryFilter);

                if (sFilter == null)
                {
                    return(null);
                }

                return(await GetFeatures(sFilter));
            }

            return(await OgcSpatialFeatureCursor.Create(this, filter));
        }
Пример #5
0
        async public Task <IFeatureCursor> GetFeatures(gView.Framework.Data.IQueryFilter filter /*, gView.Framework.Data.getFeatureQueryType type*/)
        {
            if (filter != null)
            {
                bool idField = false;
                if (filter.SubFields != "*")
                {
                    foreach (string field in filter.SubFields.Replace(",", " ").Split(' '))
                    {
                        if (field == this.IDFieldName)
                        {
                            idField = true;
                            break;
                        }
                    }
                }
                if (!idField)
                {
                    filter.AddField(this.IDFieldName);
                }
            }
            if (filter is IBufferQueryFilter)
            {
                ISpatialFilter sFilter = await BufferQueryFilter.ConvertToSpatialFilter(filter as IBufferQueryFilter);

                if (sFilter == null)
                {
                    return(null);
                }

                return(await GetFeatures(sFilter));
            }

            if (filter is IRowIDFilter)
            {
                return(new ShapeFeatureCursor(this, _file, filter, ((IRowIDFilter)filter).IDs));
            }
            else
            {
                return(new ShapeFeatureCursor(this, _file, filter, _tree));
            }
        }
Пример #6
0
        public IFeatureCursor GetFeatures(IQueryFilter filter)
        {
            if (filter == null)
            {
                return(null);
            }

            if (filter is IBufferQueryFilter)
            {
                ISpatialFilter sFilter = BufferQueryFilter.ConvertToSpatialFilter(filter as IBufferQueryFilter);
                if (sFilter == null)
                {
                    return(null);
                }
                return(GetFeatures(sFilter));
            }

            #region IDistrictFilter ?
            if (filter is IDistinctFilter)
            {
                if (filter.SubFields.Contains(":"))
                {
                    string[] fn = filter.SubFields.Split(':');

                    IFeatureLayerJoin join = _joins[fn[0]];
                    if (join != null)
                    {
                        using (join = (IFeatureLayerJoin)join.Clone())
                        {
                            join.Init(String.Empty);
                            filter         = new DistinctFilter(fn[1]);
                            filter.OrderBy = fn[1];
                            return(new FeatureCursorWrapper(join.PerformQuery(filter)));
                        }
                    }
                    return(null);
                }
                else
                {
                    return(_fc.GetFeatures(filter));
                }
            }
            #endregion

            #region IFunctionFilter ?
            if (filter is IFunctionFilter)
            {
                if (filter.SubFields.Contains(":"))
                {
                    string[] fn = filter.SubFields.Split(':');

                    IFeatureLayerJoin join = _joins[fn[0]];
                    if (join != null)
                    {
                        using (join = (IFeatureLayerJoin)join.Clone())
                        {
                            join.Init(String.Empty);
                            filter = new FunctionFilter(((IFunctionFilter)filter).Function, fn[1], ((IFunctionFilter)filter).Alias);
                            return(new FeatureCursorWrapper(join.PerformQuery(filter)));
                        }
                    }
                    return(null);
                }
                else
                {
                    return(_fc.GetFeatures(filter));
                }
            }
            #endregion

            bool hasInnerJoin = false;
            if (_joins != null)
            {
                foreach (IFeatureLayerJoin join in _joins)
                {
                    if (join.JoinType == joinType.LeftInnerJoin)
                    {
                        hasInnerJoin = true;
                        break;
                    }
                }
            }
            if ((!filter.SubFields.Contains(":") && !filter.SubFields.Contains("*") && hasInnerJoin == false && !filter.WhereClause.Contains(":")) || _joins == null || _joins.Count == 0)
            {
                return(_fc.GetFeatures(filter));
            }

            Dictionary <string, UniqueList <string> > fieldNames = new Dictionary <string, UniqueList <string> >();
            fieldNames.Add(String.Empty, new UniqueList <string>());
            fieldNames[String.Empty].Add(this.IDFieldName);

            string[] names = filter.SubFields.Replace(" ", ",").Split(',');

            foreach (string fieldname in filter.SubFields.Replace(" ", ",").Split(','))
            {
                if (fieldname == "*")
                {
                    fieldNames[String.Empty] = new UniqueList <string>();
                    fieldNames[String.Empty].Add("*");
                    foreach (IFeatureLayerJoin join in _joins)
                    {
                        fieldNames[join.JoinName] = new UniqueList <string>();
                        fieldNames[join.JoinName].Add("*");
                    }
                    break;
                }
                if (fieldname.Contains(":"))
                {
                    string[] fn = fieldname.Split(':');

                    IFeatureLayerJoin join = _joins[fn[0]];
                    if (join != null)
                    {
                        fieldNames[String.Empty].Add(join.Field);

                        if (!fieldNames.ContainsKey(fn[0]))
                        {
                            fieldNames.Add(fn[0], new UniqueList <string>());
                        }
                        fieldNames[fn[0]].Add(fn[1].Trim());
                    }
                }
                else
                {
                    fieldNames[String.Empty].Add(fieldname.Trim());
                }
            }

            foreach (IFeatureLayerJoin join in _joins)
            {
                if (join.JoinType == joinType.LeftInnerJoin)
                {
                    if (!fieldNames.Keys.Contains(join.JoinName))
                    {
                        fieldNames.Add(join.JoinName, new UniqueList <string>()
                        {
                            join.JoinFields[0].name
                        });
                        fieldNames[String.Empty].Add(join.Field);
                    }
                }
            }

            filter           = (IQueryFilter)filter.Clone();
            filter.SubFields = fieldNames[String.Empty].ToString(',');

            #region CrossTable Where Clause ?
            if (!String.IsNullOrEmpty(filter.WhereClause) && filter.WhereClause.Contains(":"))
            {
                string where = filter.WhereClause.ToLower();
                bool isCrossTableQuery = false;
                foreach (IField field in this.Fields.ToEnumerable())
                {
                    if (field.name.Contains(":") && where.Contains("[" + field.name.ToLower() + "]"))
                    {
                        IFeatureLayerJoin join = _joins[field.name.Split(':')[0]];
                        if (join != null)
                        {
                            isCrossTableQuery = true;
                            if (!fieldNames.ContainsKey(join.JoinName))
                            {
                                fieldNames.Add(join.JoinName, new UniqueList <string>());
                            }
                            fieldNames[join.JoinName].Add(field.name.Split(':')[1].Trim());
                            filter.AddField(join.Field);
                            //filter.AddField(field.name);
                        }
                    }
                    else if (!field.name.Contains(":") && where.Contains(field.name.ToLower()))  // select all fields in the where clause (because you need them in table.Select(...)
                    {
                        filter.AddField(field.name);
                    }
                }
                if (isCrossTableQuery)
                {
                    where = filter.WhereClause;
                    filter.WhereClause = String.Empty;
                    IFeatureCursor cursor = new FeatureCursor(_fc.GetFeatures(filter), (FeatureLayerJoins)_joins.Clone(), fieldNames);

                    DataTable tab  = gView.Framework.Data.FeatureCursor.ToDataTable(cursor);
                    DataRow[] rows = null;
                    try
                    {
                        rows = tab.Select(where, filter.OrderBy);
                    }
                    catch
                    {
                    }
                    return(new gView.Framework.Data.FeatureCursor.DataRowCursor(rows));
                }
            }
            #endregion

            if (fieldNames.Keys.Count <= 1)
            {
                fieldNames = null;
            }

            try
            {
                return(new FeatureCursor(_fc.GetFeatures(filter), (FeatureLayerJoins)_joins.Clone(), fieldNames));
            }
            catch
            {
                return(null);
            }
        }
Пример #7
0
        async private Task Render(IFeatureLayer layer)
        {
            IFeatureRenderer clonedFeatureRenderer = null;
            ILabelRenderer   clonedLabelRenderer   = null;

            GraphicsEngine.Abstraction.IBitmap compositionModeCopyBitmap = null;
            GraphicsEngine.Abstraction.ICanvas compositionModeCopyCanvas = null, originalCanvas = null;

            try
            {
                _map.FireOnUserInterface(true);
                if ((
                        layer.FeatureRenderer == null ||
                        layer.FeatureRenderer.HasEffect(layer, _map) == false)
                    &&
                    (
                        layer.LabelRenderer == null ||
                        _useLabelRenderer == false
                    ))
                {
                    return;
                }

                IFeatureClass fClass = layer.FeatureClass;
                if (fClass == null)
                {
                    return;
                }

                //IDataset dataset = (IDataset)_map[layer];
                //if (dataset == null) return;

                //if (!(dataset is IFeatureDataset)) return;

                IGeometry filterGeom = _map.Display.DisplayTransformation.TransformedBounds(_map.Display); //_map.Display.Envelope;

                if (_map.Display.GeometricTransformer != null)
                {
                    filterGeom = MapHelper.Project(fClass, _map.Display);
                }

                gView.Framework.Data.SpatialFilter filter = new gView.Framework.Data.SpatialFilter();
                filter.DatasetCachingContext = _datasetCachingContext;
                filter.Geometry = filterGeom;
                filter.AddField(fClass.ShapeFieldName);
                //filter.FuzzyQuery = true;
                filter.SpatialRelation = spatialRelation.SpatialRelationMapEnvelopeIntersects;
                filter.MapScale        = _map.Display.mapScale;
                filter.CancelTracker   = _cancelTracker;

                if (layer.FilterQuery != null)
                {
                    filter.WhereClause = layer.FilterQuery.WhereClause;
                    if (layer.FilterQuery is IBufferQueryFilter)
                    {
                        ISpatialFilter sFilter = await BufferQueryFilter.ConvertToSpatialFilter(layer.FilterQuery as IBufferQueryFilter);

                        if (sFilter == null)
                        {
                            return;
                        }
                        filter.SpatialRelation = spatialRelation.SpatialRelationIntersects;
                        filter.Geometry        = sFilter.Geometry;
                    }
                    if (layer.FilterQuery is ISpatialFilter)
                    {
                        //filter.FuzzyQuery = ((ISpatialFilter)layer.FilterQuery).FuzzyQuery;
                        filter.SpatialRelation = ((ISpatialFilter)layer.FilterQuery).SpatialRelation;
                        filter.Geometry        = ((ISpatialFilter)layer.FilterQuery).Geometry;
                    }
                }

                // Erst nach dem Clonen anwenden!!!
                //if (layer.FeatureRenderer != null && layer.FeatureRenderer.HasEffect(layer, _map))
                //{
                //    layer.FeatureRenderer.PrepareQueryFilter(layer, filter);
                //}
                //if (layer.LabelRenderer != null && _useLabelRenderer)
                //{
                //    layer.LabelRenderer.PrepareQueryFilter(_map.Display, layer, filter);
                //}

                IDisplay display  = _map;
                double   refScale = display.refScale;

                #region Layer Clonen

                IFeatureRenderer renderer      = null;
                ILabelRenderer   labelRenderer = null;

                lock (lockThis)
                {
                    // Beim Clonen sprerren...
                    // Da sonst bei der Servicemap bei gleichzeitigen Requests
                    // Exception "Objekt wird bereits an anderer Stelle verwendet" auftreten kann!
                    if (layer.FeatureRenderer != null && layer.FeatureRenderer.HasEffect(layer, _map))
                    {
                        if (layer.RequiresFeatureRendererClone(display))
                        {
                            renderer = clonedFeatureRenderer = (IFeatureRenderer)layer.FeatureRenderer.Clone(
                                new CloneOptions(display,
                                                 layer.UseWithRefScale(display),
                                                 maxRefScaleFactor: layer.MaxRefScaleFactor));
                        }
                        else
                        {
                            renderer = layer.FeatureRenderer;
                        }
                    }
                    if (layer.LabelRenderer != null && _useLabelRenderer)
                    {
                        if (layer.RequiresLabelRendererClone(display))
                        {
                            labelRenderer = clonedLabelRenderer =
                                (ILabelRenderer)layer.LabelRenderer.Clone(new CloneOptions(display,
                                                                                           layer.UseLabelsWithRefScale(display),
                                                                                           maxLabelRefscaleFactor: layer.MaxLabelRefScaleFactor));
                        }
                        else  // Clone with null => simple clone
                        {
                            //display.refScale = 0;
                            labelRenderer = clonedLabelRenderer = (ILabelRenderer)layer.LabelRenderer.Clone(null);
                            //display.refScale = refScale;
                        }
                    }
                }

                #endregion

                #region Prepare filter

                // Prepare erst auf geclonte renderer anwenden!! (Threadsafe)
                if (renderer != null && renderer.HasEffect(layer, _map))
                {
                    renderer.PrepareQueryFilter(layer, filter);
                }
                if (labelRenderer != null && _useLabelRenderer)
                {
                    labelRenderer.PrepareQueryFilter(_map.Display, layer, filter);
                }

                #endregion

                using (IFeatureCursor fCursor = await fClass.GetFeatures(MapHelper.MapQueryFilter(filter)))
                {
                    _map.FireOnUserInterface(false);

                    if (fCursor != null)
                    {
                        IFeature feature;

                        if (renderer != null)
                        {
                            renderer.StartDrawing(_map);

                            bool useCompostionModeCopy = layer is IFeatureLayerComposition &&
                                                         ((IFeatureLayerComposition)layer).CompositionMode == FeatureLayerCompositionMode.Copy;

                            if (useCompostionModeCopy)
                            {
                                originalCanvas            = _map.Display.Canvas;
                                compositionModeCopyBitmap = GraphicsEngine.Current.Engine.CreateBitmap(_map.Display.Bitmap.Width, _map.Display.Bitmap.Height, GraphicsEngine.PixelFormat.Rgba32);
                                compositionModeCopyCanvas = compositionModeCopyBitmap.CreateCanvas();

                                compositionModeCopyBitmap.MakeTransparent();
                                compositionModeCopyBitmap.SetResolution(_map.Display.Bitmap.DpiX,
                                                                        _map.Display.Bitmap.DpiY);

                                ((Display)_map.Display).Canvas = compositionModeCopyCanvas;
                            }

                            while ((feature = await fCursor.NextFeature()) != null)
                            {
                                if (_cancelTracker != null)
                                {
                                    if (!_cancelTracker.Continue)
                                    {
                                        break;
                                    }
                                }

                                renderer.Draw(_map, feature);

                                if (labelRenderer != null)
                                {
                                    labelRenderer.Draw(_map, feature);
                                }

                                _counter.Counter++;

                                if (_isServiceMap == false)
                                {
                                    if (_counter.Counter % 100 == 0)
                                    {
                                        _map.FireRefreshMapView();
                                    }
                                }
                            }
                        }
                        else if (labelRenderer != null && _cancelTracker.Continue)
                        {
                            while ((feature = await fCursor.NextFeature()) != null)
                            {
                                if (_cancelTracker != null)
                                {
                                    if (!_cancelTracker.Continue)
                                    {
                                        break;
                                    }
                                }

                                labelRenderer.Draw(_map, feature);
                                _counter.Counter++;
                            }
                        }

                        if (labelRenderer != null)
                        {
                            labelRenderer.Release();
                        }

                        if (renderer != null)
                        {
                            renderer.FinishDrawing(_map, _cancelTracker);
                        }

                        if (compositionModeCopyCanvas != null && compositionModeCopyBitmap != null)
                        {
                            originalCanvas.DrawBitmap(compositionModeCopyBitmap,
                                                      new GraphicsEngine.CanvasRectangle(0, 0, compositionModeCopyBitmap.Width, compositionModeCopyBitmap.Height),
                                                      new GraphicsEngine.CanvasRectangle(0, 0, compositionModeCopyBitmap.Width, compositionModeCopyBitmap.Height),
                                                      opacity: (float)Math.Min(1, (100f - ((IFeatureLayerComposition)layer).CompositionModeCopyTransparency) / 100));
                        }
                    }
                    else
                    {
                        if (fClass is IDebugging && ((IDebugging)fClass).LastException != null)
                        {
                            throw ((IDebugging)fClass).LastException;
                        }

                        throw new Exception("Can't query feature class. Unknown error");
                    }
                }
            }
            catch (Exception ex)
            {
                if (_map is IServiceMap && ((IServiceMap)_map).MapServer != null)
                {
                    await((IServiceMap)_map).MapServer.LogAsync(
                        ((IServiceMap)_map).Name,
                        "RenderFeatureLayer: " + ((layer != null) ? layer.Title : String.Empty),
                        loggingMethod.error,
                        ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace);
                }
                if (_map != null)
                {
                    _map.AddRequestException(new Exception("RenderFeatureLayerThread: " + ((layer != null) ? layer.Title : String.Empty) + "\n" + ex.Message, ex));
                }
            }
            finally
            {
                if (clonedFeatureRenderer != null)
                {
                    clonedFeatureRenderer.Release();
                }

                if (clonedLabelRenderer != null)
                {
                    clonedLabelRenderer.Release();
                }

                if (originalCanvas != null)
                {
                    ((Display)_map.Display).Canvas = originalCanvas;
                }

                if (compositionModeCopyCanvas != null)
                {
                    compositionModeCopyCanvas.Dispose();
                    compositionModeCopyCanvas = null;
                }

                if (compositionModeCopyBitmap != null)
                {
                    compositionModeCopyBitmap.Dispose();
                    compositionModeCopyBitmap = null;
                }

                _map.FireOnUserInterface(false);
            }
        }