예제 #1
0
            void zoom2max_Click(object sender, EventArgs e)
            {
                if (_doc == null || _doc.FocusMap == null || _doc.FocusMap.Display == null ||
                    _ovmap == null || _ovmap.Display == null)
                {
                    return;
                }

                IEnvelope extent = _doc.FocusMap.Display.Limit;

                if (_doc.FocusMap.Display.SpatialReference != null &&
                    !_doc.FocusMap.Display.SpatialReference.Equals(_ovmap.Display.SpatialReference))
                {
                    extent = GeometricTransformerFactory.Transform2D(
                        extent,
                        _doc.FocusMap.Display.SpatialReference,
                        _ovmap.Display.SpatialReference).Envelope;
                }

                _ovmap.Display.ZoomTo(extent);

                if (RefreshOverviewMap != null)
                {
                    RefreshOverviewMap();
                }
            }
예제 #2
0
        async public Task LoadAsync(IDisplay display)
        {
            double displayResolution = display.mapScale / (/*display.dpi*/ 96.0 / 0.0254);

            int level = _grid.GetBestLevel(displayResolution, 90D);

            IEnvelope dispEnvelope = display.DisplayTransformation.TransformedBounds(display);

            if (display.GeometricTransformer != null)
            {
                dispEnvelope = (IEnvelope)((IGeometry)display.GeometricTransformer.InvTransform2D(dispEnvelope)).Envelope;
            }

            dispEnvelope = GeometricTransformerFactory.Transform2D(dispEnvelope, _dataset.SpatialReference, _dataset.WebMercatorSpatialReference)?.Envelope;

            double res  = _grid.GetLevelResolution(level);
            int    col0 = _grid.TileColumn(dispEnvelope.minx, res);
            int    row0 = _grid.TileRow(dispEnvelope.maxy, res);

            int col1 = _grid.TileColumn(dispEnvelope.maxx, res);
            int row1 = _grid.TileRow(dispEnvelope.miny, res);

            int col_from = Math.Max(0, Math.Min(col0, col1)), col_to = Math.Min((int)Math.Round(_grid.Extent.Width / (_grid.TileSizeX * res), 0) - 1, Math.Max(col0, col1));
            int row_from = Math.Max(0, Math.Min(row0, row1)), row_to = Math.Min((int)Math.Round(_grid.Extent.Height / (_grid.TileSizeY * res), 0) - 1, Math.Max(row0, row1));

            await LoadAsync(level, col_from, col_to, row_from, row_to);
        }
예제 #3
0
파일: FormXY.cs 프로젝트: jugstalt/gview5
 public IPoint GetPoint(ISpatialReference sRef)
 {
     return(GeometricTransformerFactory.Transform2D(
                coordControl1.Point,
                coordControl1.SpatialReference,
                sRef) as IPoint);
 }
예제 #4
0
        private IEnvelope ClassEnvelope(IClass Class, ISpatialReference sRef)
        {
            IEnvelope         envelope  = null;
            ISpatialReference classSRef = null;

            if (Class is IFeatureClass)
            {
                envelope  = ((IFeatureClass)Class).Envelope;
                classSRef = ((IFeatureClass)Class).SpatialReference;
            }
            else if (Class is IRasterClass && ((IRasterClass)Class).Polygon != null)
            {
                envelope  = ((IRasterClass)Class).Polygon.Envelope;
                classSRef = ((IRasterClass)Class).SpatialReference;
            }

            if (envelope != null && classSRef != null && sRef != null && !sRef.Equals(classSRef))
            {
                IGeometry geom = GeometricTransformerFactory.Transform2D(envelope, classSRef, sRef);
                if (geom == null)
                {
                    return(null);
                }

                envelope = geom.Envelope;
            }
            return(envelope);
        }
예제 #5
0
            public Task <bool> OnEvent(object MapEvent)
            {
                if (_doc == null || _doc.FocusMap == null || _doc.FocusMap.Display == null)
                {
                    return(Task.FromResult(true));
                }
                if (!(MapEvent is MapEventRubberband))
                {
                    return(Task.FromResult(true));
                }

                MapEventRubberband ev = (MapEventRubberband)MapEvent;

                if (ev.Map == null)
                {
                    return(Task.FromResult(true));
                }

                if (!(ev.Map.Display is Display))
                {
                    return(Task.FromResult(true));
                }
                Display nav = (Display)ev.Map.Display;

                IEnvelope extent = new Envelope(ev.minX, ev.minY, ev.maxX, ev.maxY);

                if (ev.Map.Display.SpatialReference != null &&
                    !ev.Map.Display.SpatialReference.Equals(_doc.FocusMap.Display.SpatialReference))
                {
                    extent = GeometricTransformerFactory.Transform2D(
                        extent,
                        ev.Map.Display.SpatialReference,
                        _doc.FocusMap.Display.SpatialReference).Envelope;
                }
                if (Math.Abs(ev.maxX - ev.minX) < 1e-5 ||
                    Math.Abs(ev.maxY - ev.minY) < 1e-5)
                {
                    IEnvelope dispEnv = new Envelope(_doc.FocusMap.Display.Envelope);
                    dispEnv.Center = extent.Center;
                    _doc.FocusMap.Display.ZoomTo(dispEnv);
                }
                else
                {
                    _doc.FocusMap.Display.ZoomTo(extent);
                }

                if (_doc.Application is IMapApplication)
                {
                    ((IMapApplication)_doc.Application).RefreshActiveMap(DrawPhase.All);
                }

                //ev.refreshMap = true;
                //ev.drawPhase = DrawPhase.Graphics;

                return(Task.FromResult(true));
            }
예제 #6
0
        public float GridQuery(gView.Framework.Carto.IDisplay display, IPoint point, ISpatialReference sRef)
        {
            float floatNodata = (float)_nodata;

            TFWFile tfw = this.WorldFile as TFWFile;

            if (tfw == null)
            {
                return(floatNodata);
            }

            if (this.SpatialReference != null && sRef != null &&
                !sRef.Equals(this.SpatialReference))
            {
                point = GeometricTransformerFactory.Transform2D(point, sRef, this.SpatialReference) as IPoint;
            }
            if (point == null)
            {
                return(floatNodata);
            }

            // Punkt transformieren -> Bild
            vector2[] vecs = new vector2[1];
            vecs[0] = new vector2(point.X, point.Y);

            if (!tfw.ProjectInv(vecs))
            {
                return(floatNodata);
            }

            if (vecs[0].x < 0 || vecs[0].x >= _iWidth ||
                vecs[0].y < 0 || vecs[0].y >= _iHeight)
            {
                return(floatNodata);
            }

            unsafe
            {
                fixed(float *buf = new float[2])
                {
                    _gridQueryBand.ReadRaster((int)vecs[0].x, (int)vecs[0].y, 1, 1,
                                              (IntPtr)buf,
                                              1, 1, OSGeo_v1.GDAL.DataType.GDT_CFloat32, 4, 0);

                    if ((_hasNoDataVal != 0 && buf[0] == floatNodata) ||
                        (_useIgnoreValue && buf[0] == _ignoreValue))
                    {
                        return(floatNodata);
                    }

                    return(buf[0]);
                }
            }
        }
