Exemplo n.º 1
0
        async public Task <IRasterLayerCursor> ChildLayers(gView.Framework.Carto.IDisplay display, string filterClause)
        {
            if (_fc == null || display == null || _fdb == null)
            {
                return(new SimpleRasterlayerCursor(new List <IRasterLayer>()));
            }

            double dpm = Math.Max(display.Canvas.DpiX, display.Canvas.DpiY) / 0.0254;
            double pix = display.mapScale / dpm; /*display.dpm;*/                              // [m]

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

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

            SpatialFilter filter = new SpatialFilter();

            filter.Geometry        = dispEnvelope;
            filter.SubFields       = "*";
            filter.WhereClause     = filterClause;
            filter.SpatialRelation = spatialRelation.SpatialRelationIntersects;

            return(new RasterLayerCursor(this, await _fc.Search(filter) as IFeatureCursor,
                                         dispEnvelope, pix));
        }
        public void BeginPaint(gView.Framework.Carto.IDisplay display, ICancelTracker cancelTracker)
        {
            throw new NotImplementedException();
            //if (_fdb == null) return;
            //try
            //{
            //    DataTable tab = _fdb._conn.Select("IMAGE,X,Y,dx1,dx2,dy1,dy2", _dsname + "_IMAGE_DATA", "ID=" + _ID);
            //    if (tab == null) return;
            //    if (tab.Rows.Count != 1) return;
            //    DataRow row = tab.Rows[0];

            //    _bm = (System.Drawing.Bitmap)ImageFast.FromStream((byte[])row["IMG"]);
            //    _X = (double)tab.Rows[0]["X"];
            //    _Y = (double)tab.Rows[0]["Y"];
            //    _dx_X = (double)tab.Rows[0]["dx1"];
            //    _dx_Y = (double)tab.Rows[0]["dx2"];
            //    _dy_X = (double)tab.Rows[0]["dy1"];
            //    _dy_Y = (double)tab.Rows[0]["dy2"];
            //    _iWidth = _bm.Width;
            //    _iHeight = _bm.Height;
            //}
            //catch
            //{
            //    EndPaint(cancelTracker);
            //}
        }
Exemplo n.º 3
0
        async public Task <IRasterPaintContext> BeginPaint(gView.Framework.Carto.IDisplay display, ICancelTracker cancelTracker)
        {
            if (_fdb == null)
            {
                return(null);
            }

            DataTable tab = await _fdb._conn.Select("IMAGE,X,Y,dx1,dx2,dy1,dy2", _dsname + "_IMAGE_DATA", "ID=" + _ID);

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

            if (tab.Rows.Count != 1)
            {
                return(null);
            }

            DataRow row = tab.Rows[0];

            var bitmap = Current.Engine.CreateBitmap(new MemoryStream((byte[])row["IMG"]));

            _X       = (double)tab.Rows[0]["X"];
            _Y       = (double)tab.Rows[0]["Y"];
            _dx_X    = (double)tab.Rows[0]["dx1"];
            _dx_Y    = (double)tab.Rows[0]["dx2"];
            _dy_X    = (double)tab.Rows[0]["dy1"];
            _dy_Y    = (double)tab.Rows[0]["dy2"];
            _iWidth  = bitmap.Width;
            _iHeight = bitmap.Height;

            return(new RasterPaintContext(bitmap));
        }
Exemplo n.º 4
0
        public void BeginPaint(gView.Framework.Carto.IDisplay display, ICancelTracker cancelTracker)
        {
            if (_fdb == null)
            {
                return;
            }
            try
            {
                DataTable tab = _fdb._conn.Select("IMAGE,X,Y,dx1,dx2,dy1,dy2", _dsname + "_IMAGE_DATA", "ID=" + _ID);
                if (tab == null)
                {
                    return;
                }
                if (tab.Rows.Count != 1)
                {
                    return;
                }
                DataRow row = tab.Rows[0];

                _bm      = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(new MemoryStream((byte[])row["IMG"]));
                _X       = (double)tab.Rows[0]["X"];
                _Y       = (double)tab.Rows[0]["Y"];
                _dx_X    = (double)tab.Rows[0]["dx1"];
                _dx_Y    = (double)tab.Rows[0]["dx2"];
                _dy_X    = (double)tab.Rows[0]["dy1"];
                _dy_Y    = (double)tab.Rows[0]["dy2"];
                _iWidth  = _bm.Width;
                _iHeight = _bm.Height;
            }
            catch
            {
                EndPaint(cancelTracker);
            }
        }
Exemplo n.º 5
0
 public void BeginPaint(gView.Framework.Carto.IDisplay display, ICancelTracker cancelTracker)
 {
     if (_stream != null)
     {
         EndPaint(cancelTracker);
     }
     _stream = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read);
 }
Exemplo n.º 6
0
        async public Task <ICursor> PointQuery(gView.Framework.Carto.IDisplay display, IPoint point, ISpatialReference sRef, IUserData userdata)
        {
            PointCollection pColl = new PointCollection();

            pColl.AddPoint(point);

            return(await MultiPointQuery(display, pColl, sRef, userdata));
        }
Exemplo n.º 7
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]);
                }
            }
        }
