Exemple #1
0
        IPoint IntersectPointExtendedTo(IPolyline pPolyline, IPolygon pCirclePoly)
        {
            ICurve               pCurve;
            ILine                pLine;
            IPolyline            pPLine;
            ITopologicalOperator pTopoOpt;
            IGeometryCollection  pGeoCol;

            pCurve = pPolyline;
            pLine  = new Line();
            double gridWidth = _mapTemplate.Width * _scale / 100.0;

            pCurve.QueryTangent(esriSegmentExtension.esriExtendTangentAtTo, 1, true, gridWidth * 1.1, pLine);
            pPLine = new Polyline() as IPolyline;
            IPointCollection pPnts  = pPLine as IPointCollection;
            IClone           pClone = pLine.FromPoint as IClone;

            pPnts.AddPoint(pClone.Clone() as IPoint);
            pClone = pLine.ToPoint as IClone;
            pPnts.AddPoint(pClone.Clone() as IPoint);
            pTopoOpt = pPLine as ITopologicalOperator;
            pGeoCol  = new GeometryBag() as IGeometryCollection;
            pGeoCol  =
                pTopoOpt.Intersect(pCirclePoly, esriGeometryDimension.esriGeometry0Dimension) as IGeometryCollection;
            if (pGeoCol.GeometryCount == 0)
            {
                return(null);
            }
            return(pGeoCol.Geometry[0] as IPoint);
        }
Exemple #2
0
        //获取当前的缓冲后的几何体
        private void get_BufferGeometry()
        {
            //存在上次的缓冲几何体 则先抹去其图形
            if (m_pBufferGeometry != null)
            {
                drawgeometryXOR(m_pBufferGeometry as IPolygon, m_pScreenDisplay);
            }

            //获取缓冲半径
            double dBufferSize = ((double)trackBar.Value /*/ 10*/);

            dBufferSize = dBufferSize < 1 ? 1 : dBufferSize;
            //if ( dBufferSize == 0.0) dBufferSize = 0.001;

            //==如果直接操作,则原pGeometry会被改变
            //进行克隆,获取topo实例
            IClone pClone = (IClone)m_pGeometry;
            ITopologicalOperator pTopo;

            if (m_pGeometry.GeometryType != esriGeometryType.esriGeometryBag)
            {
                pTopo = pClone.Clone() as ITopologicalOperator;

                //topo非空则进行缓冲,获取缓冲后的 m_pBufferGeometry
                if (pTopo != null)
                {
                    m_pBufferGeometry = pTopo.Buffer(dBufferSize);
                }
            }
            else
            {
                IGeometryCollection pGeometryBag = (IGeometryCollection)pClone.Clone();
                pTopo = (ITopologicalOperator)pGeometryBag.get_Geometry(0);
                IGeometry pUnionGeom = pTopo.Buffer(dBufferSize);
                for (int i = 1; i < pGeometryBag.GeometryCount; i++)
                {
                    pTopo = (ITopologicalOperator)pGeometryBag.get_Geometry(i);
                    IGeometry pTempGeom = pTopo.Buffer(dBufferSize);
                    pTopo      = (ITopologicalOperator)pUnionGeom;
                    pUnionGeom = pTopo.Union(pTempGeom);
                }
                m_pBufferGeometry = pUnionGeom;
            }
            // m_pBufferGeometry为空,直接返回
            if (m_pBufferGeometry == null)
            {
                return;
            }

            //对 m_pBufferGeometry的topo进行简化再绘出
            pTopo = m_pBufferGeometry as ITopologicalOperator;
            if (pTopo != null)
            {
                pTopo.Simplify();
            }

            IPolygon pPolygon = m_pBufferGeometry as IPolygon;

            drawgeometryXOR(pPolygon, m_pScreenDisplay);
        }
        public IFeatureLayer  CreateLayer(IFeatureClass pFeatureClass, int index)  //新建任意范围打印地图的图层
        {
            string FilePath = @"C:\任意打印\";
            string FileName = "bb" + index.ToString();
            /////////////////////////////////////////////////
            // ILayerFile layerFile = new LayerFileClass();

            // layerFile.New(FilePath + FileName);

            /////////////////////////////////////////////


            IFields           pFields        = pFeatureClass.Fields;
            IClone            pClone         = pFields as IClone;
            IFields           pCloneFields   = pClone.Clone() as IFields;
            IDataset          pDataSet       = pFeatureClass as IDataset;
            IWorkspace        pWorkSpace     = pDataSet.Workspace;
            IFeatureWorkspace pFeatWorkspace = pWorkSpace as IFeatureWorkspace;

            IFeatureClass newFeatcls = pFeatWorkspace.CreateFeatureClass(FileName, pCloneFields,
                                                                         null, null, esriFeatureType.esriFTSimple, pFeatureClass.ShapeFieldName, "");
            IFeatureLayer pFeatureLayer = new FeatureLayerClass();

            pFeatureLayer.FeatureClass = newFeatcls;
            pFeatureLayer.Name         = newFeatcls.AliasName;

            return(pFeatureLayer);

            // System.Runtime.InteropServices.Marshal.ReleaseComObject(FilePath);
            // System.Runtime.InteropServices.Marshal.ReleaseComObject(FileName );
            // System.Runtime.InteropServices.Marshal.ReleaseComObject(pFields );
            //System.Runtime.InteropServices.Marshal.ReleaseComObject(pDataSet );
            // System.Runtime.InteropServices.Marshal.ReleaseComObject(newFeatcls);
        }