예제 #7
0
        async public Task <bool> PerformUpdateFeature(IFeatureClass fc, IFeature feature)
        {
            if (fc == null || feature == null ||
                fc.Dataset == null ||
                !(fc.Dataset.Database is IFeatureUpdater))
            {
                return(false);
            }

            if (_attributEditor != null && !_attributEditor.CommitValues())
            {
                MessageBox.Show(_attributEditor.LastErrorMessage, "ERROR: Commit Values...");
                return(false);
            }

            EditorEventArgument args = new EditorEventArgument(fc, feature);

            if (OnUpdateFeature != null)
            {
                OnUpdateFeature(this, args);
            }

            if (args.Cancel)
            {
                _lastMsg = args.Message;
                return(false);
            }

            IGeometry shape = feature.Shape;

            if (_doc != null &&
                _doc.FocusMap != null &&
                _doc.FocusMap.Display != null &&
                _doc.FocusMap.Display.SpatialReference != null &&
                !_doc.FocusMap.Display.SpatialReference.Equals(_fc.SpatialReference))
            {
                feature.Shape = GeometricTransformerFactory.Transform2D(
                    feature.Shape,
                    _doc.FocusMap.Display.SpatialReference,
                    _fc.SpatialReference);
            }
            bool ret = await((IFeatureUpdater)fc.Dataset.Database).Update(fc, feature);

            feature.Shape = shape;

            if (!ret)
            {
                _lastMsg = fc.Dataset.Database.LastErrorMessage;
            }

            return(ret);
        }
예제 #8
0
        private IEnvelope ProjectEnvelope(IEnvelope env, ISpatialReference sRef)
        {
            if (sRef == null || env == null || _sRef == null)
            {
                return(env);
            }

            IGeometry geom = GeometricTransformerFactory.Transform2D(env, sRef, _sRef);

            if (geom != null)
            {
                return(geom.Envelope);
            }

            return(null);
        }
예제 #9
0
        public Task <ICursor> PointQuery(gView.Framework.Carto.IDisplay display, IPoint point, ISpatialReference sRef, IUserData userdata)
        {
            TFWFile tfw = this.WorldFile as TFWFile;

            if (tfw == null)
            {
                return(Task.FromResult <ICursor>(null));
            }

            if (this.SpatialReference != null && sRef != null &&
                !sRef.Equals(this.SpatialReference))
            {
                point = GeometricTransformerFactory.Transform2D(point, sRef, this.SpatialReference) as IPoint;
            }
            if (point == null)
            {
                return(Task.FromResult <ICursor>(null));;
            }

            // Punkt transformieren -> Bild
            vector2[] vecs = new vector2[1];
            vecs[0] = new vector2(point.X, point.Y);

            if (!tfw.ProjectInv(vecs))
            {
                return(Task.FromResult <ICursor>(null));;
            }

            if (vecs[0].x < 0 || vecs[0].x >= _iWidth ||
                vecs[0].y < 0 || vecs[0].y >= _iHeight)
            {
                return(Task.FromResult <ICursor>(null));
            }

            switch (_type)
            {
            case RasterType.image:
                return(Task.FromResult <ICursor>(QueryImage((int)Math.Floor(vecs[0].x), (int)Math.Floor(vecs[0].y))));

            case RasterType.grid:
                return(Task.FromResult <ICursor>(QueryGrid((int)Math.Floor(vecs[0].x), (int)Math.Floor(vecs[0].y))));
            }

            return(Task.FromResult <ICursor>(null));;
        }
예제 #10
0
        static public void GeometryToSpatialReference(this IQueryFilter filter, ISpatialReference targetSRef)
        {
            if (targetSRef != null &&
                filter is ISpatialFilter &&
                ((ISpatialFilter)filter).Geometry != null &&
                ((ISpatialFilter)filter).FilterSpatialReference != null &&
                !targetSRef.Equals(((ISpatialFilter)filter).FilterSpatialReference))
            {
                var spatialFilter = (ISpatialFilter)filter;

                spatialFilter.Geometry =
                    GeometricTransformerFactory.Transform2D(
                        spatialFilter.Geometry,
                        spatialFilter.FilterSpatialReference,
                        targetSRef);
                spatialFilter.FilterSpatialReference = targetSRef;
            }
        }
예제 #11
0
        public bool ProjectTo(ISpatialReference sRef)
        {
            if (_bounds == null)
            {
                return(false);
            }

            if (_sRef != null && !_sRef.Equals(sRef))
            {
                IGeometry result = GeometricTransformerFactory.Transform2D(_bounds, _sRef, sRef);
                if (result != null && result.Envelope != null)
                {
                    _bounds = result.Envelope;
                    _sRef   = sRef;
                    return(true);
                }
            }
            return(true);
        }
예제 #12
0
            public IEnvelope Envelope(string srs)
            {
                IEnvelope env = null;

                _boundaryBoxes.TryGetValue(srs.ToUpper(), out env);

                if (env == null && LatLonBoundingBox != null)
                {
                    // Projezieren
                    ISpatialReference sRef      = gView.Framework.Geometry.SpatialReference.FromID(srs);
                    ISpatialReference epsg_4326 = gView.Framework.Geometry.SpatialReference.FromID("epsg:4326");

                    IGeometry geom = GeometricTransformerFactory.Transform2D(LatLonBoundingBox, epsg_4326, sRef);
                    if (geom != null)
                    {
                        env = geom.Envelope;
                    }
                }

                return((env != null) ? env : new Envelope(-180, -90, 180, 90));
            }
예제 #13
0
        async public Task <IFeatureCursor> GetFeatures(IQueryFilter filter)
        {
            if (filter is ISpatialFilter)
            {
                if (this.SpatialReference != null &&
                    ((ISpatialFilter)filter).FilterSpatialReference != null &&
                    !((ISpatialFilter)filter).FilterSpatialReference.Equals(this.SpatialReference))
                {
                    filter = (ISpatialFilter)filter.Clone();

                    ((ISpatialFilter)filter).Geometry =
                        GeometricTransformerFactory.Transform2D(((ISpatialFilter)filter).Geometry,
                                                                ((ISpatialFilter)filter).FilterSpatialReference,
                                                                this.SpatialReference);
                    ((ISpatialFilter)filter).FilterSpatialReference = null;
                }
            }

            if (_dataset.Source != null)
            {
                if (_dataset.Source.IsValid)
                {
                    if (filter is DistinctFilter)
                    {
                        return(new GeoJsonDistinctFeatureCursor(await _dataset.Source?.GetFeatures(this.GeometryType), (DistinctFilter)filter));
                    }

                    return(new GeoJsonFeatureCursor(this, await _dataset.Source?.GetFeatures(this.GeometryType), filter));
                }
                else if (_dataset.Source.LastException != null)
                {
                    throw new Exception(_dataset.Source.LastException.AllMessages());
                }
            }

            // Dataset is not intializalized
            return(new GeoJsonFeatureCursor(this, new IFeature[0], filter));
        }
예제 #14
0
        private void InsertMapExtent(IDisplay display)
        {
            if (_ovmap == null || display == null ||
                _ovmap.Display == null)
            {
                return;
            }

            IGeometry mapEnv = display.Envelope;

            _ovmap.Display.GraphicsContainer.Elements.Clear();
            if (display.SpatialReference != null &&
                !display.SpatialReference.Equals(_ovmap.Display.SpatialReference))
            {
                mapEnv = GeometricTransformerFactory.Transform2D(
                    mapEnv, display.SpatialReference,
                    _ovmap.Display.SpatialReference);
            }

            _envGraphics.LimitEnvelope = _ovmap.Display.Envelope;
            _envGraphics.Geometry      = mapEnv;
            _ovmap.Display.GraphicsContainer.Elements.Add(_envGraphics);
        }
