示例#1
0
        /// <summary>
        ///     Updates the field with the specified field <paramref name="index" /> with the <paramref name="value" /> for the
        ///     row.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="index">The index.</param>
        /// <param name="value">The value.</param>
        /// <exception cref="System.ArgumentNullException">row</exception>
        /// <exception cref="System.IndexOutOfRangeException"></exception>
        protected virtual void SetValue(IRow row, int index, object value)
        {
            if (row == null)
            {
                throw new ArgumentNullException("row");
            }
            if (index < 0 || index > row.Fields.FieldCount - 1)
            {
                throw new IndexOutOfRangeException();
            }

            IAnnotationFeature annoFeature = row as IAnnotationFeature;
            IElement           element     = value as IElement;

            if (annoFeature != null && element != null)
            {
                // We have to handle Annotation a little different because the ELEMENT field is controlled by an interface called
                // IAnnotationFeature that is responsible for setting the element and the Shape.
                IFeatureClass             oclass    = (IFeatureClass)row.Table;
                IAnnotationClassExtension annoClass = oclass.Extension as IAnnotationClassExtension;
                if (annoClass != null)
                {
                    int elementFieldIndex = annoClass.ElementFieldIndex;
                    if (index == elementFieldIndex)
                    {
                        annoFeature.Annotation = element;
                        return;
                    }
                }
            }

            row.Value[index] = value;
        }
        private void ProcessAnnotation(IAnnotationLayer annoLayer)
        {
            //get unique values
            IFeatureLayer   featureLayer = annoLayer as IFeatureLayer;
            IDataStatistics dataStats    = new DataStatisticsClass();

            dataStats.Field      = "SymbolID";
            dataStats.SampleRate = -1; //all records
            IQueryFilter queryFilter = new QueryFilterClass();

            queryFilter.SubFields = "SymbolID";
            dataStats.Cursor      = featureLayer.Search(queryFilter, true) as ICursor;

            object value   = null;
            var    enumVar = dataStats.UniqueValues;

            //now remove items
            IFeatureClass             featureClass     = featureLayer.FeatureClass;
            IAnnotationClassExtension annoClassExt     = featureClass.Extension as IAnnotationClassExtension;
            ISymbolCollection2        symbolCollection = annoClassExt.SymbolCollection as ISymbolCollection2;

            ISymbolCollection2 newSymColl = new SymbolCollectionClass();

            while (enumVar.MoveNext())
            {
                value = enumVar.Current;
                ISymbolIdentifier2 symbolIdent = null;
                symbolCollection.GetSymbolIdentifier(Convert.ToInt32(value), out symbolIdent);
                newSymColl.set_Symbol(symbolIdent.ID, symbolIdent.Symbol);
                newSymColl.RenameSymbol(symbolIdent.ID, symbolIdent.Name);
            }

            //update class extension with the new collection
            IAnnoClassAdmin3 annoClassAdmin = annoClassExt as IAnnoClassAdmin3;

            annoClassAdmin.SymbolCollection = (ISymbolCollection)newSymColl;
            annoClassAdmin.UpdateProperties();
        }
示例#3
0
        /// <summary>
        ///     Determines whether the specified objects are equal.
        /// </summary>
        /// <param name="x">The first object of type to compare.</param>
        /// <param name="y">The second object of type to compare.</param>
        /// <param name="index">The index of the field that will be compare.</param>
        /// <returns>
        ///     Returns a <see cref="bool" /> representing <c>true</c> if the specified objects are equal; otherwise, <c>false</c>.
        /// </returns>
        public virtual bool Equals(IRow x, IRow y, int index)
        {
            if ((x == null) && (y == null))
            {
                return(true);
            }

            if ((x == null) ^ (y == null))
            {
                return(false);
            }

            IAnnotationFeature xAnnoFeature = x as IAnnotationFeature;
            IAnnotationFeature yAnnoFeature = y as IAnnotationFeature;

            if (xAnnoFeature != null && yAnnoFeature != null)
            {
                // We have to handle Annotation a little different because the ELEMENT field is controlled by an interface called
                // IAnnotationFeature that is responsible for setting the element and the Shape.
                IFeatureClass oclass = x.Table as IFeatureClass;
                if (oclass != null)
                {
                    IAnnotationClassExtension annoClass = oclass.Extension as IAnnotationClassExtension;
                    if (annoClass != null)
                    {
                        int elementFieldIndex = annoClass.ElementFieldIndex;
                        if (index == elementFieldIndex)
                        {
                            // Since it's Annotation, pass in the Element for comparison instead
                            // of the ELEMENT value itself.
                            return(this.AreEqual(xAnnoFeature.Annotation, yAnnoFeature.Annotation));
                        }
                    }
                }
            }

            return(this.AreEqual(x.Value[index], y.Value[index]));
        }