Exemple #4
0
        private void dataGridView3_CellClick(object obj, DataGridViewCellEventArgs dataGridViewCellEventArgs)
        {
            if (dataGridViewCellEventArgs.RowIndex < 0)
            {
                return;
            }
            IFeatureClass featureClass = this.m_pCurLayer.FeatureClass;

            try
            {
                string        str              = this.dataGridView3[0, dataGridViewCellEventArgs.RowIndex].Value.ToString();
                string        whereClause      = featureClass.OIDFieldName + " = " + str;
                IFeatureClass arg_5C_0         = featureClass;
                IQueryFilter  queryFilterClass = new QueryFilter();
                queryFilterClass.WhereClause = (whereClause);
                IFeatureCursor featureCursor = arg_5C_0.Search(queryFilterClass, false);
                IFeature       feature       = featureCursor.NextFeature();
                IGeometry      shape         = feature.Shape;
                IClone         clone         = (IClone)shape;
                IClone         clone2        = clone.Clone();
                this.igeometry_0 = (IGeometry)clone2;
                this.ScaleToGeo(this.m_iApp.ActiveView, this.igeometry_0);
                this.m_nCurRowIndex = dataGridViewCellEventArgs.RowIndex;
                this.timer_0.Start();
                this.m_nTimerCounter = 0;
                this.m_iApp.ActiveView.Refresh();
            }
            catch (Exception)
            {
            }
        }
Exemple #5
0
        private void CopyLayerToOverview(string layerName)
        {
            IFeatureLayer featureLayerClass;
            IFeatureLayer featureLayer = null;

            if (_mainMapControl.LayerCount == 0)
            {
                return;
            }

            ILayer pLayer = LayerHelper.QueryLayerByDisplayName(_context.MapControl.Map, layerName) as ILayer;

            if (pLayer == null)
            {
                CopyLastLayerToOverview();
                return;
            }

            IClone pClone   = pLayer as IClone;
            ILayer newLayer = pClone.Clone() as ILayer;

            newLayer.Visible = true;
            axMapControl1.Map.AddLayer(newLayer);
            this.axMapControl1.Extent = _mainMapControl.FullExtent;
        }
Exemple #6
0
        //尝试复制Legend
        private void DeepCopyLegend(ILegend SrcLegend, ILegend DstLegend)
        {
            IClone pSrc  = SrcLegend as IClone;
            IClone pDest = pSrc.Clone();

            DstLegend = pDest as ILegend;
        }
Exemple #7
0
        private void method_5()
        {
            this.bool_6 = true;
            this.bool_1 = false;
            IEnumFeature        enumFeature        = _context.FocusMap.FeatureSelection as IEnumFeature;
            IGeometryCollection geometryCollection = new GeometryBag() as IGeometryCollection;

            enumFeature.Reset();
            IFeature feature = enumFeature.Next();
            object   value   = Missing.Value;

            while (feature != null)
            {
                esriGeometryType geometryType = feature.Shape.GeometryType;
                if (geometryType == esriGeometryType.esriGeometryPolygon ||
                    geometryType == esriGeometryType.esriGeometryPolyline)
                {
                    IClone clone = feature.Shape as IClone;
                    geometryCollection.AddGeometry(clone.Clone() as IGeometry, ref value, ref value);
                    this.bool_4 = true;
                }
                feature = enumFeature.Next();
            }
            if (this.bool_2)
            {
                this.isegmentGraph_0.SetEmpty();
                this.isegmentGraphCursor_0 = null;
            }
            this.isegmentGraph_0.Load(geometryCollection as IEnumGeometry, false, true);
            this.bool_2 = false;
        }
        //复制指北针
        private void CopyNorthArrow(INorthArrow srcArrow, INorthArrow destArrow)
        {
            IClone pSrc  = srcArrow as IClone;
            IClone pDest = pSrc.Clone();

            destArrow = pDest as INorthArrow;
        }