예제 #15
0
        private void treeObjects_MouseClick(object sender, MouseEventArgs e)
        {
            if (_doc == null)
            {
                return;
            }
            if (_doc.FocusMap == null)
            {
                return;
            }
            if (_doc.FocusMap.Display == null)
            {
                return;
            }
            if (_doc.Application == null)
            {
                return;
            }

            TreeNode node = treeObjects.GetNodeAt(e.X, e.Y);

            if (node is FeatureTreeNode && e.Button == MouseButtons.Left)
            {
                IFeature          feature = ((FeatureTreeNode)node).Feature;
                ISpatialReference sRef    = ((FeatureTreeNode)node).SpatialReference;
                ILayer            layer   = ((FeatureTreeNode)node).Layer;

                if (feature != null && feature.Shape != null)
                {
                    if (e.X > 50)
                    {
                        IGeometry shape = feature.Shape;
                        if (sRef != null && !sRef.Equals(_doc.FocusMap.Display.SpatialReference))
                        {
                            shape = GeometricTransformerFactory.Transform2D(shape, sRef, _doc.FocusMap.Display.SpatialReference);
                        }
                        _doc.FocusMap.HighlightGeometry(shape, 300);
                    }
                    else if (e.X >= 38)
                    {
                        IEnvelope envelope = feature.Shape.Envelope;
                        if (sRef != null && !sRef.Equals(_doc.FocusMap.Display.SpatialReference))
                        {
                            IGeometry geom = GeometricTransformerFactory.Transform2D(envelope,
                                                                                     sRef,
                                                                                     _doc.FocusMap.Display.SpatialReference);
                            if (geom == null)
                            {
                                return;
                            }
                            envelope = geom.Envelope;
                        }
                        _doc.FocusMap.Display.ZoomTo(envelope);
                        if (layer != null && layer.MaximumZoomToFeatureScale > _doc.FocusMap.Display.mapScale)
                        {
                            _doc.FocusMap.Display.mapScale = layer.MaximumZoomToFeatureScale;
                        }
                        if (_doc.Application is IMapApplication)
                        {
                            ((IMapApplication)_doc.Application).RefreshActiveMap(DrawPhase.All);
                        }
                    }
                }
            }
            //else if(node is CategoryTreeNode)
            //{
            //    var categoryTreeNode = (CategoryTreeNode)node;
            //    MessageBox.Show(categoryTreeNode.Category);
            //}
        }
예제 #16
0
        public Task <bool> OnEvent(object element, object dataset)
        {
            if (_doc == null || _doc.FocusMap == null || _doc.FocusMap.Display == null)
            {
                return(Task.FromResult(true));
            }

            if (element is IFeatureLayer && ((IFeatureLayer)element).FeatureClass != null && ((IFeatureLayer)element).FeatureClass.Envelope != null)
            {
                IEnvelope envelope = ((IFeatureLayer)element).FeatureClass.Envelope;
                if (((IFeatureLayer)element).FeatureClass.SpatialReference != null && !((IFeatureLayer)element).FeatureClass.SpatialReference.Equals(_doc.FocusMap.Display.SpatialReference))
                {
                    IGeometry geom = GeometricTransformerFactory.Transform2D(envelope, ((IFeatureLayer)element).FeatureClass.SpatialReference, _doc.FocusMap.Display.SpatialReference);
                    if (geom == null)
                    {
                        return(Task.FromResult(true));
                    }

                    envelope = geom.Envelope;
                }
                _doc.FocusMap.Display.ZoomTo(envelope);
            }
            else if (element is IRasterLayer && ((IRasterLayer)element).RasterClass != null && ((IRasterLayer)element).RasterClass.Polygon != null)
            {
                IEnvelope envelope = ((IRasterLayer)element).RasterClass.Polygon.Envelope;
                if (((IRasterLayer)element).RasterClass.SpatialReference != null && !((IRasterLayer)element).RasterClass.SpatialReference.Equals(_doc.FocusMap.Display.SpatialReference))
                {
                    IGeometry geom = GeometricTransformerFactory.Transform2D(envelope, ((IRasterLayer)element).RasterClass.SpatialReference, _doc.FocusMap.Display.SpatialReference);
                    if (geom == null)
                    {
                        return(Task.FromResult(true));
                    }

                    envelope = geom.Envelope;
                }
                _doc.FocusMap.Display.ZoomTo(envelope);
            }
            else if (element is IWebServiceLayer && ((IWebServiceLayer)element).WebServiceClass != null && ((IWebServiceLayer)element).WebServiceClass.Envelope != null)
            {
                IEnvelope envelope = ((IWebServiceLayer)element).WebServiceClass.Envelope;
                if (((IWebServiceLayer)element).WebServiceClass.SpatialReference != null && !((IWebServiceLayer)element).WebServiceClass.SpatialReference.Equals(_doc.FocusMap.Display.SpatialReference))
                {
                    IGeometry geom = GeometricTransformerFactory.Transform2D(envelope, ((IWebServiceLayer)element).WebServiceClass.SpatialReference, _doc.FocusMap.Display.SpatialReference);
                    if (geom == null)
                    {
                        return(Task.FromResult(true));
                    }

                    envelope = geom.Envelope;
                }
                _doc.FocusMap.Display.ZoomTo(envelope);
            }
            else
            {
                return(Task.FromResult(true));
            }
            if (_doc.Application is IMapApplication)
            {
                ((IMapApplication)_doc.Application).RefreshActiveMap(DrawPhase.All);
            }

            return(Task.FromResult(true));
        }
예제 #17
0
        async public Task <bool> OnEvent(object MapEvent)
        {
            if (!(MapEvent is MapEvent))
            {
                return(false);
            }

            IMap map = ((MapEvent)MapEvent).Map;

            bool firstDataset = (map[0] == null);

            List <ExplorerDialogFilter> filters = new List <ExplorerDialogFilter>();

            filters.Add(new OpenDataFilter());

            ExplorerDialog dlg = new ExplorerDialog("Add data...", filters, true);

            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                List <IDataset> datasets = await dlg.Datasets();

                FormDatasetProperties datasetProps = await FormDatasetProperties.CreateAsync(null, datasets);

                try
                {
                    if (((MapEvent)MapEvent).UserData == null)
                    {
                        if (datasetProps.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                        {
                            return(true);
                        }
                    }
                }
                catch  // Kann ObjectDisposed Exception werfen...
                {
                    return(true);
                }


                Envelope env = null;
                foreach (ILayer layer in datasetProps.Layers)
                {
                    ISpatialReference sRef     = null;
                    IEnvelope         classEnv = null;
                    if (layer is IFeatureLayer && ((IFeatureLayer)layer).FeatureClass != null && ((IFeatureLayer)layer).FeatureClass.Envelope != null)
                    {
                        sRef     = ((IFeatureLayer)layer).FeatureClass.SpatialReference;
                        classEnv = ((IFeatureLayer)layer).FeatureClass.Envelope;
                    }
                    else if (layer is IRasterLayer && ((IRasterLayer)layer).RasterClass != null && ((IRasterLayer)layer).RasterClass.Polygon != null && ((IRasterLayer)layer).RasterClass.Polygon.Envelope != null)
                    {
                        sRef     = ((IRasterLayer)layer).RasterClass.SpatialReference;
                        classEnv = ((IRasterLayer)layer).RasterClass.Polygon.Envelope;
                    }
                    else if (layer is IWebServiceLayer && ((IWebServiceLayer)layer).WebServiceClass != null && ((IWebServiceLayer)layer).WebServiceClass.Envelope != null)
                    {
                        sRef     = ((IWebServiceLayer)layer).WebServiceClass.SpatialReference;
                        classEnv = ((IWebServiceLayer)layer).WebServiceClass.Envelope;
                    }

                    if (classEnv != null)
                    {
                        if (sRef != null && !sRef.Equals(map.Display.SpatialReference))
                        {
                            bool found = false;
                            foreach (string p in map.Display.SpatialReference.Parameters)
                            {
                                if (p.ToLower().Trim() == "+nadgrids=@null")
                                {
                                    found = false;
                                }
                            }
                            if (found)
                            {
                                classEnv = null;
                            }
                            else
                            {
                                IGeometry geom = GeometricTransformerFactory.Transform2D(classEnv.ToPolygon(0), sRef, map.Display.SpatialReference);
                                if (geom != null)
                                {
                                    classEnv = geom.Envelope;
                                }
                                else
                                {
                                    classEnv = null;
                                }
                            }
                        }
                        if (classEnv != null)
                        {
                            if (env == null)
                            {
                                env = new Envelope(classEnv);
                            }
                            else
                            {
                                env.Union(classEnv);
                            }
                        }
                    }

                    map.AddLayer(layer);
                }
                //map.AddDataset(dataset, 0);


                if (env != null && map.Display != null)
                {
                    if (firstDataset)
                    {
                        map.Display.Limit = env;
                        map.Display.ZoomTo(env);
                    }
                    else
                    {
                        IEnvelope limit = map.Display.Limit;
                        limit.Union(env);
                        map.Display.Limit = limit;
                    }
                }
                ((MapEvent)MapEvent).drawPhase  = DrawPhase.All;
                ((MapEvent)MapEvent).refreshMap = true;
            }

            return(true);
        }
