private void SetDefaultSymbol(ILineElement elem) { ILineSymbol defaultLineSym = null; String esriStylePath; IStyleGallery styleGallery = new StyleGalleryClass(); IStyleGalleryStorage styleStor = (IStyleGalleryStorage)styleGallery; esriStylePath = styleStor.DefaultStylePath + "ESRI.style"; IEnumStyleGalleryItem styleItems = styleGallery.get_Items("Line Symbols", esriStylePath, "Dashed"); styleItems.Reset(); IStyleGalleryItem styleGalleryItem = styleItems.Next(); while (!(styleGalleryItem == null)) { if (styleGalleryItem.Name == "Dashed 4:4") { defaultLineSym = (ILineSymbol)styleGalleryItem.Item; defaultLineSym.Width = 1.50; IRgbColor rgbColor = new RgbColorClass(); rgbColor.Red = 255; rgbColor.Blue = 0; rgbColor.Green = 0; rgbColor.Transparency = 50; defaultLineSym.Color = rgbColor; break; } else { styleGalleryItem = styleItems.Next(); } } elem.Symbol = defaultLineSym; }
static IStyleGallery GetStyleGallery(string stylePath) { IStyleGallery styleGallery = null; String tempPath = stylePath.ToLower(); if (tempPath.Contains(".serverstyle")) { styleGallery = new ServerStyleGalleryClass(); } else { styleGallery = new StyleGalleryClass(); } return(styleGallery); }
/*从文件获取符号 * */ private ISymbol getSymbolByName(string symbolstyle, string name) { ISymbol result = null; string stylepath = System.Configuration.ConfigurationSettings.AppSettings["SymbolPath"]; //符号管理对象 IStyleGallery pStyleGallery = new StyleGalleryClass(); //符号文件管理, 设定符号文件 IStyleGalleryStorage pStyleStorage = pStyleGallery as IStyleGalleryStorage; IEnumStyleGalleryItem pEnumStyleGall; IStyleGalleryItem pStyleItem; string pp = pStyleStorage.DefaultStylePath; pStyleStorage.AddFile(stylepath); //根据类型取得不同符号集 if (symbolstyle == "1") { pEnumStyleGall = pStyleGallery.get_Items("Marker Symbols", stylepath, ""); } else if (symbolstyle == "2") { pEnumStyleGall = pStyleGallery.get_Items("Line Symbols", stylepath, ""); } else if (symbolstyle == "3") { pEnumStyleGall = pStyleGallery.get_Items("Fill Symbols", stylepath, ""); } else { return(null); } pEnumStyleGall.Reset(); pStyleItem = pEnumStyleGall.Next(); while (pStyleItem != null) //Loop through and access each marker { if (pStyleItem.Name == name) //根据符号名称获取符号 { result = pStyleItem.Item as ISymbol; break; } pStyleItem = pEnumStyleGall.Next(); } return(result); }
/// <summary> /// Creates a renderer for output rasters. /// </summary> /// <param name="pRL"></param> /// <param name="pColor1"></param> /// <param name="pColor2"></param> private void CreateRasterStretchRenderer(IRasterLayer pRL, IRgbColor pColor1, IRgbColor pColor2) { try { IRaster pRaster = pRL.Raster; IRasterStretchColorRampRenderer pStretchRen = new RasterStretchColorRampRendererClass(); IRasterRenderer pRasRen; IAlgorithmicColorRamp pRamp = new AlgorithmicColorRampClass(); IStyleGallery pGallery = new StyleGalleryClass(); bool bCreate; //create renderer pRasRen = (IRasterRenderer)pStretchRen; pRasRen.Raster = pRaster; pRasRen.Update(); //create color ramp pRamp.Size = 255; pRamp.FromColor = pColor1; pRamp.ToColor = pColor2; pRamp.CreateRamp(out bCreate); //apply the color ramp pStretchRen.BandIndex = 0; pStretchRen.ColorRamp = pRamp; IRasterStretch pRasStretch = (IRasterStretch)pStretchRen; pRasStretch.Background = true; double dValue = 0; pRasStretch.set_BackgroundValues(ref dValue); pRasRen.Update(); pRL.Renderer = (IRasterRenderer)pStretchRen; ArcMap.Document.ActiveView.Refresh(); ArcMap.Document.UpdateContents(); } catch (Exception ex) { clsStatic.ShowErrorMessage(ex.ToString()); } }
private void SetDefaultSymbol(ILineElement elem) { ILineSymbol defaultLineSym = null; String esriStylePath; IStyleGallery styleGallery = new StyleGalleryClass(); IStyleGalleryStorage styleStor = (IStyleGalleryStorage)styleGallery; esriStylePath = styleStor.DefaultStylePath + "ESRI.style"; IEnumStyleGalleryItem styleItems = styleGallery.get_Items("Line Symbols",esriStylePath,"Dashed"); styleItems.Reset(); IStyleGalleryItem styleGalleryItem = styleItems.Next(); while (!(styleGalleryItem == null)) { if (styleGalleryItem.Name == "Dashed 4:4") { defaultLineSym = (ILineSymbol)styleGalleryItem.Item; defaultLineSym.Width = 1.50; IRgbColor rgbColor = new RgbColorClass(); rgbColor.Red = 255; rgbColor.Blue = 0; rgbColor.Green = 0; rgbColor.Transparency = 50; defaultLineSym.Color = rgbColor; break; } else { styleGalleryItem = styleItems.Next(); } } elem.Symbol = defaultLineSym; }
static IStyleGallery GetStyleGallery(string stylePath) { IStyleGallery styleGallery = null; String tempPath = stylePath.ToLower(); if (tempPath.Contains(".serverstyle")) { styleGallery = new ServerStyleGalleryClass(); } else { styleGallery = new StyleGalleryClass(); } return styleGallery; }
private void button1_Click(object sender, EventArgs e) { string target = this.tbxInput.Text; string cat = this.tbxSet.Text; int size = int.Parse(this.tbxSize.Text); string pdf = this.tbxOutput.Text; int labelsize = int.Parse(this.tbxLabelSize.Text); int lwidth = int.Parse(this.tbxWidth.Text); int label_h = labelsize; int size_w = size; int size_h = size + label_h; List<string> pdfpages = new List<string>(); IPageLayout3 layout = new PageLayoutClass(); IGraphicsContainer con = layout as IGraphicsContainer; IPage page = layout.Page; page.FormID = esriPageFormID.esriPageFormA4; page.Units = esriUnits.esriPoints; double width; double height; page.QuerySize(out width, out height); int col = (int)Math.Floor(width / size_w); int row = (int)Math.Floor(height / size_h); IStyleGalleryStorage sgs = new StyleGalleryClass(); while (sgs.FileCount > 0) { sgs.RemoveFile(sgs.get_File(0)); } IStyleGallery sg = sgs as IStyleGallery; sgs.AddFile(target); sgs.TargetFile = target; if (cbPoint.Checked) { List<string> ps = ExportSymbol(sg, "Marker Symbols", col, row, size, lwidth,labelsize, label_h, size_w, size_h, height, cat, layout); pdfpages.AddRange(ps); } if(cbLine.Checked) { List<string> ps = ExportSymbol(sg, "Line Symbols", col, row, size, lwidth, labelsize, label_h, size_w, size_h, height, cat, layout); pdfpages.AddRange(ps); } if (cbArea.Checked) { List<string> ps = ExportSymbol(sg, "Fill Symbols", col, row, size, lwidth, labelsize, label_h, size_w, size_h, height, cat, layout); pdfpages.AddRange(ps); } PdfDocument doc = new PdfDocument(); foreach (string temp in pdfpages) { PdfDocument temp_doc = PdfReader.Open(temp, PdfDocumentOpenMode.Import); doc.AddPage(temp_doc.Pages[0]); } if (doc.PageCount > 0) { doc.Save(pdf); } doc.Close(); MessageBox.Show("成功生成符号图集"); }
private void button1_Click(object sender, EventArgs e) { string input = this.tbxInput.Text; string cat = this.tbxSet.Text; string folder = this.tbxOutput.Text; string target = this.tbxTarget.Text; string depth = this.cbxDepth.Text; IStyleGalleryStorage sgs = new StyleGalleryClass(); while (sgs.FileCount > 0) { sgs.RemoveFile(sgs.get_File(0)); } IStyleGallery sg = sgs as IStyleGallery; sgs.AddFile(input); sgs.TargetFile = target; IPageLayout3 layout = new PageLayoutClass(); IGraphicsContainer con = layout as IGraphicsContainer; IPage page = layout.Page; page.Units = esriUnits.esriPoints; IRgbColor bgc = new RgbColorClass(); bgc.Red = 255; bgc.Green = 255; bgc.Blue = 254; IFrameProperties fp = page as IFrameProperties; ISymbolBackground bg = new SymbolBackgroundClass(); bg.Gap = 0; ISimpleFillSymbol sfs = new SimpleFillSymbolClass(); sfs.Color = bgc as IColor; ISimpleLineSymbol sls = new SimpleLineSymbolClass(); sls.Style = esriSimpleLineStyle.esriSLSNull; sfs.Outline = sls; bg.FillSymbol = sfs as IFillSymbol; fp.Background = bg; IEnumStyleGalleryItem items = sg.get_Items("Marker Symbols", input, cat); IStyleGalleryItem item = items.Next(); while (item != null) { //con.DeleteAllElements(); IMarkerElement mele = new MarkerElementClass(); IMarkerSymbol sym_m = item.Item as IMarkerSymbol; IMultiLayerMarkerSymbol sym_ml = sym_m as IMultiLayerMarkerSymbol; double pic_size; if (sym_ml.Size % 2 == 0) { pic_size = sym_ml.Size+4; } else { pic_size = sym_ml.Size+5; } page.PutCustomSize(pic_size, pic_size); IPoint ptn = new PointClass(); ptn.PutCoords(pic_size / 2, pic_size / 2); IElement ele_i = mele as IElement; ele_i.Geometry = ptn; sym_m.Size = sym_ml.Size; mele.Symbol = sym_m; con.AddElement(ele_i, 0); IActiveView av = layout as IActiveView; string pic_file = folder+"\\"+item.Name + ".png"; ExportPNG(av, pic_file,bgc,depth); con.DeleteElement(ele_i); ISymbol sym = CreatePictureMarkerSymbol(esriIPictureType.esriIPicturePNG, pic_file, pic_size) as ISymbol; IStyleGalleryItem newitem = new StyleGalleryItemClass(); newitem.Name = item.Name; newitem.Item = sym; newitem.Category = cat; sg.AddItem(newitem); item = items.Next(); } MessageBox.Show("成功导出图标"); }
private void button1_Click(object sender, EventArgs e) { this.button1.Enabled = false; esriIPictureType ptype=esriIPictureType.esriIPicturePNG; switch (cbxPType.Text) { case "BMP": ptype=esriIPictureType.esriIPictureBitmap; break; case "GIF": ptype=esriIPictureType.esriIPictureGIF; break; case "EMF": ptype=esriIPictureType.esriIPictureEMF; break; case "JPEG": ptype=esriIPictureType.esriIPictureJPG; break; } try { int size = int.Parse(this.tbxSize.Text); string cat = this.tbxSet.Text; string folder = this.tbxFolder.Text; string target = this.tbxOutput.Text; IStyleGalleryStorage sgs = new StyleGalleryClass(); sgs.TargetFile = target; IStyleGallery sg = sgs as IStyleGallery; int i = 0; foreach (string f in Directory.GetFiles(folder)) { string name = Path.GetFileNameWithoutExtension(f); string pic = f; if (cbIsScale.Checked) { pic = ScalePicture(f, size); } ISymbol sym = CreatePictureMarkerSymbol(ptype, pic, size) as ISymbol; IStyleGalleryItem item = new StyleGalleryItemClass(); if (cbIsFileName.Checked) { item.Name = name; } else { item.Name = i.ToString(); } item.Item = sym; item.Category = cat; sg.AddItem(item); i++; } sg.SaveStyle(target, cat, ""); MessageBox.Show("�ɹ�������ʽ�⡣"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } this.button1.Enabled = true; }
/// <summary> /// This method loads the configured style files /// </summary> private bool LoadStyleFiles() { bool success = true; IStyleGallery styleGallery = new StyleGalleryClass(); IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage; try { if (styleGalleryStorage != null) { // Debug Info, if needed: // Console.WriteLine(String.Format("Default folder : {0}, File Count : {1}", StyleGalleryStorage.DefaultStylePath, StyleGalleryStorage.FileCount)); // Console.WriteLine(String.Format("Class Count : {0}", StyleGallery.ClassCount)); // First remove current Styles int fileCount = styleGalleryStorage.FileCount; List<string> files = new List<string>(); for (int i = 0; i < fileCount; i++) { string file = styleGalleryStorage.get_File(i); files.Add(file); } foreach (string path in files) { styleGalleryStorage.RemoveFile(path); } List<string> styleFiles = styleFiles2525; if (symbologyStandard.ToUpper().Contains("APP6")) styleFiles = styleFilesApp6; // WORKAROUND: loading all styles at once causing issues so doing them one at a time foreach (string styleFile in styleFiles) { string stylepath = styleGalleryStorage.DefaultStylePath + styleFile; if (!System.IO.File.Exists(stylepath)) { // Check files exists and issue warning and bails if not success = false; LogError("Could not find required Style: " + stylepath); break; } // ex: string stylepath = @"C:\Program Files (x86)\ArcGIS\Desktop10.1\Styles\" + styleFile; styleGalleryStorage.AddFile(stylepath); System.Diagnostics.Trace.WriteLine("Style: " + styleFile); // IMPORTANT: Note: preloading all the gallery items for faster lookup try { ProcessStyleGalleryItems(styleGallery, "Marker Symbols"); ProcessStyleGalleryItems(styleGallery, "Representation Rules"); } catch (Exception ex) { LogError("Exception: " + ex); } styleGalleryStorage.RemoveFile(stylepath); } } } catch (Exception ex2) { LogError("Exception: " + ex2); } // release objects int refsLeft = 0; do { refsLeft = System.Runtime.InteropServices.Marshal.ReleaseComObject(styleGallery); } while (refsLeft > 0); styleGallery = null; GC.Collect(); GC.WaitForPendingFinalizers(); return success; }