Exemple #9
0
        //面构成线
        private static IPolyline PolygonToPolyline(ref IPolygon pPolygon)
        {
            try
            {
                //创建一个新的Polygon geometry.
                IGeometryCollection pPolygonGeometryCol = new PolylineClass();

                //克隆即将要操作的Polyline
                IClone pClone = pPolygon as IClone;

                IGeometryCollection pGeoms_Polygon = pClone.Clone() as IGeometryCollection;
                object pBObj = Type.Missing;
                object pAObj = Type.Missing;
                for (int i = 0; i < pGeoms_Polygon.GeometryCount; i++)
                {
                    //通过Polyline的每个Path创建为一个新的Ring,并把Ring增加到一个新的Polygon
                    ISegmentCollection pSegs_Path = new Path() as ISegmentCollection;
                    pSegs_Path.AddSegmentCollection(pGeoms_Polygon.get_Geometry(i) as ISegmentCollection);
                    pPolygonGeometryCol.AddGeometry(pSegs_Path as IGeometry, ref pBObj, ref pAObj);
                }
                //生成的Polygon旋转的顺序可能不正确,为确保正确调用SimplifyPreserveFromTo
                IPolyline pNewPolyline = new PolylineClass();
                pNewPolyline = pPolygonGeometryCol as IPolyline;

                return(pNewPolyline);
            }
            catch
            {
                return(null);
            }
        }
Exemple #10
0
 public IPolyline ConvertPointsToPolyline(IPointCollection pPoints)
 {
     try
     {
         if (pPoints == null)
         {
             return(null);
         }
         IClone           clone  = pPoints as IClone;
         IPointCollection points = null;
         points = clone.Clone() as IPointCollection;
         if (points.PointCount < 0)
         {
             return(null);
         }
         IPointCollection points2 = null;
         points2 = new PolylineClass();
         int    i      = 0;
         object before = null;
         object after  = null;
         for (i = 0; i <= (points.PointCount - 1); i++)
         {
             points2.AddPoint(points.get_Point(i), ref before, ref after);
         }
         (points2 as ITopologicalOperator).Simplify();
         return(points2 as IPolyline);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.GeometryFun", "ConvertPointsToPolyline", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(null);
     }
 }
Exemple #11
0
        public void ZoomToPoint(AxGlobeControl axGlobeControl, double MapX, double MapY)
        {
            try
            {
                IPoint point = new PointClass();
                point.PutCoords(MapX, MapY);    //设置点击的点坐标
                //point = CommonBaseTool.BaseGISTools.getGeoPoint(MapX, MapY);        //转换坐标

                IPoint ptObserver = new PointClass();
                IPoint ptTarget   = new PointClass();

                //Observer点
                IClone pClone1 = point as IClone;
                ptObserver   = pClone1.Clone() as IPoint;
                ptObserver.Y = ptObserver.Y - 0.08;
                ptObserver.Z = 15.45;
                //Target点
                IClone pClone2 = point as IClone;
                ptTarget   = pClone2.Clone() as IPoint;
                ptTarget.Z = -0.01;

                axGlobeControl.GlobeCamera.SetObserverLatLonAlt(ptObserver.Y, ptObserver.X, ptObserver.Z);
                axGlobeControl.GlobeCamera.SetTargetLatLonAlt(ptTarget.Y, ptTarget.X, ptTarget.Z);
                //刷新
                axGlobeControl.GlobeDisplay.RefreshViewers();
            }
            catch { }
        }
        //复制MapFrame
        private void CopyMapSurroundFrame(IMapSurroundFrame srcArrow, IMapSurroundFrame destArrow)
        {
            IClone pSrc  = srcArrow as IClone;
            IClone pDest = pSrc.Clone();

            destArrow = pDest as IMapSurroundFrame;
        }
Exemple #13
0
        public static IEnvelope Clone(this IEnvelope envelope)
        {
            IClone    clone         = (IClone)envelope;
            object    copy          = clone.Clone();
            IEnvelope envelopeClone = (IEnvelope)copy;

            return(envelopeClone);
        }