Exemplo n.º 8
0
        public Task <IRasterLayerCursor> ChildLayers(gView.Framework.Carto.IDisplay display, string filterClause)
        {
            if (_dataset == null || _dataset.Extent == null || _dataset.Scales == null)
            {
                return(null);
            }

            double dpi = 96.0;  // gView Default... //25.4D / 0.28D;   // wmts 0.28mm -> 1 Pixel in WebMercator;

            // !!!! Only correct, if diplay unit is meter !!!!
            double displayResolution = display.mapScale / (display.dpi / 0.0254);

            Grid grid = new Grid(new Point(_dataset.Extent.minx, _dataset.Extent.maxx), _dataset.TileWidth, _dataset.TileHeight, dpi, _dataset.Origin);

            for (int i = 0, to = _dataset.Scales.Length; i < to; i++)
            {
                grid.AddLevel(i, _dataset.Scales[i] / (dpi / 0.0254));
            }

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

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

            int    level = grid.GetBestLevel(displayResolution, 90D);
            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(_dataset.Extent.Width / (_dataset.TileWidth * res), 0) - 1, Math.Max(col0, col1));
            int row_from = Math.Max(0, Math.Min(row0, row1)), row_to = Math.Min((int)Math.Round(_dataset.Extent.Height / (_dataset.TileHeight * res), 0) - 1, Math.Max(row0, row1));

            LayerCursor cursor = new LayerCursor();

            for (int r = row_from; r <= row_to; r++)
            {
                for (int c = col_from; c <= col_to; c++)
                {
                    cursor.Layers.Add(
                        new RasterTile(_dataset, grid, level, r, c, res));
                }
            }
            cursor.Layers.Sort(new TileSorter(dispEnvelope.Center));

            return(Task.FromResult <IRasterLayerCursor>(cursor));
        }
Exemplo n.º 9
0
 public void BeginPaint(gView.Framework.Carto.IDisplay display, ICancelTracker cancelTracker)
 {
     try
     {
         byte[] buffer = new byte[_header.streamLength];
         _stream.Position = _header.startPosition;
         _stream.Read(buffer, 0, _header.streamLength);
         _bm = (System.Drawing.Bitmap)ImageFast.FromStream(buffer);
     }
     catch
     {
         EndPaint(cancelTracker);
     }
 }
Exemplo n.º 10
0
        public IRasterLayerCursor ChildLayers(gView.Framework.Carto.IDisplay display, string filterClause)
        {
            List <IRasterLayer> layers = new List <IRasterLayer>();

            double dpm = Math.Max(display.GraphicsContext.DpiX, display.GraphicsContext.DpiY) / 0.0254;
            double pix = display.mapScale / dpm; /*display.dpm;*/  // [m]

            // Level bestimmen
            int level = 1;

            foreach (PyramidLevelHeader levHeader in _levelHeader)
            {
                if (levHeader.cellX <= pix && levHeader.cellY <= pix)
                {
                    level = levHeader.level;
                }
            }

            IEnvelope dispEnvelope = display.Envelope;

            if (display.GeometricTransformer != null)
            {
                dispEnvelope = (IEnvelope)((IGeometry)display.GeometricTransformer.InvTransform2D(dispEnvelope)).Envelope;
            }
            IGeometryDef geomDef = new GeometryDef(geometryType.Polygon, null, true);

            foreach (PyramidPictureHeader picHeader in _picHeader)
            {
                if (picHeader.level != level)
                {
                    continue;
                }

                IPolygon polygon = picHeader.CreatePolygon();
                if (gView.Framework.SpatialAlgorithms.Algorithm.IntersectBox(polygon, dispEnvelope))
                {
                    PyramidFileImageClass pClass = new PyramidFileImageClass(_stream, picHeader, polygon);
                    RasterLayer           rLayer = new RasterLayer(pClass);
                    rLayer.InterpolationMethod = this.InterpolationMethod;
                    if (pClass.SpatialReference == null)
                    {
                        pClass.SpatialReference = _sRef;
                    }
                    layers.Add(rLayer);
                }
            }
            return(new SimpleRasterlayerCursor(layers));
        }
Exemplo n.º 11
0
        async public Task <ICursor> MultiPointQuery(gView.Framework.Carto.IDisplay dispaly, IPointCollection points, ISpatialReference sRef, IUserData userdata)
        {
            IMultiPoint         mPoint = new MultiPoint(points);
            List <IRasterLayer> layers = await QueryChildLayers(mPoint, String.Empty);

            if (layers == null || layers.Count == 0)
            {
                return(null);
            }

            List <IRow> cursorRows = new List <IRow>();

            for (int i = 0; i < mPoint.PointCount; i++)
            {
                IPoint point = mPoint[i];
                foreach (IRasterLayer layer in layers)
                {
                    if (layer == null ||
                        !(layer.Class is IRasterClass) ||
                        !(layer.Class is IPointIdentify))
                    {
                        continue;
                    }

                    if (gView.Framework.SpatialAlgorithms.Algorithm.Jordan(
                            ((IRasterClass)layer.Class).Polygon,
                            point.X, point.Y))
                    {
                        using (ICursor cursor = await((IPointIdentify)layer.Class).PointQuery(dispaly, point, sRef, userdata))
                        {
                            if (cursor is IRowCursor)
                            {
                                IRow row;
                                while ((row = await((IRowCursor)cursor).NextRow()) != null)
                                {
                                    row.Fields.Add(new FieldValue("x", point.X));
                                    row.Fields.Add(new FieldValue("y", point.Y));
                                    cursorRows.Add(row);
                                }
                            }
                        }
                    }
                }
            }

            return(new SimpleRowCursor(cursorRows));
        }
Exemplo n.º 12
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));;
        }
Exemplo n.º 13
0
 public Task <IRasterPaintContext> BeginPaint(gView.Framework.Carto.IDisplay display, ICancelTracker cancelTracker)
 {
     return(Task.FromResult <IRasterPaintContext>(new RasterPaintContext(null)));
 }
