private static void ConvertVectorPicturesToRepresentationMarkers(string stylePath) { IStyleGallery styleGallery = GetStyleGallery(stylePath); IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage; styleGalleryStorage.TargetFile = stylePath; IEnumStyleGalleryItem enumItems = styleGallery.get_Items("Marker Symbols", stylePath, "Vector"); IStyleGalleryItem3 originalItem = null; IStyleGalleryItem3 newItem = null; enumItems.Reset(); originalItem = enumItems.Next() as IStyleGalleryItem3; while (originalItem != null) { newItem = ConvertMarkerItemToRep(originalItem); styleGallery.AddItem(newItem); originalItem = enumItems.Next() as IStyleGalleryItem3; } }
private static void ConvertVectorPicturesToRepresentationMarkers(string stylePath) { if (!System.IO.File.Exists(stylePath)) { Console.WriteLine("StylePath does NOT exist: " + stylePath); return; } IStyleGallery styleGallery = GetStyleGallery(stylePath); IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage; styleGalleryStorage.TargetFile = stylePath; IEnumStyleGalleryItem enumItems = styleGallery.get_Items("Marker Symbols", stylePath, ""); IStyleGalleryItem3 originalItem = null; IStyleGalleryItem3 newItem = null; enumItems.Reset(); originalItem = enumItems.Next() as IStyleGalleryItem3; while (originalItem != null) { IPictureMarkerSymbol pictureMS = originalItem.Item as IPictureMarkerSymbol; if (pictureMS != null) { // check if it requires conversion to rep marker? // TODO: perhaps make this an option if user doesn't need rep's if (containsVectorTag(originalItem.Tags)) { newItem = ConvertMarkerItemToRep(originalItem); Console.WriteLine("Converting symbol " + newItem.Name + " to a representation marker"); styleGallery.AddItem(newItem); } originalItem = enumItems.Next() as IStyleGalleryItem3; } } }
static void ImportMaki(string jsonPath, string stylePath, string renderPath, string emfPath) { IStyleGallery styleGallery = GetStyleGallery(stylePath); IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage; File.Delete(stylePath); //delete the existing Style to start from scratch styleGalleryStorage.TargetFile = stylePath; Icon[] icons = Deserialize(jsonPath); System.Array.Sort(icons); //sort by name IStyleGalleryItem2 styleGalleryItem = null; IStyleGalleryItem2 styleGalleryItemVector = null; string tags = ""; int[] sizes = { 16, 24, 32 }; int[] displays = { 1, 2 }; //the order here is mainly to produce a pleasing experience in ArcMap. Add 96 dpi images at each size first //then add retina, finally add vector foreach (int display in displays) // do regular first, the retina { foreach (Icon icon in icons) { if (icon.tags[0] == "deprecated") { continue; } foreach (int size in sizes) { //raster version IPictureMarkerSymbol rasterPictureMarkerSymbol = MakeMarkerSymbol(renderPath, icon.icon, size, display, false); styleGalleryItem = new StyleGalleryItemClass(); styleGalleryItem.Item = rasterPictureMarkerSymbol; styleGalleryItem.Name = icon.name + " " + size + "px"; string displayDescrip = (display == 2) ? "Retina" : ""; styleGalleryItem.Category = "Picture " + displayDescrip; tags = string.Join(";", icon.tags); //make array into string styleGalleryItem.Tags = tags + ";png" + ";" + size; styleGallery.AddItem((IStyleGalleryItem)styleGalleryItem); } } } //now add vector versions to the end of the list //vector version foreach (Icon icon in icons) { if (icon.tags[0] == "deprecated") { continue; } foreach (int size in sizes) { IPictureMarkerSymbol vectorPictureMarkerSymbol = MakeMarkerSymbol(emfPath, icon.icon, size, 1, true); styleGalleryItemVector = new StyleGalleryItemClass(); styleGalleryItemVector.Item = vectorPictureMarkerSymbol; styleGalleryItemVector.Name = icon.name + " " + size + "px"; styleGalleryItemVector.Category = "Vector"; tags = string.Join(";", icon.tags); //make array into string styleGalleryItemVector.Tags = tags + ";emf" + ";" + size; styleGallery.AddItem((IStyleGalleryItem)styleGalleryItemVector); } } }
static void ImportCSV(string csvPath, string stylePath) { //the expected field names for this util string filePath = "filePath"; string pointSize = "pointSize"; string styleItemName = "styleItemName"; string styleItemCategory = "styleItemCategory"; string styleItemTags = "styleItemTags"; IStyleGallery styleGallery = GetStyleGallery(stylePath); IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage; styleGalleryStorage.TargetFile = stylePath; ITable table = OpenCSVAsTable(csvPath); IRow row = null; int filePathIdx, styleItemNameIdx, pointSizeIdx, styleItemCategoryIdx, styleItemTagsIdx; IStyleGalleryItem3 styleGalleryItem = null; using (ComReleaser comReleaser = new ComReleaser()) { // Create the cursor. ICursor cursor = table.Search(null, false); comReleaser.ManageLifetime(cursor); filePathIdx = cursor.FindField(filePath); styleItemNameIdx = cursor.FindField(styleItemName); pointSizeIdx = cursor.FindField(pointSize); styleItemCategoryIdx = cursor.FindField(styleItemCategory); styleItemTagsIdx = cursor.FindField(styleItemTags); int rowCount = 0; while ((row = cursor.NextRow()) != null) { rowCount++; try { String itemFilePath = (string)row.get_Value(filePathIdx); IPictureMarkerSymbol pictureMarkerSymbol = MakeMarkerSymbol(itemFilePath, Convert.ToDouble(row.get_Value(pointSizeIdx))); if (pictureMarkerSymbol == null) { Console.WriteLine("Image not found: Row: " + rowCount + ", Image: " + itemFilePath); continue; } styleGalleryItem = new StyleGalleryItemClass(); styleGalleryItem.Item = pictureMarkerSymbol; styleGalleryItem.Name = row.get_Value(styleItemNameIdx) as string; styleGalleryItem.Category = row.get_Value(styleItemCategoryIdx) as string; object obj = row.get_Value(styleItemTagsIdx); // set a default tag, just in case tags field is empty string tags = styleGalleryItem.Category + ";" + styleGalleryItem.Name; // Make sure tags are set & a valid string type before converting to string if (!((obj == null) || (obj is DBNull))) { tags = obj as string; } const int MAX_TAG_LENGTH = 255; int tagsLength = tags.Length; if (tagsLength > MAX_TAG_LENGTH) { // WORKAROUND if length > 255 (a hard limit), trim from the front (last most important) tags = tags.Substring(tagsLength - MAX_TAG_LENGTH, MAX_TAG_LENGTH); } // Note: Tag vector symbols for later (see: containsVectorTag) // + switch to disable if desired const bool TAG_EMFS_WITH_VECTOR_TAG = true; if (TAG_EMFS_WITH_VECTOR_TAG && (itemFilePath.Substring(itemFilePath.Length - 4) == ".emf") && (!tags.ToUpper().Contains("VECTOR"))) { tags = tags + ";vector"; } styleGalleryItem.Tags = tags; //we want tags for search. If they weren't specified, use the default tags if (styleGalleryItem.Tags == "") { styleGalleryItem.Tags = styleGalleryItem.DefaultTags; } Console.WriteLine("Importing symbol " + rowCount + " : " + styleGalleryItem.Name); styleGallery.AddItem((IStyleGalleryItem)styleGalleryItem); } catch (Exception ex) { // Catch-all exception for row processing, just so 1 bad row doesn't abort the whole process Console.WriteLine("Skipping bad row: " + rowCount + ", Exception : " + ex.Message); continue; } } } }