Esempio n. 1
0
        private static IStyleGalleryItem3 ConvertMarkerItemToRep(IStyleGalleryItem3 inputItem)
        {
            IMarkerSymbol           markerSymbol = inputItem.Item as IMarkerSymbol;
            IRepresentationRule     repRule      = new RepresentationRuleClass();
            IRepresentationRuleInit repRuleInit  = repRule as IRepresentationRuleInit;

            repRuleInit.InitWithSymbol((ISymbol)markerSymbol); //initialize the rep rule with the marker
            IRepresentationGraphics representationGraphics = new RepresentationMarkerClass();

            IGraphicAttributes      graphicAttributes  = null;
            IRepresentationGraphics tempMarkerGraphics = null;
            IGeometry           tempGraphicGeometry    = null;
            IRepresentationRule tempRule = null;

            //only pull the markers out.
            for (int i = 0; i < repRule.LayerCount; i++)
            {
                graphicAttributes  = repRule.get_Layer(i) as IGraphicAttributes;
                tempMarkerGraphics = graphicAttributes.get_Value((int)esriGraphicAttribute.esriGAMarker) as IRepresentationGraphics;

                tempMarkerGraphics.Reset();
                tempMarkerGraphics.Next(out tempGraphicGeometry, out tempRule);

                while (tempRule != null && tempGraphicGeometry != null)
                {
                    representationGraphics.Add(tempGraphicGeometry, tempRule);
                    tempGraphicGeometry = null;
                    tempRule            = null;
                    tempMarkerGraphics.Next(out tempGraphicGeometry, out tempRule);
                }
            }

            IStyleGalleryItem3 newMarkerStyleGalleryItem = new ServerStyleGalleryItemClass();

            newMarkerStyleGalleryItem.Item     = representationGraphics;
            newMarkerStyleGalleryItem.Name     = inputItem.Name;
            newMarkerStyleGalleryItem.Category = inputItem.Category;
            newMarkerStyleGalleryItem.Tags     = inputItem.Tags.Replace(";emf", ""); //strip emf from the tags

            return(newMarkerStyleGalleryItem);
        }
Esempio n. 2
0
        private static IStyleGalleryItem3 ConvertMarkerItemToRep(IStyleGalleryItem3 inputItem)
        {
            IMarkerSymbol markerSymbol = inputItem.Item as IMarkerSymbol;
              IRepresentationRule repRule = new RepresentationRuleClass();
              IRepresentationRuleInit repRuleInit = repRule as IRepresentationRuleInit;

              repRuleInit.InitWithSymbol((ISymbol)markerSymbol); //initialize the rep rule with the marker
              IRepresentationGraphics representationGraphics = new RepresentationMarkerClass();

              IGraphicAttributes graphicAttributes = null;
              IRepresentationGraphics tempMarkerGraphics = null;
              IGeometry tempGraphicGeometry = null;
              IRepresentationRule tempRule = null;

              //only pull the markers out.
              for (int i = 0; i < repRule.LayerCount; i++)
              {

            graphicAttributes = repRule.get_Layer(i) as IGraphicAttributes;
            tempMarkerGraphics = graphicAttributes.get_Value((int)esriGraphicAttribute.esriGAMarker) as IRepresentationGraphics;

            tempMarkerGraphics.Reset();
            tempMarkerGraphics.Next(out tempGraphicGeometry, out tempRule);

            while (tempRule != null && tempGraphicGeometry != null)
            {
              representationGraphics.Add(tempGraphicGeometry, tempRule);
              tempGraphicGeometry = null;
              tempRule = null;
              tempMarkerGraphics.Next(out tempGraphicGeometry, out tempRule);
            }
              }

              IStyleGalleryItem3 newMarkerStyleGalleryItem = new ServerStyleGalleryItemClass();
              newMarkerStyleGalleryItem.Item = representationGraphics;
              newMarkerStyleGalleryItem.Name = inputItem.Name;
              newMarkerStyleGalleryItem.Category = inputItem.Category;
              newMarkerStyleGalleryItem.Tags = inputItem.Tags.Replace(";emf", ""); //strip emf from the tags

              return newMarkerStyleGalleryItem;
        }
Esempio n. 3
0
        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;
            }
        }
Esempio n. 4
0
        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;
                }
            }
        }
Esempio n. 5
0
        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;
                    }
                }
            }
        }