예제 #1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            //从点图层中读取所有点
            pointSE pPointse = new pointSE();

            pPointse = ReadPoint();
            IPointCollection PointCollection = pPointse.pPointCollection;
            List <double>    sunv            = new List <double>();
            List <double>    earv            = new List <double>();

            sunv = pPointse.sunvec;
            earv = pPointse.earvec;
            //创建shp文件
            creatshpfile();
            //根据点生成线
            for (int i = 0; i < PointCollection.PointCount; i++)
            {
                IPolyline PolySunline = CreateSunPolyline(PointCollection.Point[i], sunv[i]);

                IPolyline PolyEarline = CreateSunPolyline(PointCollection.Point[i], earv[i]);

                AddFeatureVector(PolySunline as IGeometry, "VecValue", sunv[i], "Type", "太阳矢量");
                AddFeatureVector(PolyEarline as IGeometry, "VecValue", earv[i], "Type", "地球矢量");
            }
            this.Close();
        }
예제 #2
0
        //从点图层中收集所有点
        private pointSE ReadPoint()
        {
            string pPointFileName = cmbPointLayer.SelectedItem.ToString();
            ILayer pLayer         = null;

            for (int i = 0; i < m_mapControl.LayerCount; i++)
            {
                if (pPointFileName == m_mapControl.get_Layer(i).Name)
                {
                    pLayer = m_mapControl.get_Layer(i);
                    break;
                }
            }

            int           sunindex  = 0;
            int           earindex  = 0;
            List <double> sunvect   = new List <double>();
            List <double> earvect   = new List <double>();
            ITable        pTable    = pLayer as ITable;
            IFields       pPPfields = pTable.Fields;

            for (int i = 0; i < pPPfields.FieldCount; i++)
            {
                if (pPPfields.Field[i].Name == cmbSunField.Text)
                {
                    sunindex = i;
                }
                if (pPPfields.Field[i].Name == cmbEarthField.Text)
                {
                    earindex = i;
                }
            }


            psf = ((IGeoDataset)pLayer).SpatialReference;
            IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
            //IFeatureCursor pFeatureCursor = pFeatureLayer.Search(null, false);

            //获取数据库或者单个文件的第一个属性字段
            //IFeature pFeature = null;
            //IFeature pFeature=pFeatureCursor.NextFeature();
            //IField pField = null;
            //if (pFeatureLayer.FeatureClass.Fields.FindField("FID") != -1)
            //{
            //    pField = pFeatureLayer.FeatureClass.Fields.get_Field(pFeatureLayer.FeatureClass.Fields.FindField("FID"));
            //}
            //else if (pFeatureLayer.FeatureClass.Fields.FindField("OBJECTID") != -1)
            //{
            //    pField = pFeatureLayer.FeatureClass.Fields.get_Field(pFeatureLayer.FeatureClass.Fields.FindField("OBJECTID"));
            //}

            //第一个属性字段名称
            IFeatureClass    pFC              = pFeatureLayer.FeatureClass;
            IFeatureCursor   pFCursor         = pFC.Search(null, false);
            IFeature         pF               = pFCursor.NextFeature();
            IPointCollection pPointCollection = new MultipointClass();

            while (pF != null)
            {
                IGeometry pGeometry = pF.Shape as IGeometry;
                IPoint    pPoint    = pGeometry as IPoint;



                if (pF.get_Value(sunindex).GetType().FullName != "System.DBNull" &&
                    pF.get_Value(earindex).GetType().FullName != "System.DBNull")
                {
                    sunvect.Add(Convert.ToDouble(pF.get_Value(sunindex)));
                    earvect.Add(Convert.ToDouble(pF.get_Value(earindex)));
                    pPointCollection.AddPoint(pPoint);
                }

                pF = pFCursor.NextFeature();
            }

            //string FirstFieldName = pField.AliasName;
            //IQueryFilter pQueryFilter = new QueryFilterClass();
            //pQueryFilter.WhereClause = FirstFieldName + ">=0";
            //int number = pFeatureLayer.FeatureClass.FeatureCount(pQueryFilter);

            //IPointCollection pPointCollection = new MultipointClass();
            //for (int i = 0; i < number; i++)
            //{
            //    IGeometry pGeometry = pFeature.Shape as IGeometry;
            //    IPoint pPoint = pGeometry as IPoint;

            //    pPointCollection.AddPoint(pPoint);

            //    pFeature = pFeatureCursor.NextFeature();
            //    sunvect.Add(Convert.ToDouble(pFeature.get_Value(sunindex)));
            //    earvect.Add(Convert.ToDouble(pFeature.get_Value(earindex)));
            //}

            pointSE pPointSE = new pointSE();

            pPointSE.pPointCollection = pPointCollection;
            pPointSE.sunvec           = sunvect;
            pPointSE.earvec           = earvect;

            return(pPointSE);
        }