Exemplo n.º 14
0
        async public Task <bool> MapRequest(gView.Framework.Carto.IDisplay display)
        {
            if (_dataset == null)
            {
                return(false);
            }

            List <IWebServiceTheme> themes = Themes;

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

            #region Check for visible Layers

            bool visFound = this.Themes.Where(l => l.Visible).Count() > 0;
            if (!visFound)
            {
                if (_image != null)
                {
                    _image.Dispose();
                    _image = null;
                }
                return(true);
            }

            #endregion Check for visible Layers

            var serviceUrl = _dataset.ServiceUrl();

            //IServiceRequestContext context = display.Map as IServiceRequestContext;

            var jsonExportMap = new JsonExportMap();
            if (display?.Envelope != null)
            {
                var env = display.Envelope;
                jsonExportMap.BBox = $"{env.minx.ToDoubleString()},{env.miny.ToDoubleString()},{env.maxx.ToDoubleString()},{env.maxy.ToDoubleString()}";
            }

            var sRef = display.SpatialReference ?? this.SpatialReference;
            if (sRef != null)
            {
                jsonExportMap.BBoxSRef = sRef.Name.ToLower().Replace("epsg:", "");
            }
            jsonExportMap.Size = $"{display.iWidth},{display.iHeight}";

            var layerIds = this.Themes
                           .Where(l => l.Visible && (l.Class is IWebFeatureClass || l.Class is IWebRasterClass))
                           .Select(l =>
            {
                if (l.Class is IWebFeatureClass)
                {
                    return(((IWebFeatureClass)l.Class).ID);
                }

                if (l.Class is IWebRasterClass)
                {
                    return(((IWebRasterClass)l.Class).ID);
                }

                return(String.Empty);
            });

            jsonExportMap.Layers = $"show:{String.Join(",", layerIds)}";

            var urlParameters = SerializeToUrlParameters(jsonExportMap);

            var response = await _dataset.TryPostAsync <JsonExportResponse>(
                serviceUrl
                .UrlAppendPath("export")
                .UrlAppendParameters("f=json")
                .UrlAppendParameters(urlParameters));

            bool hasImage = false;
            if (!String.IsNullOrWhiteSpace(response.Href))
            {
                var bm = WebFunctions.DownloadImage(response.Href);
                if (bm != null)
                {
                    hasImage = true;
                    _image   = new GeorefBitmap(bm);
                    if (response.Extent != null)
                    {
                        _image.Envelope = new Envelope(response.Extent.Xmin, response.Extent.Ymin, response.Extent.Xmax, response.Extent.Ymax);
                    }
                    _image.SpatialReference = sRef;
                }
            }

            if (!hasImage)
            {
                if (_image != null)
                {
                    _image.Dispose();
                    _image = null;
                }
                return(false);
            }

            return(true);

            return(true);
        }