예제 #18
0
        async static public Task <IFeatureCursor> Create(OgcSpatialFeatureclass fc, IQueryFilter filter)
        {
            var featureCursor = new OgcSpatialFeatureCursor(fc, filter);

            if (fc == null || fc.Dataset == null)
            {
                return(featureCursor);
            }

            featureCursor._idField = fc.IDFieldName;
            if (filter is ISpatialFilter)
            {
                featureCursor._spatialfilter = (ISpatialFilter)filter;
            }

            try
            {
                if (fc.SpatialReference != null &&
                    filter is ISpatialFilter &&
                    ((ISpatialFilter)filter).FilterSpatialReference != null &&
                    !((ISpatialFilter)filter).FilterSpatialReference.Equals(fc.SpatialReference))
                {
                    filter = (ISpatialFilter)filter.Clone();

                    ((ISpatialFilter)filter).Geometry =
                        GeometricTransformerFactory.Transform2D(((ISpatialFilter)filter).Geometry,
                                                                ((ISpatialFilter)filter).FilterSpatialReference,
                                                                fc.SpatialReference);
                    ((ISpatialFilter)filter).FilterSpatialReference = null;
                    if (((ISpatialFilter)filter).SpatialRelation == spatialRelation.SpatialRelationMapEnvelopeIntersects &&
                        ((ISpatialFilter)filter).Geometry != null)
                    {
                        ((ISpatialFilter)filter).Geometry = ((ISpatialFilter)filter).Geometry.Envelope;
                    }

                    featureCursor._spatialfilter = (ISpatialFilter)filter;
                }
                DbCommand command = ((OgcSpatialDataset)fc.Dataset).SelectCommand(
                    fc, filter, out featureCursor._shapeField);
                if (command == null)
                {
                    return(featureCursor);
                }

                featureCursor._subFields = filter.QuerySubFields.ToArray();

                featureCursor._conn = ((OgcSpatialDataset)fc.Dataset).ProviderFactory.CreateConnection();
                featureCursor._conn.ConnectionString = fc.Dataset.ConnectionString;

                command.Connection = featureCursor._conn;

                if (featureCursor._conn.State != ConnectionState.Closed)
                {
                    try
                    {
                        featureCursor._conn.Close();
                    }
                    catch { }
                }
                await featureCursor._conn.OpenAsync();

                command.SetCustomCursorTimeout();
                featureCursor._reader = await command.ExecuteReaderAsync();

                return(featureCursor);
            }
            catch (Exception ex)
            {
                if (featureCursor._fc != null)
                {
                    featureCursor._fc.LastException = ex;
                }

                if (featureCursor._conn != null && featureCursor._conn.State != ConnectionState.Closed)
                {
                    featureCursor._conn.Close();
                    featureCursor._conn = null;
                }

                fc.LastException = ex;

                return(null);
            }
        }
