Esempio n. 1
0
        public virtual ImageObj Create_Scale(float length = 10000, string unit = "km")
        {
            string   pathScale = Directory.GetCurrentDirectory() + "/ModelData/Image/GIS/Scale.png";
            ImageObj imgScale  = new ImageObj(100, 100);

            //计算图例区间
            double W          = _Metadata.MaxX - _Metadata.MinX;
            double ratioScale = W * 111000 / _Image.Width;
            int    nPixels    = (int)(length / ratioScale);

            var font = imgScale.defaultFont(11, "");
            var sizeText = imgScale.Graphic.MeasureString(unit, font);
            int nOffset_x = 10, nOffset_y = 8;
            int nW = nPixels + nOffset_x * 3 + (int)sizeText.Width;
            int nH = nOffset_y * 3 + (int)sizeText.Height;

            imgScale.Create(pathScale, nPixels, nOffset_y);

            //绘制
            ImageColor pColor = new ImageColor("#192734");
            ImageObj   img    = new ImageObj(nW, nH);

            img.DrawImage(nOffset_x, nOffset_y + (int)sizeText.Height, imgScale, 1);

            int hUnit = nOffset_y + (int)(sizeText.Height - imgScale.Height / 2 - 1);

            img.DrawText(nOffset_x * 2 + nPixels, hUnit, pColor.Color, unit, font, 0, true, false, Alignment.Near, Alignment.Near);

            int hDis = (int)(sizeText.Height / 2 - 1);

            img.DrawText(nOffset_x, hDis, pColor.Color, "0", font, 0, true, false, Alignment.Center, Alignment.Near);
            img.DrawText(nOffset_x + nPixels / 2 / 2, hDis, pColor.Color, (length / 1000 / 2 / 2).ToString(), font, 0, true, false, Alignment.Center, Alignment.Near);
            img.DrawText(nOffset_x + nPixels / 2, hDis, pColor.Color, (length / 1000 / 2).ToString(), font, 0, true, false, Alignment.Center, Alignment.Near);
            img.DrawText(nOffset_x + nPixels, hDis, pColor.Color, (length / 1000).ToString(), font, 0, true, false, Alignment.Center, Alignment.Near);
            return(img);
        }
Esempio n. 2
0
        public override bool Renderer(string strParams_renderer = "")
        {
            bool bResult = true;

            _FloderRenderer = _FloderOutput;
            if (base.Renderer(strParams_renderer))
            {
                //载入结果栅格
                if (_dstRasterFile == "")
                {
                    return(true);
                }
                GdalRead_TIFF gdalRead_TIFF = new GdalRead_TIFF();
                gdalRead_TIFF.InitDataset(_dstRasterFile, 0, false);

                string          fileName = _Datas["title"] + _dtTag;
                IRasterRenderer pRender  = (IRasterRenderer)Renderer_Factory.CreateRenderer(emRenderType.Classify, gdalRead_TIFF);
                pRender.InitParams(_Renderer);
                pRender.Render();
                pRender.Output(_FloderRenderer, fileName);


                //图例处理等
                JObject renderInfo = (JObject)pRender.ToRendererStr(false);
                _Result["renderer"] = renderInfo;
                _Renderer           = (JObject)_Params["rendererParms"];
                if (_Renderer != null)
                {
                    //创建图例
                    if (Convert.ToBoolean(_Renderer["rendererOutputLegend"]))
                    {
                        bResult = bResult && pRender.Create_Legend(_FloderRenderer, "Legend_" + _Datas["title"]);
                        if (bResult)
                        {
                            _Result["renderer"]["renderer"]["nameLegend"] = pRender.Image_Legend.Name + pRender.Image_Legend.Suffix;
                        }
                    }

                    //创建发布图
                    if (Convert.ToBoolean(_Renderer["rendererOutputPublish"]))
                    {
                        //含图例的渲染图
                        ImageObj _Image = pRender.Image, _Image_legend = pRender.Image_Legend;
                        if (_Image_legend == null)
                        {
                            bResult       = bResult && pRender.Create_Legend(_FloderRenderer, "Legend_" + _Datas["title"]);
                            _Image_legend = pRender.Image_Legend;
                        }

                        ImageColor pColor       = new ImageColor("#192734");
                        ImageObj   _Image_Scale = pRender.Create_Scale();
                        ImageObj   img          = new ImageObj(_Image.Width + _Image_legend.Width, _Image.Height > _Image_legend.Height ? _Image.Height : _Image_legend.Height);
                        img.DrawImage(_Image_legend.Width, 0, _Image, 1);
                        img.DrawImage(0, (int)((img.Height - _Image_legend.Height)), _Image_legend, 1);
                        img.DrawImage((int)(_Image_legend.Width * 1.2), (int)((img.Height - _Image_Scale.Height * 1.2)), _Image_Scale, 1);
                        img.DrawPolygon(0, 20, pColor.Color, 1, img.Width - 1, img.Height - 21);
                        img.Name = fileName + "_publish";
                        bResult  = bResult && img.Save(_FloderRenderer);
                        if (bResult)
                        {
                            _Result["renderer"]["renderer"]["namePublish"] = img.Name + img.Suffix;
                        }
                    }
                }
            }
            return(true);
        }