Ejemplo n.º 1
0
        public string TIFF([System.Web.Http.FromBody] UploadData uploadData)
        {
            MapExportItem exportItem = JsonConvert.DeserializeObject <MapExportItem>(uploadData.data);

            TIFFCreator tiffCreator = new TIFFCreator();
            Image       img         = tiffCreator.Create(exportItem);

            MemoryStream outStream = new MemoryStream();

            ZipOutputStream zipStream = new ZipOutputStream(outStream);

            zipStream.SetLevel(3);

            ZipEntry imageEntry = new ZipEntry(ZipEntry.CleanName("kartexport.tiff"));

            imageEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(imageEntry);

            MemoryStream imageStream = new MemoryStream(imgToByteArray(img));

            byte[] buffer = new byte[4096];

            StreamUtils.Copy(imageStream, zipStream, buffer);

            imageStream.Close();
            zipStream.CloseEntry();

            ZipEntry worldFileEntry = new ZipEntry(ZipEntry.CleanName("kartexport.tfw"));

            worldFileEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(worldFileEntry);
            MemoryStream worldFileStream = new MemoryStream(MapImageCreator.CreateWorldFile(exportItem));

            byte[] buffer2 = new byte[4096];
            StreamUtils.Copy(worldFileStream, zipStream, buffer2);

            worldFileStream.Close();
            zipStream.CloseEntry();

            zipStream.IsStreamOwner = false;    // False stops the Close also Closing the underlying stream.
            zipStream.Close();                  // Must finish the ZipOutputStream before using outputMemStream.

            outStream.Position = 0;
            outStream.ToArray();

            string[] fileInfo = byteArrayToFileInfo(outStream.ToArray(), "zip");
            if (exportItem.proxyUrl != "")
            {
                return(exportItem.proxyUrl + "/Temp/" + fileInfo[1]);
            }
            else
            {
                return(Request.Url.GetLeftPart(UriPartial.Authority) + "/Temp/" + fileInfo[1]);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create map and append the document with an image.
        /// </summary>
        /// <param name="chapter"></param>
        /// <returns>Path to created map image</returns>
        private string AppendMap(Chapter chapter)
        {
            MapSettings mapSettings = chapter.mapSettings;

            chapter.baseLayer = this.baseLayer;
            string[] layers = chapter.layers;
            if (layers != null && chapter.mapSettings.extent != null && layers.Length > 0)
            {
                if (chapter.baseLayer != null)
                {
                    layers = (new string[] { chapter.baseLayer }).Union(chapter.layers).ToArray();
                }
                LayerConfig   layerConfig   = this.LookupLayers(layers);
                MapExportItem mapExportItem = new MapExportItem();
                int           mapHeight     = 500;
                int           mapWidth      = (int)(mapHeight * ((1 + Math.Sqrt(5)) / 2));
                mapExportItem.size       = new int[] { mapWidth, mapHeight };
                mapExportItem.resolution = 90;
                double[] mapExtent = chapter.mapSettings.extent;
                mapExportItem.bbox = new double[] { mapExtent[0], mapExtent[2], mapExtent[1], mapExtent[3] };

                mapExportItem.arcgisLayers = layerConfig.arcgislayers.Select(layer =>
                                                                             layer.AsInfo(layer.zIndex == null ? 0 : (int)layer.zIndex)
                                                                             ).ToList();

                mapExportItem.wmsLayers = layerConfig.wmslayers.Select(layer =>
                                                                       layer.AsInfo(layer.zIndex == null ? 0 : (int)layer.zIndex)
                                                                       ).ToList();

                mapExportItem.vectorLayers = layerConfig.vectorlayers.Select(layer =>
                                                                             layer.AsInfo(layer.zIndex == null ? 0 : (int)layer.zIndex, new double[] { mapExtent[1], mapExtent[0], mapExtent[3], mapExtent[2] })
                                                                             ).ToList();

                try
                {
                    System.Drawing.Image i = MapImageCreator.GetImage(mapExportItem);
                    string mapImageGuid    = Guid.NewGuid().ToString();
                    string path            = String.Format("C:\\tmp\\{0}.png", mapImageGuid);
                    i.Save(path, System.Drawing.Imaging.ImageFormat.Png);
                    (new Task(() =>
                    {
                        Thread.Sleep(20000);
                        File.Delete(path);
                    })).Start();
                    return(string.Format("<div><img src='{0}'/></div>", path));
                }
                catch (Exception ex)
                {
                    return(String.Empty);
                }
            }
            else
            {
                return(String.Empty);
            }
        }
Ejemplo n.º 3
0
        public ActionResult TIFF(string json)
        {
            MapExportItem exportItem = JsonConvert.DeserializeObject <MapExportItem>(json);

            TIFFCreator tiffCreator = new TIFFCreator();
            Image       img         = tiffCreator.Create(exportItem);

            MemoryStream outStream = new MemoryStream();

            ZipOutputStream zipStream = new ZipOutputStream(outStream);

            zipStream.SetLevel(3);

            ZipEntry imageEntry = new ZipEntry(ZipEntry.CleanName("kartexport.tiff"));

            imageEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(imageEntry);

            MemoryStream imageStream = new MemoryStream(imgToByteArray(img));

            byte[] buffer = new byte[4096];

            StreamUtils.Copy(imageStream, zipStream, buffer);

            imageStream.Close();
            zipStream.CloseEntry();

            ZipEntry worldFileEntry = new ZipEntry(ZipEntry.CleanName("kartexport.tfw"));

            worldFileEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(worldFileEntry);
            MemoryStream worldFileStream = new MemoryStream(MapImageCreator.CreateWorldFile(exportItem));

            byte[] buffer2 = new byte[4096];
            StreamUtils.Copy(worldFileStream, zipStream, buffer2);

            worldFileStream.Close();
            zipStream.CloseEntry();

            zipStream.IsStreamOwner = false;    // False stops the Close also Closing the underlying stream.
            zipStream.Close();                  // Must finish the ZipOutputStream before using outputMemStream.

            outStream.Position = 0;

            return(File(outStream.ToArray(), "application/octet-stream", "kartexport.zip"));
        }
Ejemplo n.º 4
0
 public byte[] Create(MapExportItem exportItem, string fontName)
 {
     return(this.createPdf(MapImageCreator.GetImage(exportItem), exportItem, fontName));
 }
Ejemplo n.º 5
0
        public string TIFF(string json)
        {
            _log.DebugFormat("Received json: {0}", json);

            // try to decode input string to see if it is base64 encoded
            try
            {
                byte[] decoded = Convert.FromBase64String(json);
                json = System.Text.Encoding.UTF8.GetString(decoded);
                _log.DebugFormat("json after decode: {0}", json);
            }
            catch (Exception e)
            {
                _log.DebugFormat("Could not decode base64. Will treat as non-base64 encoded: {0}", e.Message);
            }
            MapExportItem exportItem = JsonConvert.DeserializeObject <MapExportItem>(json);

            TIFFCreator tiffCreator = new TIFFCreator();
            Image       img         = tiffCreator.Create(exportItem);

            MemoryStream outStream = new MemoryStream();

            ZipOutputStream zipStream = new ZipOutputStream(outStream);

            zipStream.SetLevel(3);

            ZipEntry imageEntry = new ZipEntry(ZipEntry.CleanName("kartexport.tiff"));

            imageEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(imageEntry);

            MemoryStream imageStream = new MemoryStream(imgToByteArray(img));

            byte[] buffer = new byte[4096];

            StreamUtils.Copy(imageStream, zipStream, buffer);

            imageStream.Close();
            zipStream.CloseEntry();

            ZipEntry worldFileEntry = new ZipEntry(ZipEntry.CleanName("kartexport.tfw"));

            worldFileEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(worldFileEntry);
            MemoryStream worldFileStream = new MemoryStream(MapImageCreator.CreateWorldFile(exportItem));

            byte[] buffer2 = new byte[4096];
            StreamUtils.Copy(worldFileStream, zipStream, buffer2);

            worldFileStream.Close();
            zipStream.CloseEntry();

            zipStream.IsStreamOwner = false;    // False stops the Close also Closing the underlying stream.
            zipStream.Close();                  // Must finish the ZipOutputStream before using outputMemStream.

            outStream.Position = 0;
            outStream.ToArray();

            string[] fileInfo = byteArrayToFileInfo(outStream.ToArray(), "zip");
            if (exportItem.proxyUrl != "")
            {
                return(exportItem.proxyUrl + "/Temp/" + fileInfo[1]);
            }
            else
            {
                return(Request.Url.GetLeftPart(UriPartial.Authority) + "/Temp/" + fileInfo[1]);
            }
        }
Ejemplo n.º 6
0
        public string ExportPDF(MapExportItem exportItem)
        {
            string tempPath = "/Temp";
            string path     = HttpContext.Current.Server.MapPath(tempPath);
            string filename = Guid.NewGuid() + ".pdf";
            string localPdf = path + "\\" + filename;

            Image       img      = MapImageCreator.GetImage(exportItem);
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.AddPage();

            page.Size        = exportItem.format == "A4" ? PdfSharp.PageSize.A4 : PdfSharp.PageSize.A3;
            page.Orientation = exportItem.orientation == "L" ? PdfSharp.PageOrientation.Landscape : PdfSharp.PageOrientation.Portrait;

            XGraphics gfx = XGraphics.FromPdfPage(page);

            int    scale      = int.Parse(exportItem.scale);
            double length     = (1.0 / scale);
            double unitLength = (length * 2.82e3);

            Dictionary <int, string> scaleBarTexts = new Dictionary <int, string>()
            {
                { 1000, "50 m" },
                { 2000, "100 m" },
                { 5000, "200 m" },
                { 10000, "500 m" },
                { 20000, "1 km" },
                { 50000, "2 km" },
                { 100000, "5 km" },
                { 250000, "10 km" }
            };

            Dictionary <int, int> scaleBarLengths = new Dictionary <int, int>()
            {
                { 1000, 50 },
                { 2000, 100 },
                { 5000, 200 },
                { 10000, 500 },
                { 20000, 1000 },
                { 50000, 2000 },
                { 100000, 5000 },
                { 250000, 10000 }
            };

            int    displayLength = (int)(unitLength * scaleBarLengths.FirstOrDefault(a => a.Key == scale).Value);
            string displayText   = scaleBarTexts.FirstOrDefault(a => a.Key == scale).Value;

            this.drawImage(gfx, img, 10, 10, page);

            Point[] points = new Point[] {
                new Point(12, 12),
                new Point(12, 55),
                new Point(55 + displayLength, 55),
                new Point(55 + displayLength, 12),
                new Point(12, 12)
            };

            gfx.DrawPolygon(XBrushes.White, points, XFillMode.Winding);

            gfx.DrawLine(XPens.Black, new Point(15, 47), new Point(15 + displayLength, 47));
            gfx.DrawLine(XPens.Black, new Point(15, 44), new Point(15, 50));
            gfx.DrawLine(XPens.Black, new Point(15 + displayLength, 44), new Point(15 + displayLength, 50));

            string copyright = ConfigurationManager.AppSettings["exportCopyrightText"];

            this.drawText(gfx, String.Format("© {0}", copyright), 15, 25);
            this.drawText(gfx, String.Format("Skala 1:{0}", exportItem.scale), 15, 40);
            this.drawText(gfx, displayText, 20 + displayLength, 50);

            XImage logo = XImage.FromFile(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "assets", "logo.png"));

            gfx.DrawImage(logo, gfx.PageSize.Width - 212, 12, 200, 67);

            document.Save(localPdf);

            return(tempPath + "/" + filename);
        }
Ejemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="dataSet"></param>
 /// <returns></returns>
 public byte[] Create(MapExportItem exportItem)
 {
     return(this.createPdf(MapImageCreator.GetImage(exportItem), exportItem));
 }
Ejemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="dataSet"></param>
 /// <returns></returns>
 public Image Create(MapExportItem exportItem)
 {
     return(MapImageCreator.GetImage(exportItem));
 }