예제 #19
0
        async public Task <bool> MapRequest(gView.Framework.Carto.IDisplay display)
        {
            if (_srs == null)
            {
                return(false);
            }

            if (!_dataset.IsOpened)
            {
                if (!await _dataset.Open())
                {
                    return(false);
                }
            }

            List <IWebServiceTheme> themes = Themes;

            if (themes == null)
            {
                return(false);
            }

            #region Check for visible Layers

            bool visFound = false;
            foreach (IWebServiceTheme theme in themes)
            {
                if (!theme.Visible)
                {
                    continue;
                }

                if (theme.MinimumScale > 1 && theme.MinimumScale > display.mapScale)
                {
                    continue;
                }

                if (theme.MaximumScale > 1 && theme.MaximumScale < display.mapScale)
                {
                    continue;
                }

                visFound = true;
                break;
            }
            if (!visFound)
            {
                if (_image != null)
                {
                    _image.Dispose();
                    _image = null;
                }
                return(true);
            }

            #endregion Check for visible Layers

            int iWidth  = display.iWidth;
            int iHeight = display.iHeight;

            if (BeforeMapRequest != null)
            {
                ISpatialReference sRef = this.SpatialReference;
                BeforeMapRequest(this, display, ref sRef, ref iWidth, ref iHeight);
                if (sRef != null && sRef.Name.ToLower() != this.SRSCode.ToLower())
                {
                    this.SRSCode = sRef.Name;
                }
            }

            IEnvelope displayEnv = display.Envelope;

            if (display.SpatialReference != null && !display.SpatialReference.Equals(this.SpatialReference))
            {
                displayEnv = GeometricTransformerFactory.Transform2D(displayEnv, display.SpatialReference, this.SpatialReference).Envelope;
                iHeight    = (int)((displayEnv.Height / displayEnv.Width) * iWidth);
            }

            StyledLayerDescriptorWriter sldWriter = null;
            StringBuilder request = new StringBuilder("VERSION=1.1.1&REQUEST=GetMap");
            StringBuilder layers = new StringBuilder(), styles = new StringBuilder();
            foreach (IWebServiceTheme theme in themes)
            {
                if (!theme.Visible || theme.Locked ||
                    (!(theme.Class is WMSThemeClass) &&
                     !(theme.Class is WFSFeatureClass)))
                {
                    continue;
                }

                if (layers.Length > 0)
                {
                    layers.Append(",");
                    styles.Append(",");
                }
                layers.Append(theme.Class.Name);
                if (theme.Class is IWMSStyle)
                {
                    styles.Append(((IWMSStyle)theme.Class).Style);
                }

                if (theme.FeatureRenderer != null &&
                    _userDefinedSymbolization.SupportSLD &&
                    _userDefinedSymbolization.UserStyle)
                {
                    SLDRenderer sldRenderer = null;
                    if (theme.FeatureRenderer is SLDRenderer)
                    {
                        sldRenderer = (SLDRenderer)theme.FeatureRenderer;
                    }
                    else
                    {
                        //if (theme.FilterQuery is ISpatialFilter)
                        //{
                        //    IGeometry pGeometry = GeometricTransformer.Transform2D(
                        //        ((ISpatialFilter)theme.FilterQuery).Geometry,
                        //        display.SpatialReference,
                        //        this.SpatialReference);

                        //    IGeometry oGeometry = ((ISpatialFilter)theme.FilterQuery).Geometry;
                        //    ((ISpatialFilter)theme.FilterQuery).Geometry = pGeometry;
                        //    sldRenderer = new SLDRenderer(theme);
                        //    ((ISpatialFilter)theme.FilterQuery).Geometry = oGeometry;
                        //}
                        //else
                        {
                            sldRenderer = await SLDRenderer.CreateAync(theme);

                            if (display.SpatialReference != null)
                            {
                                sldRenderer.SetDefaultSrsName(display.SpatialReference.Name);
                            }
                        }
                    }
                    if (sldWriter == null)
                    {
                        sldWriter = new StyledLayerDescriptorWriter();
                    }

                    sldWriter.WriteNamedLayer(theme.Class.Name, sldRenderer);
                }
            }
            request.Append("&LAYERS=" + layers.ToString());
            if (sldWriter != null)
            {
                string sld = sldWriter.ToLineString();
                if (!_use_SLD_BODY && !string.IsNullOrEmpty(MapServerConfig.DefaultOutputPath))
                {
                    string       sldFilename = "style_" + Guid.NewGuid().ToString("N") + ".sld";
                    StreamWriter sw          = new StreamWriter(MapServerConfig.DefaultOutputPath + @"/" + sldFilename);
                    sw.WriteLine(sldWriter.ToString());
                    sw.Close();

                    request.Append("&SLD=" + MapServerConfig.DefaultOutputUrl + "/" + sldFilename);
                }
                else
                {
                    request.Append("&SLD_BODY=" + sld.Replace("#", "%23"));
                }
            }
            else
            {
                request.Append("&STYLES=" + styles.ToString());
            }
            if (_exceptions != null && _exceptions.Formats.Count > 0)
            {
                request.Append("&EXCEPTIONS=" + _exceptions.Formats[0]);
            }
            request.Append("&SRS=" + _srs.Srs[_srs.SRSIndex]);
            request.Append("&WIDTH=" + iWidth);
            request.Append("&HEIGHT=" + iHeight);
            request.Append("&FORMAT=" + _getMap.Formats[_getMap.FormatIndex]);
            request.Append("&BBOX=" +
                           displayEnv.minx.ToString(_nhi) + "," +
                           displayEnv.miny.ToString(_nhi) + "," +
                           displayEnv.maxx.ToString(_nhi) + "," +
                           displayEnv.maxy.ToString(_nhi));
            //request.Append("&BGCOLOR=FFFFFF");
            request.Append("&TRANSPARENT=TRUE");

            if (_image != null)
            {
                _image.Dispose();
                _image = null;
            }
            IBitmap bitmap = null;
            //if (_getMap.Post_OnlineResource != String.Empty && sldWriter != null)
            //{
            //    //bm = WebFunctions.DownloadImage(WMSDataset.Append2Url(_getMap.Post_OnlineResource, request.ToString() + "&SLD="),
            //    //    UTF8Encoding.UTF8.GetBytes(sldWriter.ToString()));
            //    bm = WebFunctions.DownloadImage(_getMap.Post_OnlineResource,
            //        UTF8Encoding.UTF8.GetBytes(request.ToString()));
            //}
            //else
            {
#if (DEBUG)
                gView.Framework.system.Logger.LogDebug("Start WMS DownloadImage");
#endif
                string url = WMSDataset.Append2Url(_getMap.Get_OnlineResource, request.ToString());
                try
                {
                    bitmap = WebFunctions.DownloadImage(url,
                                                        ConfigTextStream.ExtractValue(_dataset._connectionString, "usr"),
                                                        ConfigTextStream.ExtractValue(_dataset._connectionString, "pwd"));
                }
                catch (Exception ex)
                {
                    await WMSClass.ErrorLogAsync(display.Map as IServiceRequestContext, "MapRequest", url, ex);

                    return(false);
                }
#if (DEBUG)
                gView.Framework.system.Logger.LogDebug("WMS DownloadImage Finished");
#endif
            }
            if (bitmap != null)
            {
                _image                  = new GeorefBitmap(bitmap);
                _image.Envelope         = displayEnv;
                _image.SpatialReference = this.SpatialReference;

                if (AfterMapRequest != null)
                {
                    AfterMapRequest(this, display, _image);
                }
            }
            return(_image != null);
        }
