public void DrawBandHead() { pPen.Width = 1; pdfGC.DrawLine(pPen, (float)BandTopLeftLocation.X, (float)BandTopLeftLocation.Y, (float)BandTopLeftLocation.X, (float)(BandTopLeftLocation.Y + BandHight)); pdfGC.DrawLine(pPen, (float)BandTopLeftLocation.X, (float)(BandTopLeftLocation.Y + BandHight), (float)(BandTopLeftLocation.X - BandHeadWidth), (float)(BandTopLeftLocation.Y + BandHight)); pdfGC.DrawLine(pPen, (float)(BandTopLeftLocation.X - BandHeadWidth), (float)(BandTopLeftLocation.Y + BandHight), (float)(BandTopLeftLocation.X - BandHeadWidth), (float)BandTopLeftLocation.Y); pdfGC.DrawLine(pPen, (float)(BandTopLeftLocation.X - BandHeadWidth), (float)BandTopLeftLocation.Y, (float)BandTopLeftLocation.X, (float)BandTopLeftLocation.Y); // RectangleF rF = new RectangleF((float)(BandTopLeftLocation.X - BandHeadWidth), (float)(BandTopLeftLocation.Y), (float)BandHeadWidth, (float)BandHight); RectangleF rF = new RectangleF(0, 0, (float)BandHight, (float)BandHeadWidth); PdfStringFormat psf = new PdfStringFormat(PdfStringFormat.GenericDefault); psf.Alignment = PdfStringAlignment.Center; psf.LineAlignment = PdfStringAlignment.Center; // pdfGC.DrawString(BandName, textfont, Brushes.Black, rF, psf); pdfGC.SaveGraphicsState(); // head box 的左下角 pdfGC.TranslateTransform((float)(BandTopLeftLocation.X - BandHeadWidth), (float)(BandTopLeftLocation.Y + BandHight)); pdfGC.RotateTransform(270); pdfGC.DrawString(BandName, headFont, new SolidBrush(Color.Black), rF, psf); pdfGC.RestoreGraphicsState(); }
private void GenerateReportOfSegment(double BegMeasure, double endMeasure, string outFile) { if (checkBoxRotateMap.Checked) { IFeatureLayer pCenterlineLayer = null; string pCenterlineFileName = comboBoxExCenterline.SelectedItem.ToString(); for (int i = 0; i < pMapcontrol.LayerCount; i++) { if (pCenterlineFileName == pMapcontrol.get_Layer(i).Name) { pCenterlineLayer = pMapcontrol.get_Layer(i) as IFeatureLayer; } } IFeatureClass pCenterlineFC = pCenterlineLayer.FeatureClass; try { IFeatureCursor pCurcor = pCenterlineFC.Search(null, false); IFeature pFeature = pCurcor.NextFeature(); IGeometry pGeo = pFeature.Shape; IMSegmentation pMS = pGeo as IMSegmentation; double minM = pMS.MMin; double maxM = pMS.MMax; BegMeasure = BegMeasure < minM ? minM : BegMeasure; endMeasure = endMeasure > maxM ? maxM : endMeasure; IPoint begPt = pMS.GetPointsAtM(BegMeasure, 0).Geometry[0] as IPoint; IPoint endPt = pMS.GetPointsAtM(endMeasure, 0).Geometry[0] as IPoint; ISpatialReference sourcePrj; sourcePrj = pCenterlineFC.Fields.get_Field(pCenterlineFC.FindField(pCenterlineFC.ShapeFieldName)).GeometryDef.SpatialReference; ISpatialReference targetPrj = pMapcontrol.Map.SpatialReference; IPoint begPtPrj; IPoint endPtPrj; begPt.Project(targetPrj); endPt.Project(targetPrj); begPtPrj = begPt; endPtPrj = endPt; IActiveView pView = this.pMapcontrol.Map as IActiveView; pView.ScreenDisplay.DisplayTransformation.Rotation = 0; double widthHeightR = (((double)pView.ExportFrame.right - pView.ExportFrame.left) / ((double)pView.ExportFrame.bottom - pView.ExportFrame.top)); // Dim fw As New FileWindow(begPt, endPt, widthHeightR) MCenterlineUtil fw = new MCenterlineUtil(begPtPrj, endPtPrj, widthHeightR); fw.FitActiveViewTo(pView, true); System.Runtime.InteropServices.Marshal.ReleaseComObject(pCurcor); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } #region //导出arcmap 地图 export mapfram IPageLayout _PageLayout = this.pPageLayoutControl.PageLayout; SizeF m_PageSize = new SizeF(); double width; double hight; _PageLayout.Page.QuerySize(out width, out hight); m_PageSize.Width = Convert.ToSingle(width); m_PageSize.Height = Convert.ToSingle(hight); IUnitConverter pUConvert = new UnitConverterClass(); esriUnits ut = _PageLayout.Page.Units; float pageUnitToInchUnitScale = (float)pUConvert.ConvertUnits(1, ut, esriUnits.esriInches); var layerOutPageSize = m_PageSize; var outputDPI = 300; int BandHeadWidth = 40; var originalActiveView = _PageLayout as IActiveView; var activeView = _PageLayout as IActiveView; originalActiveView.Refresh(); var avEvents = _PageLayout as IActiveViewEvents; float centerX = layerOutPageSize.Width / 2; float centerY = layerOutPageSize.Height / 2; var backGroundEnv = new Envelope() as IEnvelope; backGroundEnv.PutCoords(0, 0, layerOutPageSize.Width, layerOutPageSize.Height); activeView.Extent = backGroundEnv; //System.Threading.Thread.Sleep(2000); IExport pExporter = new ExportPDF() as IExport; pExporter.ExportFileName = outFile; pExporter.Resolution = outputDPI; var pExPdf = pExporter as IExportPDF; pExPdf.Compressed = true; pExPdf.ImageCompression = esriExportImageCompression.esriExportImageCompressionDeflate; var screenResolution = GetCurrentScreenResolution(); var outputResolution = outputDPI; ESRI.ArcGIS.esriSystem.tagRECT exportRECT; exportRECT.left = 0; exportRECT.top = 0; exportRECT.right = (int)(activeView.ExportFrame.right * outputResolution / screenResolution) + 1; exportRECT.bottom = (int)(activeView.ExportFrame.bottom * outputResolution / screenResolution) + 1; var envelope = new Envelope() as IEnvelope; envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); pExporter.PixelBounds = envelope; var hDC = pExporter.StartExporting(); activeView.Output(hDC, outputDPI, exportRECT, backGroundEnv, null); pExporter.FinishExporting(); pExporter.Cleanup(); // MessageBox.Show("Export finished."); #endregion #region //根据中线图层生成剖面图 System.Drawing.Point LastBottomLeftPoint = new System.Drawing.Point(); int bandwidth = 0; PdfGraphics pGraphics = null; IFeatureLayer pCenterlinePointLayer = null; string centerlinePointnName = cboBoxPointLayer.SelectedItem.ToString(); for (int i = 0; i < pMapcontrol.LayerCount; i++) { if (centerlinePointnName == pMapcontrol.get_Layer(i).Name) { pCenterlinePointLayer = pMapcontrol.get_Layer(i) as IFeatureLayer; } } IQueryFilter pQF = null; DataTable centerlinePointTable = AOFunctions.GDB.ITableUtil.GetDataTableFromITable(pCenterlinePointLayer.FeatureClass as ITable, pQF); chartControl1.Series.Clear(); Series series = new Series("高程", ViewType.Line); Series series2 = new Series("埋深", ViewType.Line); SecondaryAxisY myAxisY = new SecondaryAxisY("埋深"); foreach (DataRow r in centerlinePointTable.Rows) { double m; double z; double underz; m = Convert.ToDouble(r[EvConfig.CenterlineMeasureField]); if (m < BegMeasure || m > endMeasure) { continue; } if (r[EvConfig.CenterlineMeasureField] != DBNull.Value && r[EvConfig.CenterlineZField] != DBNull.Value) { m = Convert.ToDouble(r[EvConfig.CenterlineMeasureField]); z = Convert.ToDouble(r[EvConfig.CenterlineZField]); series.Points.Add(new SeriesPoint(m, z)); } // if (r[EvConfig.CenterlineMeasureField] != DBNull.Value && r["管道埋深("] != DBNull.Value) if (r[EvConfig.CenterlineMeasureField] != DBNull.Value && r[EvConfig.CenterlineBuryDepthField] != DBNull.Value) { m = Convert.ToDouble(r[EvConfig.CenterlineMeasureField]); z = Convert.ToDouble(r[EvConfig.CenterlineBuryDepthField]); series2.Points.Add(new SeriesPoint(m, z)); } } chartControl1.Series.Add(series); chartControl1.Series.Add(series2); ((XYDiagram)chartControl1.Diagram).SecondaryAxesY.Clear(); ((XYDiagram)chartControl1.Diagram).SecondaryAxesX.Clear(); ((XYDiagram)chartControl1.Diagram).SecondaryAxesY.Add(myAxisY); ((LineSeriesView)series2.View).AxisY = myAxisY; ((LineSeriesView)series.View).AxisY = ((XYDiagram)chartControl1.Diagram).AxisY; series.ChangeView(ViewType.Line); ((XYDiagram)chartControl1.Diagram).AxisY.WholeRange.Auto = true; myAxisY.WholeRange.Auto = true; series2.ChangeView(ViewType.Line); myAxisY.Tickmarks.Visible = true; myAxisY.Tickmarks.MinorVisible = false; ((XYDiagram)chartControl1.Diagram).AxisX.WholeRange.AutoSideMargins = false; ((XYDiagram)chartControl1.Diagram).AxisX.WholeRange.SideMarginsValue = 0; ((XYDiagram)chartControl1.Diagram).AxisX.WholeRange.SetMinMaxValues(BegMeasure, endMeasure); series.ArgumentScaleType = ScaleType.Numerical; int ProfileMapHight = 8; #endregion #region export chartcontrol IGraphicsContainer pGC = _PageLayout as IGraphicsContainer; pGC.Reset(); IElement pE = pGC.Next(); while (pE != null) { if (pE is IMapFrame) { // framgeo related to _PageLayout.Page pagesize, 8.5 x 11, inch IEnvelope framgeo = pE.Geometry.Envelope as IEnvelope; float defaultDPI = PdfGraphics.DefaultDpi; double x = defaultDPI * framgeo.LowerLeft.X * pageUnitToInchUnitScale; double y = defaultDPI * (layerOutPageSize.Height - framgeo.LowerLeft.Y) * pageUnitToInchUnitScale + 1; bandwidth = (int)(defaultDPI * (framgeo.Width * pageUnitToInchUnitScale)); LastBottomLeftPoint.X = (int)x; LastBottomLeftPoint.Y = (int)y; chartControl1.Size = new System.Drawing.Size((int)(framgeo.Width * pageUnitToInchUnitScale * defaultDPI), (int)(ProfileMapHight * pageUnitToInchUnitScale * defaultDPI)); Image img = null; Bitmap bmp = null; // Create an image of the chart. ImageFormat format = ImageFormat.Png; using (MemoryStream s = new MemoryStream()) { chartControl1.ExportToImage(s, format); img = Image.FromStream(s); bmp = new Bitmap(img); bmp.SetResolution(300, 300); } using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) { processor.LoadDocument(outFile); PdfDocument pd = processor.Document; PdfPage page = pd.Pages[0]; PdfRectangle pdfrec = page.MediaBox; // RectangleF rf = new RectangleF(0, 0, Convert.ToSingle(pdfrec.Width) * 96 / 72, Convert.ToSingle(pdfrec.Height) * 96 / 72); // Create and draw PDF graphics. using (pGraphics = processor.CreateGraphics()) { PdfGraphics graph = pGraphics; Pen defaultPen = new Pen(Color.Black); defaultPen.Width = 1; graph.DrawImage(bmp, new RectangleF((float)x, (float)y, (float)framgeo.Width * pageUnitToInchUnitScale * defaultDPI, (float)ProfileMapHight * pageUnitToInchUnitScale * defaultDPI)); // draw map head. RectangleF MapheadRect = new RectangleF((float)(int)(defaultDPI * framgeo.XMin * pageUnitToInchUnitScale - BandHeadWidth), (float)(int)(defaultDPI * (layerOutPageSize.Height - framgeo.UpperLeft.Y) * pageUnitToInchUnitScale), (float)(int)(BandHeadWidth), (float)(int)(defaultDPI * framgeo.Height * pageUnitToInchUnitScale)); graph.DrawRectangle(defaultPen, MapheadRect); //draw head text RectangleF rF = new RectangleF(0, 0, (float)MapheadRect.Height, (float)BandHeadWidth); PdfStringFormat psf = new PdfStringFormat(PdfStringFormat.GenericDefault); psf.Alignment = PdfStringAlignment.Center; psf.LineAlignment = PdfStringAlignment.Center; graph.SaveGraphicsState(); // head box 的左下角 System.Drawing.Font textfont = new System.Drawing.Font("仿宋", 6F); graph.TranslateTransform((float)(MapheadRect.Left), (float)(MapheadRect.Bottom)); graph.RotateTransform(270); graph.DrawString("地图", textfont, new SolidBrush(Color.Black), rF, psf); graph.RestoreGraphicsState(); // draw chart head RectangleF ChartheadRect = new RectangleF((float)(int)(defaultDPI * framgeo.XMin * pageUnitToInchUnitScale - BandHeadWidth), (float)(int)(defaultDPI * (layerOutPageSize.Height - framgeo.LowerLeft.Y) * pageUnitToInchUnitScale + 1), (float)(int)(BandHeadWidth), (float)(int)(defaultDPI * ProfileMapHight * pageUnitToInchUnitScale)); graph.DrawRectangle(defaultPen, ChartheadRect); //draw head text rF = new RectangleF(0, 0, (float)ChartheadRect.Height, (float)BandHeadWidth); graph.SaveGraphicsState(); // head box 的左下角 graph.TranslateTransform((float)(ChartheadRect.Left), (float)(ChartheadRect.Bottom)); graph.RotateTransform(270); graph.DrawString("剖面图", textfont, new SolidBrush(Color.Black), rF, psf); graph.RestoreGraphicsState(); LastBottomLeftPoint.Y = (int)ChartheadRect.Bottom; //double beginM = -999; double endM = -999; //GetIMUBeginEndMeasure(ref beginM, ref endM); double beginM = BegMeasure; double endM = endMeasure; for (int i = 0; i < listBoxDrawBandFields.Items.Count; i++) { string fieldname = listBoxDrawBandFields.Items[i].ToString(); band b = new band(); b.BandName = fieldname; b.pdfGC = pGraphics; b.BandWidth = (int)bandwidth; b.headFont = labelbiaotou.Font; b.ContentFont = labelNeirong.Font; System.Drawing.Point pt = new System.Drawing.Point(); pt.X = LastBottomLeftPoint.X; pt.Y = LastBottomLeftPoint.Y; b.BandTopLeftLocation = pt; b.BeginM = beginM; b.EndM = endM; //b.bandData = new List<Tuple<double, string>>(); //for (int j = 0; j < 6; j++) //{ // double m = j * 500; // string txt = "异常2"; // Tuple<double, string> t = new Tuple<double, string>(m,txt); // b.bandData.Add(t); //} b.bandData = GetPDFBandData(fieldname); b.Draw(); LastBottomLeftPoint.Y += (int)b.BandHight; } // graph.DrawImage(img, rf); graph.AddToPageForeground(page); // Render a page with graphics. //processor.RenderNewPage(PdfPaperSize.Letter, graph); processor.SaveDocument(outFile); } } break; } pE = pGC.Next(); } #endregion }