Exemplo n.º 15
0
        public void BeginPaint(gView.Framework.Carto.IDisplay display, ICancelTracker cancelTracker)
        {
            EndPaint(cancelTracker);
            try
            {
                if (!(_polygon is ITopologicalOperation))
                {
                    return;
                }

                TFWFile tfw = this.WorldFile as TFWFile;
                if (tfw == null)
                {
                    return;
                }

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

                IGeometry clipped;
                ((ITopologicalOperation)_polygon).Clip(dispEnvelope, out clipped);
                if (!(clipped is IPolygon))
                {
                    return;
                }

                IPolygon cPolygon = (IPolygon)clipped;

                // geclipptes Polygon transformieren -> Bild
                vector2[] vecs = new vector2[cPolygon[0].PointCount];
                for (int i = 0; i < cPolygon[0].PointCount; i++)
                {
                    vecs[i] = new vector2(cPolygon[0][i].X, cPolygon[0][i].Y);
                }
                if (!tfw.ProjectInv(vecs))
                {
                    return;
                }
                IEnvelope picEnv = vector2.IntegerEnvelope(vecs);
                picEnv.minx = Math.Max(0, picEnv.minx);
                picEnv.miny = Math.Max(0, picEnv.miny);
                picEnv.maxx = Math.Min(picEnv.maxx, _iWidth);
                picEnv.maxy = Math.Min(picEnv.maxy, _iHeight);

                // Ecken zurücktransformieren -> Welt
                vecs    = new vector2[3];
                vecs[0] = new vector2(picEnv.minx, picEnv.miny);
                vecs[1] = new vector2(picEnv.maxx, picEnv.miny);
                vecs[2] = new vector2(picEnv.minx, picEnv.maxy);
                tfw.Project(vecs);
                _p1 = new gView.Framework.Geometry.Point(vecs[0].x, vecs[0].y);
                _p2 = new gView.Framework.Geometry.Point(vecs[1].x, vecs[1].y);
                _p3 = new gView.Framework.Geometry.Point(vecs[2].x, vecs[2].y);

                double pix = display.mapScale / (display.dpi / 0.0254);  // [m]
                double c1  = Math.Sqrt(_tfw.dx_X * _tfw.dx_X + _tfw.dx_Y * _tfw.dx_Y);
                double c2  = Math.Sqrt(_tfw.dy_Y * _tfw.dy_Y + _tfw.dy_X * _tfw.dy_X);
                double mag = Math.Min(c1, c2) / pix;

                if (mag > 1.0)
                {
                    mag = 1.0;
                }

                int x       = (int)(picEnv.minx);
                int y       = (int)(picEnv.miny);
                int wWidth  = (int)(picEnv.Width);
                int wHeight = (int)(picEnv.Height);

                //if (wWidth + x > _iWidth) wWidth = _iWidth - x;
                //if (wHeight + y > _iHeight) wHeight = _iHeight - y;

                int iWidth  = (int)(wWidth * mag);
                int iHeight = (int)(wHeight * mag);

                switch (_type)
                {
                case RasterType.image:
                    PaintImage(x, y, wWidth, wHeight, iWidth, iHeight, cancelTracker);
                    break;

                case RasterType.wavelet:
                    PaintWavelet(x, y, wWidth, wHeight, iWidth, iHeight, cancelTracker);
                    break;

                case RasterType.grid:
                    if (_renderRawGridValues)
                    {
                        PaintGrid(x, y, wWidth, wHeight, iWidth, iHeight);
                    }
                    else
                    {
                        PaintHillShade(x, y, wWidth, wHeight, iWidth, iHeight, mag, cancelTracker);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                string errMsg = ex.Message;
                EndPaint(cancelTracker);
            }
            finally
            {
            }
        }
Exemplo n.º 16
0
 public bool LegendRequest(gView.Framework.Carto.IDisplay display)
 {
     return(false);
 }
Exemplo n.º 17
0
        public bool MapRequest(gView.Framework.Carto.IDisplay display)
        {
            if (_dataset == null)
            {
                return(false);
            }
            if (!_dataset._opened)
            {
                _dataset.Open();
            }

            IServiceRequestContext context = display.Map as IServiceRequestContext;

            try
            {
                ISpatialReference sRef = (display.SpatialReference != null) ?
                                         display.SpatialReference.Clone() as ISpatialReference :
                                         null;

                StringBuilder sb = new StringBuilder();
                sb.Append("<?xml version='1.0' encoding='utf-8'?>");
                sb.Append("<ARCXML version='1.1'>");
                sb.Append("<REQUEST>");
                sb.Append("<GET_IMAGE>");
                sb.Append("<PROPERTIES>");
                sb.Append("<ENVELOPE minx='" + display.Envelope.minx.ToString() + "' miny='" + display.Envelope.miny.ToString() + "' maxx='" + display.Envelope.maxx.ToString() + "' maxy='" + display.Envelope.maxy.ToString() + "' />");
                sb.Append("<IMAGESIZE width='" + display.iWidth + "' height='" + display.iHeight + "' />");
                sb.Append("<BACKGROUND color='255,255,255' transcolor='255,255,255' />");
                //if (display.SpatialReference != null && !display.SpatialReference.Equals(_sRef))
                //{
                //    string map_param = gView.Framework.Geometry.SpatialReference.ToProj4(display.SpatialReference);
                //    sb.Append("<SPATIALREFERENCE name='" + display.SpatialReference.Name + "' param='" + map_param + "' />");
                //}

                if (sRef != null)
                {
                    string map_param = gView.Framework.Geometry.SpatialReference.ToProj4(display.SpatialReference);
                    sb.Append("<SPATIALREFERENCE name='" + display.SpatialReference.Name + "' param='" + map_param + "' />");

                    string wkt        = gView.Framework.Geometry.SpatialReference.ToESRIWKT(sRef);
                    string geotranwkt = gView.Framework.Geometry.SpatialReference.ToESRIGeotransWKT(sRef);

                    if (wkt != null)
                    {
                        wkt        = wkt.Replace("\"", "&quot;");
                        geotranwkt = geotranwkt.Replace("\"", "&quot;");
                        if (!String.IsNullOrEmpty(geotranwkt))
                        {
                            sb.Append("<FEATURECOORDSYS string=\"" + wkt + "\" datumtransformstring=\"" + geotranwkt + "\" />");
                            sb.Append("<FILTERCOORDSYS string=\"" + wkt + "\" datumtransformstring=\"" + geotranwkt + "\" />");
                        }
                        else
                        {
                            sb.Append("<FEATURECOORDSYS string=\"" + wkt + "\" />");
                            sb.Append("<FILTERCOORDSYS string=\"" + wkt + "\" />");
                        }
                    }
                }

                sb.Append("<LAYERLIST>");
                foreach (IWebServiceTheme theme in Themes)
                {
                    sb.Append("<LAYERDEF id='" + theme.LayerID + "' visible='" + (theme.Visible && !theme.Locked).ToString() + "' />");
                }
                sb.Append("</LAYERLIST>");
                sb.Append("</PROPERTIES>");
                sb.Append("</GET_IMAGE>");
                sb.Append("</REQUEST>");
                sb.Append("</ARCXML>");

                string user = ConfigTextStream.ExtractValue(_dataset._connection, "user");
                string pwd  = Identity.HashPassword(ConfigTextStream.ExtractValue(_dataset._connection, "pwd"));

                if ((user == "#" || user == "$") &&
                    context != null && context.ServiceRequest != null && context.ServiceRequest.Identity != null)
                {
                    string roles = String.Empty;
                    if (user == "#" && context.ServiceRequest.Identity.UserRoles != null)
                    {
                        foreach (string role in context.ServiceRequest.Identity.UserRoles)
                        {
                            if (String.IsNullOrEmpty(role))
                            {
                                continue;
                            }
                            roles += "|" + role;
                        }
                    }
                    user = context.ServiceRequest.Identity.UserName + roles;
                    pwd  = context.ServiceRequest.Identity.HashedPassword;
                }

#if (DEBUG)
                //Logger.LogDebug("Start gView Mapserver Request");
#endif
                MapServerConnection service = new MapServerConnection(ConfigTextStream.ExtractValue(_dataset._connection, "server"));
                string resp = service.Send(_name, sb.ToString(), "BB294D9C-A184-4129-9555-398AA70284BC", user, pwd);

#if (DEBUG)
                //Logger.LogDebug("gView Mapserver Request Finished");
#endif

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(resp);

                System.Drawing.Bitmap bm = null;
                XmlNode output           = doc.SelectSingleNode("//OUTPUT[@file]");
                if (_image != null)
                {
                    _image.Dispose();
                    _image = null;
                }

                try
                {
                    System.IO.FileInfo fi = new System.IO.FileInfo(output.Attributes["file"].Value);
                    if (fi.Exists)
                    {
                        bm = System.Drawing.Bitmap.FromFile(fi.FullName) as System.Drawing.Bitmap;
                    }
                }
                catch { }

                if (bm == null)
                {
                    bm = WebFunctions.DownloadImage(output);
                }

                if (bm != null)
                {
                    _image = new GeorefBitmap(bm);
                    _image.SpatialReference = display.SpatialReference;
                    _image.Envelope         = display.Envelope;

                    if (AfterMapRequest != null)
                    {
                        AfterMapRequest(this, display, _image);
                    }
                }

                return(_image != null);
            }
            catch (Exception ex)
            {
                MapServerClass.ErrorLog(context, "MapRequest", ConfigTextStream.ExtractValue(_dataset._connection, "server"), _name, ex);
                return(false);
            }
        }
Exemplo n.º 18
0
        async public Task <bool> MapRequest(gView.Framework.Carto.IDisplay display)
        {
            if (_dataset == null)
            {
                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

            string server  = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "server");
            string service = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "service");
            string user    = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "user");
            string pwd     = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "pwd");
            IServiceRequestContext context = display.Map as IServiceRequestContext;

            //if ((user == "#" || user == "$") &&
            //    context != null && context.ServiceRequest != null && context.ServiceRequest.Identity != null)
            //{
            //    string roles = String.Empty;
            //    if (user == "#" && context.ServiceRequest.Identity.UserRoles != null)
            //    {
            //        foreach (string role in context.ServiceRequest.Identity.UserRoles)
            //        {
            //            if (String.IsNullOrEmpty(role)) continue;
            //            roles += "|" + role;
            //        }
            //    }
            //    user = context.ServiceRequest.Identity.UserName + roles;
            //    pwd = context.ServiceRequest.Identity.HashedPassword;
            //}

            dotNETConnector connector = new dotNETConnector();
            if (!String.IsNullOrEmpty(user) || !String.IsNullOrEmpty(pwd))
            {
                connector.setAuthentification(user, pwd);
            }

            if (_dataset.State != DatasetState.opened)
            {
                if (!await _dataset.Open(context))
                {
                    return(false);
                }
            }

            ISpatialReference sRef = (display.SpatialReference != null) ?
                                     display.SpatialReference.Clone() as ISpatialReference :
                                     null;

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

            if (BeforeMapRequest != null)
            {
                BeforeMapRequest(this, display, ref sRef, ref iWidth, ref iHeight);
            }

            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<?xml version='1.0' encoding='utf-8'?>");
                sb.Append("<ARCXML version='1.1'>");
                sb.Append("<REQUEST>");
                sb.Append("<GET_IMAGE>");
                sb.Append("<PROPERTIES>");
                IEnvelope bounds = display.DisplayTransformation.TransformedBounds(display);
                if (display.DisplayTransformation.UseTransformation == true)
                {
                    iWidth  = (int)(bounds.Width * display.dpm / display.mapScale);
                    iHeight = (int)(bounds.Height * display.dpm / display.mapScale);
                }
                sb.Append("<ENVELOPE minx='" + bounds.minx.ToString() + "' miny='" + bounds.miny.ToString() + "' maxx='" + bounds.maxx.ToString() + "' maxy='" + bounds.maxy.ToString() + "' />");
                sb.Append("<IMAGESIZE width='" + iWidth + "' height='" + iHeight + "' />");
                sb.Append("<BACKGROUND color='" + Color2AXL(display.BackgroundColor) + "' transcolor='" + Color2AXL(display.TransparentColor) + "' />");

                string propertyString = _dataset._properties.PropertyString;
                if (propertyString != String.Empty)
                {
                    sb.Append(_dataset._properties.PropertyString);
                }
                else
                {
                    if (sRef != null)
                    {
                        //if (this.SpatialReference != null && !display.SpatialReference.Equals(this.SpatialReference))
                        {
                            string wkt        = gView.Framework.Geometry.SpatialReference.ToESRIWKT(sRef);
                            string geotranwkt = gView.Framework.Geometry.SpatialReference.ToESRIGeotransWKT(sRef);

                            if (wkt != null)
                            {
                                //wkt = "PROJCS[\"MGI_M31\",GEOGCS[\"GCS_MGI\",DATUM[\"D_MGI\",SPHEROID[\"Bessel_1841\",6377397.155,0]],PRIMEM[\"Greenwich\",0.0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",450000],PARAMETER[\"False_Northing\",-5000000],PARAMETER[\"Central_Meridian\",13.3333333333333],PARAMETER[\"Scale_Factor\",1],PARAMETER[\"latitude_of_origin\",0],UNIT[\"Meter\",1]]";
                                //wkt = "PROJCS[\"MGI_M31\",GEOGCS[\"GCS_MGI\",DATUM[\"D_MGI\",SPHEROID[\"Bessel_1841\",6377397.155,299.1528128]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",450000.0],PARAMETER[\"False_Northing\",-5000000.0],PARAMETER[\"Central_Meridian\",13.33333333333333],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0]]";

                                //geotranwkt = "GEOGTRAN[\"MGISTMK_To_WGS_1984\",GEOGCS[\"MGISTMK\",DATUM[\"Militar_Geographische_Institute_STMK\",SPHEROID[\"Bessel_1841\",6377397.155,299.1528128]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],METHOD[\"Position_Vector\"],PARAMETER[\"X_Axis_Translation\",577.326],PARAMETER[\"Y_Axis_Translation\",90.129],PARAMETER[\"Z_Axis_Translation\",463.919],PARAMETER[\"X_Axis_Rotation\",5.1365988],PARAMETER[\"Y_Axis_Rotation\",1.4742],PARAMETER[\"Z_Axis_Rotation\",5.2970436],PARAMETER[\"Scale_Difference\",2.4232]]";
                                wkt        = wkt.Replace("\"", "&quot;");
                                geotranwkt = geotranwkt.Replace("\"", "&quot;");
                                if (!String.IsNullOrEmpty(geotranwkt))
                                {
                                    sb.Append("<FEATURECOORDSYS string=\"" + wkt + "\" datumtransformstring=\"" + geotranwkt + "\" />");
                                    sb.Append("<FILTERCOORDSYS string=\"" + wkt + "\" datumtransformstring=\"" + geotranwkt + "\" />");
                                }
                                else
                                {
                                    sb.Append("<FEATURECOORDSYS string=\"" + wkt + "\" />");
                                    sb.Append("<FILTERCOORDSYS string=\"" + wkt + "\" />");
                                }
                                //sb.Append("<FEATURECOORDSYS string=\"" + wkt + "\" datumtransformid=\"8415\" />");
                                //sb.Append("<FILTERCOORDSYS string=\"" + wkt + "\" datumtransformid=\"8415\" />");
                            }
                        }
                    }
                }

                sb.Append("<LAYERLIST>");
                foreach (IWebServiceTheme theme in themes)
                {
                    sb.Append("<LAYERDEF id='" + theme.LayerID + "' visible='" + (theme.Visible && !theme.Locked).ToString() + "'");
                    XmlNode xmlnode;
                    if (LayerRenderer.TryGetValue(theme.LayerID, out xmlnode))
                    {
                        sb.Append(">\n" + xmlnode.OuterXml + "\n</LAYERDEF>");
                    }
                    else if (theme.FeatureRenderer != null)
                    {
                        string renderer = ObjectFromAXLFactory.ConvertToAXL(theme.FeatureRenderer);
                        sb.Append(">\n" + renderer + "\n</LAYERDEF>");
                    }
                    else
                    {
                        sb.Append("/>");
                    }
                }
                sb.Append("</LAYERLIST>");
                sb.Append("</PROPERTIES>");
                foreach (XmlNode additional in this.AppendedLayers)
                {
                    if (additional != null)
                    {
                        sb.Append(additional.OuterXml);
                    }
                }
                sb.Append("</GET_IMAGE>");
                sb.Append("</REQUEST>");
                sb.Append("</ARCXML>");