예제 #20
0
        private void WmtsCapabilities100(IServiceRequestContext context, TileServiceMetadata metadata)
        {
            gView.Framework.OGC.WMTS.Version_1_0_0.Capabilities capabilities = new Framework.OGC.WMTS.Version_1_0_0.Capabilities()
            {
                version = "1.0.0"
            };

            capabilities.NameSpaces = new System.Xml.Serialization.XmlSerializerNamespaces();
            capabilities.NameSpaces.Add("ows", "http://www.opengis.net/ows/1.1");
            capabilities.NameSpaces.Add("xlink", "http://www.w3.org/1999/xlink");
            capabilities.NameSpaces.Add("gml", "http://www.opengis.net/gml");

            #region ServiceIndentification

            capabilities.ServiceIdentification       = new gView.Framework.OGC.WMTS.Version_1_0_0.ServiceIdentification();
            capabilities.ServiceIdentification.Title = new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType()
                                                                                                                         {
                                                                                                                             Value = CapabilitiesMapName(context) // do not add folder to the name => tilecache will not work with arcgis
                                                                                                                         } };
            capabilities.ServiceIdentification.ServiceType = new gView.Framework.OGC.WMTS.Version_1_0_0.CodeType()
            {
                Value = "OGC WMTS"
            };
            capabilities.ServiceIdentification.ServiceTypeVersion = new string[] { "1.0.0" };

            #endregion

            string restFulUrl;

            if (String.IsNullOrWhiteSpace(context.ServiceRequest.Folder))
            {
                restFulUrl = context.ServiceRequest.OnlineResource.ToLower()
                             .Replace("/ogc/" + context.ServiceRequest.Service, "/tilewmts/" + context.ServiceRequest.Service);
            }
            else
            {
                string fromServiceFullname = context.ServiceRequest.Folder + "@" + context.ServiceRequest.Service;
                string toServiceFullname   = context.ServiceRequest.Folder + "/" + context.ServiceRequest.Service;

                restFulUrl = context.ServiceRequest.OnlineResource.ToLower()
                             .Replace("/ogc/" + fromServiceFullname.ToLower(), "/tilewmts/" + toServiceFullname.ToLower());
            }

            #region OperationsMetadata

            capabilities.OperationsMetadata = new gView.Framework.OGC.WMTS.Version_1_0_0.OperationsMetadata();

            var getCapOperation = new gView.Framework.OGC.WMTS.Version_1_0_0.Operation()
            {
                name = "GetCapabilities"
            };
            getCapOperation.DCP               = new gView.Framework.OGC.WMTS.Version_1_0_0.DCP[] { new gView.Framework.OGC.WMTS.Version_1_0_0.DCP() };
            getCapOperation.DCP[0].Item       = new gView.Framework.OGC.WMTS.Version_1_0_0.HTTP();
            getCapOperation.DCP[0].Item.Items = new gView.Framework.OGC.WMTS.Version_1_0_0.RequestMethodType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.RequestMethodType() };

            getCapOperation.DCP[0].Item.Items[0].href                        = context.ServiceRequest.OnlineResource + "?SERVICE=WMTS&VERSION=1.0.0" + "&";
            getCapOperation.DCP[0].Item.Items[0].Constraint                  = new gView.Framework.OGC.WMTS.Version_1_0_0.DomainType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.DomainType() };
            getCapOperation.DCP[0].Item.Items[0].Constraint[0].name          = "GetEncoding";
            getCapOperation.DCP[0].Item.Items[0].Constraint[0].AllowedValues = new object[] { new gView.Framework.OGC.WMTS.Version_1_0_0.ValueType()
                                                                                              {
                                                                                                  Value = "KVP"                                                      /*"RESTful"*/
                                                                                              } };
            getCapOperation.DCP[0].Item.ItemsElementName = new gView.Framework.OGC.WMTS.Version_1_0_0.ItemsChoiceType[] { gView.Framework.OGC.WMTS.Version_1_0_0.ItemsChoiceType.Get };


            var getTileOperation = new gView.Framework.OGC.WMTS.Version_1_0_0.Operation()
            {
                name = "GetTile"
            };
            getTileOperation.DCP               = new gView.Framework.OGC.WMTS.Version_1_0_0.DCP[] { new gView.Framework.OGC.WMTS.Version_1_0_0.DCP() };
            getTileOperation.DCP[0].Item       = new gView.Framework.OGC.WMTS.Version_1_0_0.HTTP();
            getTileOperation.DCP[0].Item.Items = new gView.Framework.OGC.WMTS.Version_1_0_0.RequestMethodType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.RequestMethodType() };

            getTileOperation.DCP[0].Item.Items[0].href                        = restFulUrl;
            getTileOperation.DCP[0].Item.Items[0].Constraint                  = new gView.Framework.OGC.WMTS.Version_1_0_0.DomainType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.DomainType() };
            getTileOperation.DCP[0].Item.Items[0].Constraint[0].name          = "GetEncoding";
            getTileOperation.DCP[0].Item.Items[0].Constraint[0].AllowedValues = new object[] { new gView.Framework.OGC.WMTS.Version_1_0_0.ValueType()
                                                                                               {
                                                                                                   Value = "RESTful"
                                                                                               } };
            getTileOperation.DCP[0].Item.ItemsElementName = new gView.Framework.OGC.WMTS.Version_1_0_0.ItemsChoiceType[] { gView.Framework.OGC.WMTS.Version_1_0_0.ItemsChoiceType.Get };

            capabilities.OperationsMetadata.Operation = new gView.Framework.OGC.WMTS.Version_1_0_0.Operation[]
            {
                getCapOperation, getTileOperation
            };

            #endregion

            #region Contents

            capabilities.Contents = new gView.Framework.OGC.WMTS.Version_1_0_0.ContentsType();

            List <gView.Framework.OGC.WMTS.Version_1_0_0.LayerType>     layers     = new List <gView.Framework.OGC.WMTS.Version_1_0_0.LayerType>();
            List <gView.Framework.OGC.WMTS.Version_1_0_0.TileMatrixSet> matrixSets = new List <gView.Framework.OGC.WMTS.Version_1_0_0.TileMatrixSet>();

            ISpatialReference sRef4326 = SpatialReference.FromID("epsg:4326");

            foreach (var epsg in metadata.EPSGCodes)
            {
                IEnvelope extent = metadata.GetEPSGEnvelope(epsg);
                if (extent == null)
                {
                    Console.WriteLine($"EPSG { epsg }: Envelope not exits");
                    continue;
                }

                IPoint origin = metadata.GetOriginUpperLeft(epsg);
                if (origin == null)
                {
                    Console.WriteLine($"EPSG { epsg }: Origin not exits");
                    continue;
                }

                ISpatialReference sRef       = SpatialReference.FromID("epsg:" + epsg);
                IEnvelope         extent4326 = GeometricTransformerFactory.Transform2D(extent, sRef, sRef4326).Envelope;

                if (double.IsInfinity(extent4326.minx))
                {
                    extent4326.minx = -180D;
                }

                if (double.IsInfinity(extent4326.miny))
                {
                    extent4326.miny = -90D;
                }

                if (double.IsInfinity(extent4326.maxx))
                {
                    extent4326.maxx = 180D;
                }

                if (double.IsInfinity(extent4326.maxy))
                {
                    extent4326.maxy = 90D;
                }

                foreach (string cacheType in new string[] { "classic", "compact" })
                {
                    string epsgPath = _mapServer.TileCachePath + @"/" + MapName(context) + @"/_alllayers/" + (cacheType == "compact" ? @"compact/" : "") +
                                      TileServiceMetadata.EpsgPath(GridOrientation.UpperLeft, epsg);

                    if (!new DirectoryInfo(epsgPath).Exists)
                    {
                        Console.WriteLine($"Path { epsgPath }: not exists");
                        continue;
                    }

                    #region Layer

                    string layerName = /*Capabilities*/ MapName(context) + " EPSG:" + epsg + " " + cacheType;
                    string layerId   = /*Capabilities*/ MapName(context).ToLower().Replace(" ", "_") + "_" + epsg + "_" + cacheType;

                    var layer = new gView.Framework.OGC.WMTS.Version_1_0_0.LayerType();

                    layer.Title = new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType()
                                                                                                    {
                                                                                                        Value = layerName
                                                                                                    } };
                    layer.Identifier = new gView.Framework.OGC.WMTS.Version_1_0_0.CodeType()
                    {
                        Value = layerId
                    };

                    List <gView.Framework.OGC.WMTS.Version_1_0_0.Style> styles = new List <Framework.OGC.WMTS.Version_1_0_0.Style>();
                    //styles.Add(new gView.Framework.OGC.WMTS.Version_1_0_0.Style()
                    //{
                    //    Title = new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType() { Value = "Default Style" } },
                    //    Identifier = new gView.Framework.OGC.WMTS.Version_1_0_0.CodeType() { Value = "default" }
                    //});
                    foreach (FilterImplementations styleVal in Enum.GetValues(typeof(FilterImplementations)))
                    {
                        string name = Enum.GetName(typeof(FilterImplementations), styleVal);
                        styles.Add(new Framework.OGC.WMTS.Version_1_0_0.Style()
                        {
                            isDefault = styleVal == FilterImplementations.Default,
                            Title     = new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType()
                                                                                                          {
                                                                                                              Value = name
                                                                                                          } },
                            Identifier = new gView.Framework.OGC.WMTS.Version_1_0_0.CodeType()
                            {
                                Value = name.ToLower()
                            }
                        });
                    }

                    layer.Style = styles.ToArray();

                    #region BoundingBox

                    layer.BoundingBox = new gView.Framework.OGC.WMTS.Version_1_0_0.BoundingBoxType[]
                    {
                        new gView.Framework.OGC.WMTS.Version_1_0_0.BoundingBoxType()
                        {
                            crs         = "urn:ogc:def:crs:EPSG::" + epsg,
                            LowerCorner = PointToString(extent.LowerLeft, sRef),
                            UpperCorner = PointToString(extent.UpperRight, sRef)
                        }
                    };
                    layer.WGS84BoundingBox = new gView.Framework.OGC.WMTS.Version_1_0_0.WGS84BoundingBoxType[]
                    {
                        new gView.Framework.OGC.WMTS.Version_1_0_0.WGS84BoundingBoxType()
                        {
                            crs         = "urn:ogc:def:crs:OGC:2:84", // urn:ogc:def:crs:OGC:2:84
                            LowerCorner = PointToString(extent4326.LowerLeft, /*sRef4326*/ null),
                            UpperCorner = PointToString(extent4326.UpperRight, /*sRef4326*/ null)
                        }
                    };

                    #endregion

                    layer.TileMatrixSetLink = new gView.Framework.OGC.WMTS.Version_1_0_0.TileMatrixSetLink[]
                    {
                        new gView.Framework.OGC.WMTS.Version_1_0_0.TileMatrixSetLink()
                        {
                            TileMatrixSet = layerId + "_default_matrixset"
                        }
                    };

                    List <string> formats = new List <string>();
                    if (metadata.FormatJpg)
                    {
                        formats.Add("image/jpg");
                    }

                    if (metadata.FormatPng)
                    {
                        formats.Add("image/png");
                    }

                    layer.Format = formats.ToArray();

                    List <Framework.OGC.WMTS.Version_1_0_0.URLTemplateType> resourceURLs = new List <Framework.OGC.WMTS.Version_1_0_0.URLTemplateType>();
                    if (metadata.FormatJpg)
                    {
                        resourceURLs.Add(new Framework.OGC.WMTS.Version_1_0_0.URLTemplateType()
                        {
                            resourceType = Framework.OGC.WMTS.Version_1_0_0.URLTemplateTypeResourceType.tile,
                            format       = "image/jpg",
                            template     = restFulUrl + "/" + cacheType + "/ul/" + epsg + "/{Style}/{TileMatrix}/{TileRow}/{TileCol}.jpg"
                        });
                    }
                    if (metadata.FormatPng)
                    {
                        resourceURLs.Add(new Framework.OGC.WMTS.Version_1_0_0.URLTemplateType()
                        {
                            resourceType = Framework.OGC.WMTS.Version_1_0_0.URLTemplateTypeResourceType.tile,
                            format       = "image/png",
                            template     = restFulUrl + "/" + cacheType + "/ul/" + epsg + "/{Style}/{TileMatrix}/{TileRow}/{TileCol}.png"
                        });
                    }
                    layer.ResourceURL = resourceURLs.ToArray();

                    layers.Add(layer);

                    #endregion

                    #region Matrix Set

                    double matrixSetWidth  = Math.Abs(extent.maxx - origin.X); // extent.Width;
                    double matrixSetHeight = Math.Abs(origin.Y - extent.miny); // extent.Height;

                    var matrixSet = new gView.Framework.OGC.WMTS.Version_1_0_0.TileMatrixSet();

                    matrixSet.Title = new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType()
                                                                                                        {
                                                                                                            Value = layerName + " Default Matrix Set"
                                                                                                        } };
                    matrixSet.Identifier = new gView.Framework.OGC.WMTS.Version_1_0_0.CodeType()
                    {
                        Value = layerId + "_default_matrixset"
                    };
                    matrixSet.SupportedCRS = "urn:ogc:def:crs:EPSG::" + epsg;

                    matrixSet.TileMatrix = new gView.Framework.OGC.WMTS.Version_1_0_0.TileMatrix[metadata.Scales.Count];

                    #region DPI

                    double inchMeter = 0.0254;                    /* 0.0254000508001016;*/
                    double dpi       = inchMeter * 1000D / 0.28D; // wmts 0.28mm -> 1 Pixel;
                    double dpm       = dpi / inchMeter;

                    #endregion

                    for (int s = 0, to = metadata.Scales.Count; s < to; s++)
                    {
                        string scalePath = _mapServer.TileCachePath + @"/" + MapName(context) + @"/_alllayers/" + (cacheType == "compact" ? @"compact/" : "") +
                                           TileServiceMetadata.ScalePath(GridOrientation.UpperLeft, epsg, metadata.Scales[s]);

                        if (!new DirectoryInfo(scalePath).Exists)
                        {
                            break;
                        }

                        double resolution = metadata.Scales[s] / (metadata.Dpi / inchMeter);

                        matrixSet.TileMatrix[s]            = new gView.Framework.OGC.WMTS.Version_1_0_0.TileMatrix();
                        matrixSet.TileMatrix[s].Identifier = new gView.Framework.OGC.WMTS.Version_1_0_0.CodeType()
                        {
                            Value = s.ToString()
                        };
                        matrixSet.TileMatrix[s].TopLeftCorner = PointToString(origin, sRef);
                        matrixSet.TileMatrix[s].TileWidth     = metadata.TileWidth.ToString();
                        matrixSet.TileMatrix[s].TileHeight    = metadata.TileHeight.ToString();

                        double tileWidth  = metadata.TileWidth * resolution;
                        double tileHeight = metadata.TileHeight * resolution;

                        int matrixWidth  = (int)Math.Round(matrixSetWidth / tileWidth + 0.5);
                        int matrixHeight = (int)Math.Round(matrixSetHeight / tileHeight + 0.5);

                        matrixSet.TileMatrix[s].MatrixWidth      = matrixWidth.ToString();
                        matrixSet.TileMatrix[s].MatrixHeight     = matrixHeight.ToString();
                        matrixSet.TileMatrix[s].ScaleDenominator = resolution * dpm;
                    }

                    matrixSets.Add(matrixSet);

                    #endregion
                }
            }

            capabilities.Contents.DatasetDescriptionSummary = layers.ToArray();
            capabilities.Contents.TileMatrixSet             = matrixSets.ToArray();

            #endregion

            XsdSchemaSerializer <gView.Framework.OGC.WMTS.Version_1_0_0.Capabilities> ser = new XsdSchemaSerializer <gView.Framework.OGC.WMTS.Version_1_0_0.Capabilities>();
            string xml = ser.Serialize(capabilities, null);

            xml = xml.Replace(@"<ows:DatasetDescriptionSummary xsi:type=""LayerType"">", "<Layer>");
            xml = xml.Replace(@"</ows:DatasetDescriptionSummary>", "</Layer>");

            context.ServiceRequest.ResponseContentType = "text/xml";
            context.ServiceRequest.Response            = xml;
        }