Exemple #14
0
        /// <summary>
        /// 算出量测计算结果,并在FormDis上进行显示
        /// </summary>
        /// <param name="ipGeo">人机交互生成的实体</param>
        public void WriteLabelText(IGeometry ipGeo)
        {
            switch (m_MeasureType)
            {
            case MeasureType.Length:              //量测长度
            {
                string strUnit = " " + (this.m_Tool as ToolMeasureLength).m_hookHelper.FocusMap.MapUnits.ToString().Substring(4);
                //this.m_LabelMeasureType.Text = "Line Measurement";
                this.m_LabelMeasureType.Text = "长度量测";
                this.m_labelArea.Visible     = true;
                if (ipGeo != null)
                {
                    IGeometryCollection ipGeoCol      = ipGeo as IGeometryCollection;
                    ISegmentCollection  ipSegmentColl = ipGeoCol.get_Geometry(0) as ISegmentCollection;
                    ILine ipLine = ipSegmentColl.get_Segment(ipSegmentColl.SegmentCount - 1) as ILine;
                    //this.m_labelSegment.Text = "段长度:" + ipLine.Length.ToString() + strUnit;
                    //this.m_labelLength.Text = "长度:" + (ipGeoCol.get_Geometry(0) as ICurve).Length.ToString() + "米";
                    this.m_labelArea.Text = "长度:" + (ipGeoCol.get_Geometry(0) as ICurve).Length.ToString("f3") + "米";
                }
                else
                {
                    this.m_labelArea.Text = "长度:" + "0" + "米";
                    //this.m_labelLength.Text = "总长度:" + "0" + strUnit;
                }
            }
            break;

            case MeasureType.Area:      //量测面积
            {
                string strUnit = " " + (this.m_Tool as ToolMeasureArea).m_hookHelper.FocusMap.MapUnits.ToString().Substring(4);
                //this.m_LabelMeasureType.Text = "Area Measurement";
                this.m_LabelMeasureType.Text = "面积量测";
                this.m_labelArea.Visible     = true;
                if (ipGeo != null)
                {
                    IGeometryCollection ipGeoCol      = ipGeo as IGeometryCollection;
                    ISegmentCollection  ipSegmentColl = ipGeoCol.get_Geometry(0) as ISegmentCollection;
                    ILine ipLine = ipSegmentColl.get_Segment(ipSegmentColl.SegmentCount - 1) as ILine;
                    //this.m_labelSegment.Text = "Segment:" + ipLine.Length.ToString() + strUnit;
                    //this.m_labelLength.Text = "Perimeter:" + (ipGeoCol.get_Geometry(0) as IRing).Length.ToString() + strUnit;
                    //this.m_labelSegment.Text = "段长度:" + ipLine.Length.ToString() + strUnit;
                    //this.m_labelLength.Text = "周长:" + (ipGeoCol.get_Geometry(0) as IRing).Length.ToString() + strUnit;

                    IClone               ipClone = ipGeo as IClone;
                    IGeometry            ipGeo1  = ipClone.Clone() as IGeometry;
                    ITopologicalOperator ipTopo  = ipGeo1 as ITopologicalOperator;
                    ipTopo.Simplify();

                    this.m_labelArea.Text = "面积:" + ((ipGeo1 as IPolygon) as IArea).Area.ToString(".###") + "平方米";
                }
                else
                {
                    this.m_labelArea.Text = "面积:" + "0" + "平方米";
                }
            }
            break;
            }
        }