#if (DEBUG)
                gView.Framework.system.Logger.LogDebug("Start ArcXML SendRequest");
#endif
                await ArcIMSClass.LogAsync(display as IServiceRequestContext, "GetImage Request", server, service, sb);

                string resp = connector.SendRequest(sb, server, service);
                await ArcIMSClass.LogAsync(display as IServiceRequestContext, "GetImage Response", server, service, resp);

#if (DEBUG)
                gView.Framework.system.Logger.LogDebug("ArcXML SendRequest Finished");
#endif

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(resp);

                XmlNode outputNode   = doc.SelectSingleNode("//IMAGE/OUTPUT");
                XmlNode envelopeNode = doc.SelectSingleNode("//IMAGE/ENVELOPE");

                if (ModifyResponseOuput != null)
                {
                    ModifyResponseOuput(this, new ModifyOutputEventArgs(outputNode));
                }

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

#if (DEBUG)
                //gView.Framework.system.Logger.LogDebug("Start ArcXML DownloadImage");
#endif
                IBitmap bitmap = null;
                if (outputNode != null)
                {
#if (DEBUG)
                    gView.Framework.system.Logger.LogDebug("Start ArcXML DownloadImage");
#endif
                    bitmap = WebFunctions.DownloadImage(outputNode /*_dataset._connector.Proxy*/);
#if (DEBUG)
                    gView.Framework.system.Logger.LogDebug("ArcXML DownloadImage Finished");
#endif
                }
                else
                {
                    bitmap = null;
                }