예제 #21
0
        public void AddFeature(IFeature feature, ISpatialReference sRef, IFeatureLayer layer, string Category, IFields fields, IField primaryDisplayField)
        {
            if (feature == null)
            {
                return;
            }

            if (layer != null)
            {
                if (fields == null)
                {
                    fields = layer.Fields;
                }
                if (primaryDisplayField == null)
                {
                    primaryDisplayField = layer.Fields.PrimaryDisplayField;
                }
            }

            if (Category == "")
            {
                Category = "Results";
            }
            CategoryTreeNode parent = null;

            foreach (CategoryTreeNode node in treeObjects.Nodes)
            {
                if (node.Category == Category)
                {
                    parent = node;
                    break;
                }
            }
            if (parent == null)
            {
                parent = new CategoryTreeNode(Category, _doc, layer);
                treeObjects.Nodes.Add(parent);
            }

            parent.Nodes.Add(new FeatureTreeNode(_doc, feature, sRef, layer, (primaryDisplayField != null) ? primaryDisplayField.name : "", 1));

            if (fields != null && feature.Fields != null)
            {
                List <FieldValue> fvs = gView.Framework.system.ListOperations <FieldValue> .Clone(feature.Fields);

                feature.Fields.Clear();

                foreach (IField field in fields.ToEnumerable())
                {
                    if (!field.visible)
                    {
                        continue;
                    }
                    for (int i = 0; i < fvs.Count; i++)
                    {
                        if (fvs[i].Name == field.name)
                        {
                            feature.Fields.Add(new FieldValue(field.aliasname, fvs[i].Value));
                            fvs.RemoveAt(i);
                            break;
                        }
                    }
                }
            }

            if (treeObjects.SelectedNode == null)
            {
                treeObjects.SelectedNode = parent.Nodes[0];

                if (_doc != null && _doc.FocusMap != null && _doc.FocusMap.Display != null)
                {
                    IGeometry shape = feature.Shape;
                    if (sRef != null && !sRef.Equals(_doc.FocusMap.Display.SpatialReference))
                    {
                        shape = GeometricTransformerFactory.Transform2D(shape, sRef, _doc.FocusMap.Display.SpatialReference);
                    }
                    _doc.FocusMap.HighlightGeometry(shape, 300);
                }
                //parent.ExpandAll();
                parent.Expand();
                if (parent.Nodes.Count > 0)
                {
                    parent.Nodes[0].Expand();
                }
            }
        }