Exemple #15
0
        private IFeatureClass method_1(IFeatureWorkspace ifeatureWorkspace_0, string string_4, double double_0,
                                       ITextSymbol itextSymbol_0, IFields ifields_0)
        {
            IObjectClassDescription  description  = new AnnotationFeatureClassDescriptionClass();
            IFeatureClassDescription description2 = description as IFeatureClassDescription;
            IClone     requiredFields             = description.RequiredFields as IClone;
            IFields    fields = requiredFields.Clone() as IFields;
            IFieldEdit edit   = null;
            int        index  = fields.FindField(description2.ShapeFieldName);

            edit = fields.get_Field(index) as IFieldEdit;
            IGeometryDefEdit      geometryDef    = edit.GeometryDef as IGeometryDefEdit;
            IFeatureWorkspaceAnno anno           = ifeatureWorkspace_0 as IFeatureWorkspaceAnno;
            IGraphicsLayerScale   referenceScale = new GraphicsLayerScaleClass
            {
                ReferenceScale = double_0,
                Units          = esriUnits.esriMeters
            };
            UID instanceCLSID                  = description.InstanceCLSID;
            UID classExtensionCLSID            = description.ClassExtensionCLSID;
            ISymbolCollection symbolCollection = new SymbolCollectionClass();

            symbolCollection.set_Symbol(0, itextSymbol_0 as ISymbol);
            IAnnotateLayerPropertiesCollection2 annoProperties = new AnnotateLayerPropertiesCollectionClass();
            IAnnotateLayerProperties            item           = new LabelEngineLayerPropertiesClass
            {
                Class         = "要素类 1",
                FeatureLinked = false,
                AddUnplacedToGraphicsContainer = false,
                CreateUnplacedElements         = true,
                DisplayAnnotation = true,
                UseOutput         = true
            };
            ILabelEngineLayerProperties properties2 = item as ILabelEngineLayerProperties;

            properties2.Offset   = 0.0;
            properties2.SymbolID = 0;
            properties2.Symbol   = itextSymbol_0;
            annoProperties.Add(item);
            for (int i = 0; i < ifields_0.FieldCount; i++)
            {
                if (fields.FindField(ifields_0.get_Field(i).Name) == -1)
                {
                    (fields as IFieldsEdit).AddField(ifields_0.get_Field(i));
                }
            }
            try
            {
                return(anno.CreateAnnotationClass(string_4, fields, instanceCLSID, classExtensionCLSID,
                                                  description2.ShapeFieldName, "", null, null, annoProperties, referenceScale, symbolCollection, false));
            }
            catch (Exception exception)
            {
                Logger.Current.Error("", exception, "");
            }
            return(null);
        }
        public void LayerRender()
        {
            try
            {
                //IFeatureLayer pFeatureLayer = featLayer;
                IGeoFeatureLayer     pGeoFeatureLayer     = featLayer as IGeoFeatureLayer;
                IFeatureClass        pFeatureClass        = featLayer.FeatureClass;         //获取图层上的featureClass
                IFeatureCursor       pFeatureCursor       = pFeatureClass.Search(null, false);
                IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); //唯一值渲染器
                //设置渲染字段对象
                pUniqueValueRenderer.FieldCount = 1;
                pUniqueValueRenderer.set_Field(0, fieldName);
                ISimpleFillSymbol pSimFillSymbol = new SimpleFillSymbolClass();   //创建填充符号
                pUniqueValueRenderer.DefaultSymbol    = (ISymbol)pSimFillSymbol;
                pUniqueValueRenderer.UseDefaultSymbol = false;
                int n = pFeatureClass.FeatureCount(null);
                for (int i = 0; i < n; i++)
                {
                    IFeature          pFeature          = pFeatureCursor.NextFeature();
                    IClone            pSourceClone      = pSimFillSymbol as IClone;
                    ISimpleFillSymbol pSimpleFillSymbol = pSourceClone.Clone() as ISimpleFillSymbol;
                    string            pFeatureValue     = pFeature.get_Value(pFeature.Fields.FindField(fieldName)).ToString();
                    pUniqueValueRenderer.AddValue(pFeatureValue, "", (ISymbol)pSimpleFillSymbol);
                }

                //为每个符号设置颜色

                for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++)
                {
                    string xv = pUniqueValueRenderer.get_Value(i);

                    if (xv != "")
                    {
                        ISimpleFillSymbol pNextSymbol = (ISimpleFillSymbol)pUniqueValueRenderer.get_Symbol(xv);
                        pNextSymbol.Color = colorRamp.get_Color(i * (colorRamp.Size / pUniqueValueRenderer.ValueCount));
                        pUniqueValueRenderer.set_Symbol(xv, (ISymbol)pNextSymbol);
                        if (xv.Contains("."))
                        {
                            pUniqueValueRenderer.set_Label(xv, xv.Substring(0, xv.IndexOf(".") + 4));
                        }
                        else
                        {
                            pUniqueValueRenderer.set_Label(xv, xv);
                        }
                    }
                }

                pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
                axmapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                axtoccontrol.Update();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Exemple #17
0
        /// <summary>
        /// 克隆对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pSrc"></param>
        /// <returns></returns>
        public static IClone CreateClone <T>(T pSrc) where T : class, IClone
        {
            IClone pClone = pSrc as IClone;

            if (pClone == null)
            {
                return(default(T));               //使用 default 关键字,此关键字对于引用类型会返回 null,对于数值类型会返回零。 对于结构,此关键字将返回初始化为零或 null 的每个结构成员,具体取决于这些结构是值类型还是引用类型。 对于可以为 null 的值类型,默认返回 System.Nullable<T>,它像任何结构一样初始化。
            }
            return(pClone.Clone());
        }