#if (DEBUG)
                //gView.Framework.system.Logger.LogDebug("ArcXML DownloadImage Finished");
#endif

                if (bitmap != null)
                {
                    _image = new GeorefBitmap(bitmap);
                    //_image.MakeTransparent(display.TransparentColor);
                    if (envelopeNode != null &&
                        envelopeNode.Attributes["minx"] != null &&
                        envelopeNode.Attributes["miny"] != null &&
                        envelopeNode.Attributes["maxx"] != null &&
                        envelopeNode.Attributes["maxy"] != null)
                    {
                        _image.Envelope = new Envelope(
                            Convert.ToDouble(envelopeNode.Attributes["minx"].Value.Replace(".", ",")),
                            Convert.ToDouble(envelopeNode.Attributes["miny"].Value.Replace(".", ",")),
                            Convert.ToDouble(envelopeNode.Attributes["maxx"].Value.Replace(".", ",")),
                            Convert.ToDouble(envelopeNode.Attributes["maxy"].Value.Replace(".", ",")));
                    }
                    _image.SpatialReference = display.SpatialReference;

                    if (AfterMapRequest != null)
                    {
                        AfterMapRequest(this, display, _image);
                    }
                }
                return(_image != null);
            }
            catch (Exception ex)
            {
                await ArcIMSClass.ErrorLog(context, "MapRequest", server, service, ex);

                return(false);
            }
        }