示例#4
0
        public override void OnDblClick()
        {
            try
            {
                ArcGIS.Common.Editor.Editor.StartEditOperation();
                if (_lineFeedback == null)
                {
                    return;
                }
                _polyline = _lineFeedback.Stop();
                if (_lineFeedback != null)
                {
                    _context.ActiveView.Refresh();
                    _lineFeedback = null;
                }
                if (_polyline == null)
                {
                    return;
                }
                ISelectionEnvironment selectionEnvironment = new SelectionEnvironmentClass();
                selectionEnvironment.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew;
                _context.FocusMap.SelectByShape(_polyline, selectionEnvironment, false);
                ISelection        selection        = _context.FocusMap.FeatureSelection;
                IEnumFeatureSetup enumFeatureSetup = selection as IEnumFeatureSetup;
                IEnumFeature      enumFeature      = enumFeatureSetup as IEnumFeature;
                if (enumFeature == null)
                {
                    return;
                }
                enumFeature.Reset();
                IFeature feature;
                List <MultiCheQiModel> modelList = new List <MultiCheQiModel>();
                while ((feature = enumFeature.Next()) != null)
                {
                    IFeatureClass featureClass = feature.Class as IFeatureClass;
                    if (featureClass == null)
                    {
                        continue;
                    }
                    IFeatureLayer featureLayer =
                        _multiCheQiConfig.FlagLayerList.FirstOrDefault(
                            c => c.FeatureClass.FeatureClassID == featureClass.FeatureClassID);
                    if (featureLayer == null)
                    {
                        continue;
                    }
                    modelList.Add(new MultiCheQiModel(featureLayer, feature, _multiCheQiConfig.FieldSettingList, _polyline));
                }
                if (modelList.Count <= 0)
                {
                    return;
                }

                _context.ActiveView.ScreenDisplay.StartDrawing(_context.ActiveView.ScreenDisplay.hDC, 0);
                IAnnotationClassExtension annotationClassExtension = _multiCheQiConfig.FlagAnnoLayer.FeatureClass.Extension as IAnnotationClassExtension;
                IElement           headerElement           = CommonHelper.CreateHeaderElements(_multiCheQiConfig, _polyline.ToPoint);
                IFeature           headerFeature           = _multiCheQiConfig.FlagAnnoLayer.FeatureClass.CreateFeature();
                IAnnotationFeature headerAnnotationFeature = headerFeature as IAnnotationFeature;
                headerAnnotationFeature.Annotation = headerElement;
                headerFeature.Store();
                double xLength = headerFeature.Shape.Envelope.Width;
                double yLength = headerFeature.Shape.Envelope.Height;

                IPoint headerPoint = new PointClass();
                headerPoint.X                      = (headerElement.Geometry as IPoint).X - xLength / 2;
                headerPoint.Y                      = (headerElement.Geometry as IPoint).Y + yLength * (modelList.Count + 0.5);
                headerElement.Geometry             = headerPoint;
                headerAnnotationFeature.Annotation = headerElement;
                headerFeature.Store();
                annotationClassExtension.Draw(headerAnnotationFeature, _context.ActiveView.ScreenDisplay, null);
                List <MultiCheQiModel> models   = new List <MultiCheQiModel>(modelList.OrderBy(c => c.Distance));
                List <IElement>        elements = CommonHelper.CreateContentElements(_multiCheQiConfig, models,
                                                                                     headerElement.Geometry as IPoint, headerFeature.Shape.Envelope.Width,
                                                                                     headerFeature.Shape.Envelope.Height);
                foreach (IElement element in elements)
                {
                    IFeature           contentFeature           = _multiCheQiConfig.FlagAnnoLayer.FeatureClass.CreateFeature();
                    IAnnotationFeature contentAnnotationFeature = contentFeature as IAnnotationFeature;
                    contentAnnotationFeature.Annotation = element;
                    contentFeature.Store();
                    annotationClassExtension.Draw(contentAnnotationFeature, _context.ActiveView.ScreenDisplay, null);
                }
                _context.ActiveView.ScreenDisplay.FinishDrawing();

                IPointCollection pointCollection = _polyline as IPointCollection;
                IPoint           point1          = new PointClass();
                point1.X = _polyline.ToPoint.X - xLength;
                point1.Y = _polyline.ToPoint.Y;

                IPoint point2 = new PointClass();
                point2.X = _polyline.ToPoint.X - xLength;
                point2.Y = _polyline.ToPoint.Y + yLength * (modelList.Count + 1);

                pointCollection.AddPoint(point1);
                pointCollection.AddPoint(point2);
                IFeature lineFeature = _multiCheQiConfig.FlagLineLayer.FeatureClass.CreateFeature();
                lineFeature.Shape = pointCollection as IPolyline;
                lineFeature.Store();

                _context.ActiveView.Refresh();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
            finally
            {
                ArcGIS.Common.Editor.Editor.StopEditOperation();
            }
        }
示例#5
0
        private void AddElement(IPolyline polyline)
        {
            try
            {
                ArcGIS.Common.Editor.Editor.StartEditOperation();

                string strLineInfo = CommonHelper.GetIntersectInformationFlagLineOnlyOne(polyline, _cheQiConfig,
                                                                                         _feature);
                if (string.IsNullOrWhiteSpace(strLineInfo))
                {
                    MessageBox.Show(@"扯旗字段为空,请重新设置扯旗字段", @"扯旗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                IPoint referPoint = new PointClass();
                referPoint.X = _polyline.ToPoint.X;
                referPoint.Y = _polyline.ToPoint.Y;

                stdole.IFontDisp fontDisp = new StdFontClass() as IFontDisp;
                fontDisp.Name          = _cheQiConfig.FontName;
                fontDisp.Size          = _cheQiConfig.FontSize;
                fontDisp.Italic        = _cheQiConfig.Italic;
                fontDisp.Underline     = _cheQiConfig.Underline;
                fontDisp.Bold          = _cheQiConfig.Bold;
                fontDisp.Strikethrough = _cheQiConfig.Strikethrough;

                ITextSymbol textSymbol = new TextSymbolClass();
                textSymbol.Size  = (double)_cheQiConfig.FontSize;
                textSymbol.Font  = fontDisp;
                textSymbol.Color = _cheQiConfig.FontColor;
                textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;

                ITextElement textElement = new TextElementClass();
                textElement.Text      = strLineInfo;
                textElement.Symbol    = textSymbol;
                textElement.ScaleText = true;

                IPoint textPoint = new PointClass();
                textPoint.X = referPoint.X;
                textPoint.Y = referPoint.Y + 1;

                IElement element = textElement as IElement;
                element.Geometry = textPoint;

                IFeature annoFeature = _cheQiConfig.FlagAnnoLayer.FeatureClass.CreateFeature();
                IAnnotationClassExtension annotationClassExtension = _cheQiConfig.FlagAnnoLayer.FeatureClass.Extension as IAnnotationClassExtension;
                IAnnotationFeature        annotationFeature        = new AnnotationFeatureClass();
                annotationFeature                 = annoFeature as IAnnotationFeature;
                annotationFeature.Annotation      = element;
                annotationFeature.LinkedFeatureID = _feature.OID;
                annoFeature.Store();
                _context.ActiveView.ScreenDisplay.StartDrawing(_context.ActiveView.ScreenDisplay.hDC, 0);
                annotationClassExtension.Draw(annotationFeature, _context.ActiveView.ScreenDisplay, null);
                _context.ActiveView.ScreenDisplay.FinishDrawing();

                double           maxLength            = annoFeature.Shape.Envelope.Width;
                IFeatureClass    flagLineFeatureClass = _cheQiConfig.FlagLineLayer.FeatureClass;
                IFeature         feature         = flagLineFeatureClass.CreateFeature();
                IPointCollection pointCollection = _polyline as IPointCollection;
                IPoint           point           = new PointClass();
                point.Y = referPoint.Y;
                point.X = referPoint.X + maxLength;
                pointCollection.AddPoint(point);
                feature.Shape = pointCollection as IPolyline;
                feature.Store();

                _context.ActiveView.Refresh();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
            finally
            {
                ArcGIS.Common.Editor.Editor.StartEditOperation();
            }
        }