Exemple #18
0
        /// <summary>
        /// 根据参考注记层新建注记层
        /// </summary>
        /// <param name="targetName">创建注记图层的名称</param>
        /// <param name="pTargetWrksps">目标工作空间</param>
        /// <param name="pTargetDs">所属目标数据集</param>
        /// <param name="pRefAnnoFtCls">参考图层</param>
        /// <returns></returns>
        private static IFeatureClass CreateAnnotationClass(string targetName, IFeatureWorkspace pTargetWrksps, IFeatureDataset pTargetDs, IFeatureClass pRefAnnoFtCls, out string msg)
        {
            msg = "";
            try
            {
                IFeatureWorkspaceAnno pAnnoWrksps = pTargetWrksps as IFeatureWorkspaceAnno;
                if (pAnnoWrksps == null || pRefAnnoFtCls == null)
                {
                    return(null);
                }
                if (pRefAnnoFtCls.Extension is IAnnotationClassExtension pAnnoExten)
                {
                    IClone pClone = pAnnoExten.AnnoProperties as IClone;
                    IAnnotateLayerPropertiesCollection pAnnoProCol = (IAnnotateLayerPropertiesCollection)pClone.Clone();

                    esriUnits           eUnits    = pAnnoExten.ReferenceScaleUnits;
                    double              dbScale   = pAnnoExten.ReferenceScale;
                    IGraphicsLayerScale pGraScale = new GraphicsLayerScaleClass
                    {
                        ReferenceScale = dbScale,
                        Units          = eUnits
                    };
                    pClone = pAnnoExten.SymbolCollection as IClone;
                    ISymbolCollection pSymbolCol = (ISymbolCollection)pClone.Clone();

                    pClone = pRefAnnoFtCls.Fields as IClone;
                    IFields pFields = (IFields)pClone.Clone();

                    IObjectClassDescription pOCDesc = new AnnotationFeatureClassDescriptionClass();

                    IDataset pDs = (IDataset)pRefAnnoFtCls;
                    return(pAnnoWrksps.CreateAnnotationClass(targetName, pFields, pOCDesc.InstanceCLSID, pOCDesc.ClassExtensionCLSID, pRefAnnoFtCls.ShapeFieldName,
                                                             null, pTargetDs, null, pAnnoProCol, pGraScale, pSymbolCol, false));
                }
                return(null);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return(null);
            }
        }
Exemple #19
0
        private void deepCopyFromTextElement(ITextElement srcTextElement)
        {
            if (srcTextElement == null)
            {
                return;
            }

            IClone pSrcClone = srcTextElement as IClone;
            IClone pDstClone = pSrcClone.Clone();

            pTextElement = pDstClone as ITextElement;
        }
Exemple #20
0
        private IGeometry ProjectGeometry(IGeometry pGeo)
        {
            IClone            clone            = pGeo as IClone;
            IGeometry         geometry         = clone.Clone() as IGeometry;
            ISpatialReference spatialReference = this._hookHelper.FocusMap.SpatialReference;

            if (geometry.SpatialReference.Name != spatialReference.Name)
            {
                geometry.Project(spatialReference);
            }
            return(geometry);
        }
Exemple #21
0
        //http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/00010000028w000000.htm
        protected IGeometryDef CloneGeometryDef(IFeatureClass sourceFeatureClass)
        {
            // Find the shape field.
            int    shapeFieldIndex = sourceFeatureClass.FindField(sourceFeatureClass.ShapeFieldName);
            IField shapeField      = sourceFeatureClass.Fields.get_Field(shapeFieldIndex);

            // Get the geometry definition from the shape field and clone it.
            IGeometryDef geometryDef      = shapeField.GeometryDef;
            IClone       geometryDefClone = (IClone)geometryDef;

            return(geometryDefClone.Clone() as IGeometryDef);
        }
Exemple #22
0
        public IClone CloneMe(ref IClone OriginalClone)
        {
            IClone tempCloneMe = null;

            //
            // This function clones the input object.
            //
            tempCloneMe = null;
            if (OriginalClone != null)
            {
                tempCloneMe = OriginalClone.Clone();
            }
            return(tempCloneMe);
        }
Exemple #23
0
        /// <summary>
        /// Creates the geohash for IPoint
        /// </summary>
        /// <param name="pt">IPoint (must contain spatial reference)</param>
        /// <param name="precision">The precision.</param>
        /// <returns>geohash string</returns>
        public static string CreateGeohash(IPoint pt, int precision)
        {
            IClone source = (IClone)pt;
            IClone clone  = source.Clone();

            IPoint clonePoint = (IPoint)clone;

            ISpatialReference spatialReference = WGS84SpatialReference();

            clonePoint.Project(spatialReference);

            string geohash = Umbriel.GIS.Geohash.EncodeCoordinate(clonePoint.Y, clonePoint.X, precision);

            return(geohash);
        }
Exemple #24
0
        public IPolyline PolygonToPolyline(IPolygon pPolygon)
        {
            IGeometryCollection geometryCollection = new Polyline() as IGeometryCollection;
            IClone clone = (IClone)pPolygon;
            IGeometryCollection geometryCollection2 = (IGeometryCollection)clone.Clone();
            object missing = Type.Missing;

            for (int i = 0; i < geometryCollection2.GeometryCount; i++)
            {
                ISegmentCollection segmentCollection = new Path() as ISegmentCollection;
                segmentCollection.AddSegmentCollection((ISegmentCollection)geometryCollection2.get_Geometry(i));
                geometryCollection.AddGeometry((IGeometry)segmentCollection, ref missing, ref missing);
            }
            return(geometryCollection as IPolyline);
        }