Exemplo n.º 19
0
        async public Task <bool> LegendRequest(gView.Framework.Carto.IDisplay display)
        {
            if (_dataset == null)
            {
                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 (_legend != null)
                {
                    _legend.Dispose();
                    _legend = null;
                }
                return(true);
            }
            #endregion

            string server  = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "server");
            string service = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "service");
            string user    = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "user");
            string pwd     = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "pwd");
            IServiceRequestContext context = display.Map as IServiceRequestContext;

            //if ((user == "#" || user == "$") &&
            //    context != null && context.ServiceRequest != null && context.ServiceRequest.Identity != null)
            //{
            //    string roles = String.Empty;
            //    if (user == "#" && context.ServiceRequest.Identity.UserRoles != null)
            //    {
            //        foreach (string role in context.ServiceRequest.Identity.UserRoles)
            //        {
            //            if (String.IsNullOrEmpty(role)) continue;
            //            roles += "|" + role;
            //        }
            //    }
            //    user = context.ServiceRequest.Identity.UserName + roles;
            //    pwd = context.ServiceRequest.Identity.HashedPassword;
            //}

            dotNETConnector connector = new dotNETConnector();
            if (!String.IsNullOrEmpty(user) || !String.IsNullOrEmpty(pwd))
            {
                connector.setAuthentification(user, pwd);
            }

            if (_dataset.State != DatasetState.opened)
            {
                if (!await _dataset.Open(context))
                {
                    return(false);
                }
            }

            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<?xml version='1.0' encoding='utf-8'?>");
                sb.Append("<ARCXML version='1.1'>");
                sb.Append("<REQUEST>");
                sb.Append("<GET_IMAGE>");
                sb.Append("<PROPERTIES>");
                sb.Append("<ENVELOPE minx='" + display.Envelope.minx.ToString() + "' miny='" + display.Envelope.miny.ToString() + "' maxx='" + display.Envelope.maxx.ToString() + "' maxy='" + display.Envelope.maxy.ToString() + "' />");
                sb.Append("<IMAGESIZE width='" + display.iWidth + "' height='" + display.iHeight + "' />");
                sb.Append("<BACKGROUND color='255,255,255' transcolor='255,255,255' />");

                sb.Append(_dataset._properties.PropertyString);

                sb.Append("<LAYERLIST>");
                foreach (IWebServiceTheme theme in themes)
                {
                    sb.Append("<LAYERDEF id='" + theme.LayerID + "' visible='" + (theme.Visible && !theme.Locked).ToString() + "'");
                    XmlNode xmlnode;
                    if (LayerRenderer.TryGetValue(theme.LayerID, out xmlnode))
                    {
                        sb.Append(">\n" + xmlnode.OuterXml + "\n</LAYERDEF>");
                    }
                    else if (theme.FeatureRenderer != null)
                    {
                        string renderer = ObjectFromAXLFactory.ConvertToAXL(theme.FeatureRenderer);
                        sb.Append(">\n" + renderer + "\n</LAYERDEF>");
                    }
                    else
                    {
                        sb.Append("/>");
                    }
                }
                sb.Append("</LAYERLIST>");
                sb.Append("<DRAW map=\"false\" />");
                sb.Append("<LEGEND font=\"Arial\" autoextend=\"true\" columns=\"1\" width=\"165\" height=\"170\" backgroundcolor=\"255,255,255\" layerfontsize=\"11\" valuefontsize=\"10\">");
                sb.Append("<LAYERS />");
                sb.Append("</LEGEND>");
                sb.Append("</PROPERTIES>");
                foreach (XmlNode additional in this.AppendedLayers)
                {
                    sb.Append(additional.OuterXml);
                }
                sb.Append("</GET_IMAGE>");
                sb.Append("</REQUEST>");
                sb.Append("</ARCXML>");

                await ArcIMSClass.LogAsync(display as IServiceRequestContext, "GetLegend Request", server, service, sb);

                string resp = connector.SendRequest(sb, server, service);
                await ArcIMSClass.LogAsync(display as IServiceRequestContext, "GetLegend Response", server, service, resp);

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(resp);

                XmlNode output = doc.SelectSingleNode("//LEGEND");

                if (ModifyResponseOuput != null)
                {
                    ModifyResponseOuput(this, new ModifyOutputEventArgs(output));
                }

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

                _legend = WebFunctions.DownloadImage(output);
                return(true);
            }
            catch (Exception ex)
            {
                await ArcIMSClass.ErrorLog(context, "LegendRequest", server, service, ex);

                return(false);
            }
        }