예제 #22
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (_map == null || _display == null)
            {
                return;
            }

            try
            {
                bool refresh = false;

                _map.Name         = txtName.Text;
                _display.refScale = Convert.ToDouble(numRefScale.Value);

                if (cmbMapUnits.Enabled)
                {
                    _display.MapUnits = ((GeoUnitsItem)cmbMapUnits.SelectedItem).Unit;
                }

                _display.DisplayUnits = ((GeoUnitsItem)cmbDisplayUnits.SelectedItem).Unit;

                _display.BackgroundColor = btnBackgroundColor.BackColor.ToArgbColor();

                ISpatialReference oldSRef = _display.SpatialReference;
                _display.SpatialReference = _sr.SpatialReference;

                if (oldSRef != null &&
                    !oldSRef.Equals(_display.SpatialReference))
                {
                    IEnvelope limit = _display.Limit;
                    IEnvelope env   = _display.Envelope;

                    _display.Limit = GeometricTransformerFactory.Transform2D(
                        limit,
                        oldSRef,
                        _display.SpatialReference).Envelope;

                    _display.ZoomTo(
                        GeometricTransformerFactory.Transform2D(
                            env,
                            oldSRef,
                            _display.SpatialReference).Envelope
                        );
                }

                _map.LayerDefaultSpatialReference = _sr2.SpatialReference;

                _map.Title = txtTitle.Text;
                _map.SetLayerDescription(Map.MapDescriptionId, txtDescription.Text);
                _map.SetLayerCopyrightText(Map.MapCopyrightTextId, txtCopyright.Text);

                if (SystemVariables.SystemFontsScaleFactor != (float)numFontScaleFactor.Value / 100f)
                {
                    SystemVariables.SystemFontsScaleFactor = (float)numFontScaleFactor.Value / 100f;
                    _display.Screen?.RefreshSettings();

                    refresh = true;
                }

                #region Graphics Engine

                if (cmbGraphicsEngine.SelectedItem.ToString() != GraphicsEngine.Current.Engine.EngineName)
                {
                    var engine = Engines.RegisteredGraphcisEngines().Where(ge => ge.EngineName == cmbGraphicsEngine.SelectedItem.ToString()).FirstOrDefault();
                    if (engine != null)
                    {
                        GraphicsEngine.Current.Engine = engine;
                        RefreshFeatureRendererSymbolsGraphcisEngine();

                        refresh = true;
                    }
                }

                #endregion Graphics Engine

                if (refresh)
                {
                    if (_app != null)
                    {
                        _app.RefreshTOC();
                        _app.RefreshActiveMap(DrawPhase.All);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #23
0
파일: WMSTheme.cs 프로젝트: jugstalt/gview5
        public Task <ICursor> PointQuery(gView.Framework.Carto.IDisplay display, gView.Framework.Geometry.IPoint point, ISpatialReference sRef, IUserData userdata)
        {
            if (display == null || point == null)
            {
                return(Task.FromResult <ICursor>(null));
            }

            IEnvelope dispEnvelope = display.Envelope;

            if (sRef != null)
            {
                ISpatialReference mySRef = SpatialReference.FromID(_srs.Srs[_srs.SRSIndex]);
                if (mySRef != null && !mySRef.Equals(sRef))
                {
                    // TODO:
                    // Stimmt net ganz, eigentlich wird beim Projezieren aus dem
                    // Envelope ein Polygon, auch der Punkt, der als X-Pixel, Y-Pixel
                    // übergeben wird, sollte sich ändern...
                    // --> World2Image stimmt nicht 100%
                    //
                    dispEnvelope = GeometricTransformerFactory.Transform2D(dispEnvelope, sRef, mySRef).Envelope;
                }
            }
            double x = point.X, y = point.Y;

            display.World2Image(ref x, ref y);

            StringBuilder request = new StringBuilder("VERSION=1.1.1&REQUEST=GetFeatureInfo");

            request.Append("&QUERY_LAYERS=" + this.Name);
            request.Append("&QUERYLAYERS=" + this.Name);
            request.Append("&LAYERS=" + this.Name);
            //request.Append("&LAYERS=" + this.Name);
            request.Append("&EXCEPTIONS=" + _exceptions.Formats[0]);
            request.Append("&SRS=" + _srs.Srs[_srs.SRSIndex]);
            request.Append("&WIDTH=" + display.iWidth);
            request.Append("&HEIGHT=" + display.iHeight);
            request.Append("&INFOFORMAT=" + _getFeatureInfo.Formats[_getFeatureInfo.FormatIndex]);
            request.Append("&INFO_FORMAT=" + _getFeatureInfo.Formats[_getFeatureInfo.FormatIndex]);
            request.Append("&BBOX=" + dispEnvelope.minx.ToString(_nhi) + "," +
                           dispEnvelope.miny.ToString(_nhi) + "," +
                           dispEnvelope.maxx.ToString(_nhi) + "," +
                           dispEnvelope.maxy.ToString(_nhi));
            request.Append("&X=" + (int)x);
            request.Append("&Y=" + (int)y);

            string response;

            if (_getFeatureInfo.Formats[_getFeatureInfo.FormatIndex].ToLower().StartsWith("xsl/"))
            {
                return(Task.FromResult <ICursor>(new UrlCursor(WMSDataset.Append2Url(_getFeatureInfo.Get_OnlineResource, request.ToString()))));
            }
            else
            {
                switch (_getFeatureInfo.Formats[_getFeatureInfo.FormatIndex].ToLower())
                {
                case "text/plain":
                    response = WebFunctions.HttpSendRequest(WMSDataset.Append2Url(_getFeatureInfo.Get_OnlineResource, request.ToString()));
                    return(Task.FromResult <ICursor>(new TextCursor(response)));

                case "text/html":
                    return(Task.FromResult <ICursor>(new UrlCursor(WMSDataset.Append2Url(_getFeatureInfo.Get_OnlineResource, request.ToString()))));

                case "text/xml":
                    response = WebFunctions.HttpSendRequest(WMSDataset.Append2Url(_getFeatureInfo.Get_OnlineResource, request.ToString()));
                    return(Task.FromResult <ICursor>(new RowCursor(Xml2Rows(response))));

                case "application/vnd.ogc.gml":
                    response = WebFunctions.HttpSendRequest(WMSDataset.Append2Url(_getFeatureInfo.Get_OnlineResource, request.ToString()));
                    return(Task.FromResult <ICursor>(new RowCursor(Gml2Rows(response))));
                }
            }
            return(null);
        }