Exemple #25
0
        public void ExportOperationFileGDBToSDE(string fileGDBPath, string sourceFCName, string targetFCName)
        {
            // Create a name object for the source (file GDB) workspace and open it.
            IWorkspaceName sourceWorkspaceName = getWorkspaceName("esriDataSourcesGDB.FileGDBWorkspaceFactory", fileGDBPath);

            IName      sourceWorkspaceIName = (IName)sourceWorkspaceName;
            IWorkspace sourceWorkspace      = (IWorkspace)sourceWorkspaceIName.Open();

            // Create a name object for the target (sde) workspace and open it.

            IWorkspaceName targetWorkspaceName = getWorkspaceName("esriDataSourcesGDB.SdeWorkspaceFactory", sdePath);

            // Create a name object for the source dataset.
            IFeatureClassName sourceFeatureClassName = getFeatureClassName(sourceWorkspaceName, sourceFCName);

            // Create a name object for the target dataset.
            IFeatureClassName targetFeatureClassName = getFeatureClassName(targetWorkspaceName, targetFCName);

            // Open source feature class to get field definitions.
            IName         sourceName         = (IName)sourceFeatureClassName;
            IFeatureClass sourceFeatureClass = (IFeatureClass)sourceName.Open();

            // Find the shape field.
            String shapeFieldName  = sourceFeatureClass.ShapeFieldName;
            int    shapeFieldIndex = sourceFeatureClass.FindField(shapeFieldName);
            IField shapeField      = sourceFeatureClass.Fields.get_Field(shapeFieldIndex);

            // Get the geometry definition from the shape field and clone it.
            IGeometryDef geometryDef            = shapeField.GeometryDef;
            IClone       geometryDefClone       = (IClone)geometryDef;
            IClone       targetGeometryDefClone = geometryDefClone.Clone();
            IGeometryDef targetGeometryDef      = (IGeometryDef)targetGeometryDefClone;

            // Cast the IGeometryDef to the IGeometryDefEdit interface.
            IGeometryDefEdit targetGeometryDefEdit = (IGeometryDefEdit)targetGeometryDef;

            // Set the IGeometryDefEdit properties.
            //targetGeometryDefEdit.GridCount_2 = 1;
            //targetGeometryDefEdit.set_GridSize(0, 0.75);

            // Create a query filter to only select features you want to convert
            IQueryFilter queryFilter = new QueryFilterClass();

            // Create the converter and run the conversion.
            IExportOperation exportOperation = new ExportOperationClass();

            exportOperation.ExportFeatureClass(sourceFeatureClassName as IDatasetName, queryFilter, null, targetGeometryDef, targetFeatureClassName, 0);
        }
        public static void createSpatialIndex(IFeatureClass fc, double gridOneSize = 0.0, double gridTwoSize = 0.0, double gridThreeSize = 0.0)
        {
            String shapeFieldName = fc.ShapeFieldName;

            // Clone the shape field from the feature class.
            int     shapeFieldIndex  = fc.FindField(shapeFieldName);
            IFields fields           = fc.Fields;
            IField  sourceField      = fields.get_Field(shapeFieldIndex);
            IClone  sourceFieldClone = (IClone)sourceField;
            IClone  targetFieldClone = sourceFieldClone.Clone();
            IField  targetField      = (IField)targetFieldClone;

            // Open the geometry definition from the cloned field and modify it.
            IGeometryDef     geometryDef     = targetField.GeometryDef;
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            if (gridTwoSize > 0.0)
            {
                geometryDefEdit.GridCount_2 = 1;
                geometryDefEdit.set_GridSize(0, gridOneSize);
            }
            if (gridTwoSize > 0.0)
            {
                geometryDefEdit.GridCount_2 = 2;
                geometryDefEdit.set_GridSize(1, gridTwoSize);
            }
            if (gridThreeSize > 0.0)
            {
                geometryDefEdit.GridCount_2 = 3;
                geometryDefEdit.set_GridSize(2, gridThreeSize);
            }

            // Create a spatial index and set the required attributes.
            IIndex     newIndex     = new IndexClass();
            IIndexEdit newIndexEdit = (IIndexEdit)newIndex;

            newIndexEdit.Name_2 = shapeFieldName + "_Indx";

            // Create a fields collection and assign it to the new index.
            IFields     newIndexFields     = new FieldsClass();
            IFieldsEdit newIndexFieldsEdit = (IFieldsEdit)newIndexFields;

            newIndexFieldsEdit.AddField(targetField);
            newIndexEdit.Fields_2 = newIndexFields;

            // Add the spatial index back into the feature class.
            fc.AddIndex(newIndex);
        }