Exemplo n.º 20
0
        public bool MapRequest(gView.Framework.Carto.IDisplay display)
        {
            if (_srs == null)
            {
                return(false);
            }

            if (!_dataset.IsOpened)
            {
                if (!_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

            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 = GeometricTransformer.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 = new SLDRenderer(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;
            }
            System.Drawing.Bitmap bm = 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
                {
                    bm = WebFunctions.DownloadImage(url,
                                                    ConfigTextStream.ExtractValue(_dataset._connectionString, "usr"),
                                                    ConfigTextStream.ExtractValue(_dataset._connectionString, "pwd"));
                }
                catch (Exception ex)
                {
                    WMSClass.ErrorLog(display.Map as IServiceRequestContext, "MapRequest", url, ex);
                    return(false);
                }
#if (DEBUG)
                gView.Framework.system.Logger.LogDebug("WMS DownloadImage Finished");
#endif
            }
            if (bm != null)
            {
                _image                  = new GeorefBitmap(bm);
                _image.Envelope         = displayEnv;
                _image.SpatialReference = this.SpatialReference;

                if (AfterMapRequest != null)
                {
                    AfterMapRequest(this, display, _image);
                }
            }
            return(_image != null);
        }
Exemplo n.º 21
0
 public Task <bool> LegendRequest(gView.Framework.Carto.IDisplay display)
 {
     return(Task.FromResult(false));
 }
Exemplo n.º 22
0
        public ICursor PointQuery(gView.Framework.Carto.IDisplay display, gView.Framework.Geometry.IPoint point, ISpatialReference sRef, IUserData userdata)
        {
            if (display == null || point == null)
            {
                return(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 = GeometricTransformer.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(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(new TextCursor(response));

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

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

                case "application/vnd.ogc.gml":
                    response = WebFunctions.HttpSendRequest(WMSDataset.Append2Url(_getFeatureInfo.Get_OnlineResource, request.ToString()));
                    return(new RowCursor(Gml2Rows(response)));
                }
            }
            return(null);
        }
Exemplo n.º 23
0
 async public Task <bool> LegendRequest(gView.Framework.Carto.IDisplay display)
 {
     return(false);
 }
Exemplo n.º 24
0
        public Task <IRasterPaintContext> BeginPaint(gView.Framework.Carto.IDisplay display, ICancelTracker cancelTracker)
        {
            var bitmap = GraphicsEngine.Current.Engine.CreateBitmap(_filename);

            return(Task.FromResult <IRasterPaintContext>(new RasterPaintContext(bitmap)));
        }
Exemplo n.º 25
0
 public Task <IRasterPaintContext> BeginPaint(gView.Framework.Carto.IDisplay display, ICancelTracker cancelTracker)
 {
     throw new NotImplementedException();
 }
 public void BeginPaint(gView.Framework.Carto.IDisplay display, ICancelTracker cancelTracker)
 {
 }
Exemplo n.º 27
0
        async public Task <float[]> MultiGridQuery(gView.Framework.Carto.IDisplay display, IPoint[] Points, double dx, double dy, ISpatialReference sRef, IUserData userdata)
        {
            if (Points == null || Points.Length != 3)
            {
                return(null);
            }

            PointCollection pColl = new PointCollection();

            pColl.AddPoint(Points[0]);
            pColl.AddPoint(Points[1]);
            pColl.AddPoint(Points[2]);

            double d1x = Points[1].X - Points[0].X, d1y = Points[1].Y - Points[0].Y;
            double d2x = Points[2].X - Points[0].X, d2y = Points[2].Y - Points[0].Y;
            double len1  = Math.Sqrt(d1x * d1x + d1y * d1y);
            double len2  = Math.Sqrt(d2x * d2x + d2y * d2y);
            int    stepX = (int)Math.Round(len1 / dx);
            int    stepY = (int)Math.Round(len2 / dy);

            d1x /= stepX; d1y /= stepX;
            d2x /= stepY; d2y /= stepY;

            List <float> vals = new List <float>();

            vals.Add((float)(stepX + 1));
            vals.Add((float)(stepY + 1));

            List <IRasterLayer> layers = await QueryChildLayers(pColl.Envelope, String.Empty);

            try
            {
                for (int y = 0; y <= stepY; y++)
                {
                    for (int x = 0; x <= stepX; x++)
                    {
                        Point p = new Point(Points[0].X + d1x * x + d2x * y,
                                            Points[0].Y + d1y * x + d2y * y);

                        bool found = false;
                        foreach (IRasterLayer layer in layers)
                        {
                            if (layer == null ||
                                !(layer.Class is IRasterClass) ||
                                !(layer.Class is IGridIdentify))
                            {
                                continue;
                            }

                            if (gView.Framework.SpatialAlgorithms.Algorithm.Jordan(((IRasterClass)layer.Class).Polygon, p.X, p.Y))
                            {
                                ((IGridIdentify)layer.Class).InitGridQuery();
                                float val = ((IGridIdentify)layer.Class).GridQuery(display, p, sRef);
                                vals.Add(val);
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            vals.Add(float.MinValue);
                        }
                    }
                }
            }
            finally
            {
                foreach (IRasterLayer layer in layers)
                {
                    if (layer.Class is IGridIdentify)
                    {
                        ((IGridIdentify)layer.Class).ReleaseGridQuery();
                    }
                }
            }


            return(vals.ToArray());
        }
Exemplo n.º 28
0
        public bool MapRequest(gView.Framework.Carto.IDisplay display)
        {
            if (_dataset == null ||
                _dataset._mapServer == null ||
                _dataset._mapDescription == null || Themes == null)
            {
                return(false);
            }

            List <IWebServiceTheme> themes = Themes;

            #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

            ISpatialReference sRef = (display.SpatialReference != null) ?
                                     display.SpatialReference.Clone() as ISpatialReference :
                                     null;

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

            if (BeforeMapRequest != null)
            {
                BeforeMapRequest(this, display, ref sRef, ref iWidth, ref iHeight);
            }

            try
            {
                #region Extent
                _dataset._mapDescription.MapArea.Extent =
                    ArcServerHelper.EnvelopeN(display.Envelope);
                if (display.DisplayTransformation.UseTransformation)
                {
                    _dataset._mapDescription.Rotation = display.DisplayTransformation.DisplayRotation;
                }
                #endregion

                #region Back/Transparent Color
                RgbColor         backColor  = ArcServerHelper.RgbColor(display.BackgroundColor);
                SimpleFillSymbol fillSymbol = new SimpleFillSymbol();
                fillSymbol.Color   = backColor;
                fillSymbol.Outline = null;
                _dataset._mapDescription.BackgroundSymbol = fillSymbol;
                _dataset._mapDescription.TransparentColor = backColor;
                #endregion

                #region Layer Visibility
                LayerDescription[] layerDescriptions = _dataset._mapDescription.LayerDescriptions;
                foreach (LayerDescription layerDescr in layerDescriptions)
                {
                    IWebServiceTheme theme = GetThemeByLayerId(layerDescr.LayerID.ToString());
                    if (theme == null)
                    {
                        continue;
                    }
                    layerDescr.Visible = theme.Visible;
                    if (layerDescr.Visible)
                    {
                        foreach (int parentLayerId in _dataset.ParentLayerIds(layerDescr.LayerID))
                        {
                            LayerDescription parent = _dataset.LayerDescriptionById(parentLayerId);
                            if (parent != null)
                            {
                                parent.Visible = true;
                            }
                        }
                    }
                }
                #endregion

                #region ImageDescription
                ImageType imgType = new ImageType();
                imgType.ImageFormat     = esriImageFormat.esriImagePNG24;
                imgType.ImageReturnType = esriImageReturnType.esriImageReturnURL;

                ImageDisplay imgDisp = new ImageDisplay();
                imgDisp.ImageWidth       = iWidth;
                imgDisp.ImageHeight      = iHeight;
                imgDisp.ImageDPI         = display.dpi;
                imgDisp.TransparentColor = backColor;

                ImageDescription imgDescr = new ImageDescription();
                imgDescr.ImageDisplay = imgDisp;
                imgDescr.ImageType    = imgType;
                #endregion

                MapImage mapImg = _dataset._mapServer.ExportMapImage(_dataset._mapDescription, imgDescr);
                if (mapImg != null && !String.IsNullOrEmpty(mapImg.ImageURL))
                {
                    System.Drawing.Bitmap bm = WebFunctions.DownloadImage(mapImg.ImageURL, _dataset._proxy, System.Net.CredentialCache.DefaultNetworkCredentials);
                    if (bm != null)
                    {
                        _image                  = new GeorefBitmap(bm);
                        _image.Envelope         = new gView.Framework.Geometry.Envelope(new gView.Framework.Geometry.Envelope(display.Envelope));
                        _image.SpatialReference = display.SpatialReference;

                        if (AfterMapRequest != null)
                        {
                            AfterMapRequest(this, display, _image);
                        }
                    }
                }
                else
                {
                    if (_image != null)
                    {
                        _image.Dispose();
                        _image = null;
                    }
                }
                return(_image != null);
            }
            catch (Exception ex)
            {
                //ArcIMSClass.ErrorLog(context, "MapRequest", server, service, ex);
                return(false);
            }
        }