Exemple #27
0
 IGeometry IGeometricEffect.NextGeometry()
 {
     if (m_bDone)
     {
         return(null);
     }
     else
     {
         m_pCloneGeom = (IClone)m_pGeom;
         m_pGeomCopy  = (IGeometry)m_pCloneGeom.Clone();
         m_pTransform = (ITransform2D)m_pGeomCopy;
         m_pTransform.Scale(m_pCenterPoint, m_dFactorX, m_dFactorY);
         m_bDone = true;
         return(m_pGeomCopy);
     }
 }
Exemple #28
0
 public IClone CloneObejct(IClone pCloner)
 {
     try
     {
         if (pCloner == null)
         {
             return(null);
         }
         return(pCloner.Clone());
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.SystemFun", "CloneObejct", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(null);
     }
 }
 IGeometry IGeometricEffect.NextGeometry()
 {
     if (m_bDone)
     {
         return(null);
     }
     else
     {
         m_pCloneGeom = (IClone)m_pGeom;
         m_pGeomCopy  = (IGeometry)m_pCloneGeom.Clone();
         m_pTransform = (ITransform2D)m_pGeomCopy;
         m_pTransform.Move(m_dOffsetX, m_dOffsetY);
         m_bDone = true;
         return(m_pGeomCopy);
     }
 }
Exemple #30
0
        private double GetArea(IGeometry pGeometry, IMap pMap)
        {
            IClone    pClone  = pGeometry as IClone;
            IGeometry pNewGeo = pClone.Clone() as IGeometry;
            IArea     pArea   = pNewGeo as IArea;
            double    area    = pArea.Area;

            switch (pMap.MapUnits)
            {
            case esriUnits.esriKilometers:
                area = (Math.Abs(area)) * 1000000;
                break;

            case esriUnits.esriMeters:
            case esriUnits.esriUnknownUnits:
                area = Math.Abs(area);
                break;

            case esriUnits.esriDecimalDegrees:
                ////转换如果是经纬度的地图 xisheng 20110731
                //UnitConverter punitConverter = new UnitConverterClass();
                //area = punitConverter.ConvertUnits(Math.Abs(area), esriUnits.esriMeters, esriUnits.esriDecimalDegrees);
                //上面转换方法适合长度不适合面积 修改 xisheng 20111123

                ISpatialReference pOldSpatial = pMap.SpatialReference;
                //做投影变换
                if (!(pOldSpatial is IProjectedCoordinateSystem))
                {
                    pNewGeo.SpatialReference = pOldSpatial;
                    //获得坐标系
                    ISpatialReference pNewSpatial = SysCommon.Gis.ModGisPub.GetSpatialByX((pNewGeo.Envelope.XMin + pNewGeo.Envelope.XMax) / 2);
                    if (pNewSpatial != null)
                    {
                        pNewGeo.Project(pNewSpatial);
                    }
                    IArea parea = pNewGeo as IArea;
                    area = parea.Area;
                }

                break;

            default:
                area = 0;
                break;
            }
            return(area);
        }
        IGeometry IGeometricEffect.NextGeometry()
        {
            if (m_bDone)
            {
                return null;
            }
            else
            {
                m_pCloneGeom = (IClone)m_pGeom;
                m_pGeomCopy = (IGeometry)m_pCloneGeom.Clone();
                m_pTransform = (ITransform2D)m_pGeomCopy;
                m_pTransform.Move(m_dOffsetX, m_dOffsetY);
                m_bDone = true;
                return m_pGeomCopy;
            }

        }
 public IClone CloneMe(ref IClone OriginalClone)
 {
   IClone tempCloneMe = null;
   //
   // This function clones the input object.
   //
   tempCloneMe = null;
   if (OriginalClone != null)
     tempCloneMe = OriginalClone.Clone();
   return tempCloneMe;
 }
 IGeometry IGeometricEffect.NextGeometry()
 {
     if (m_bDone)
     {
         return null;
     }
     else
     {
         m_pCloneGeom = (IClone)m_pGeom;
         m_pGeomCopy = (IGeometry)m_pCloneGeom.Clone();
         m_pTransform = (ITransform2D)m_pGeomCopy;
         m_pTransform.Scale(m_pCenterPoint, m_dFactorX, m_dFactorY);
         m_bDone = true;
         return m_pGeomCopy;                
     }
 }