Example #1
0
        public void ExcelToShp(string path)
        {
            if (Utils.CheckFileExists(path))
            {
                string zjdShpTemplte = System.AppDomain.CurrentDomain.BaseDirectory + "ArcGisTemplete\\宅基地模板shp";
                string saveDir       = path.Substring(0, path.LastIndexOf(".")) + "SHP";
                FileUtils.CopyDir(zjdShpTemplte, saveDir, true);
                while (axMapControl.LayerCount > 0)
                {
                    axMapControl.DeleteLayer(0);
                }
                axMapControl.AddShapeFile(saveDir, "ZJD.shp");

                IFeatureLayer  featureLayer  = ArcGisUtils.GetFeatureLayer2("ZJD");
                IFeatureClass  featureClass  = featureLayer.FeatureClass;
                IWorkspaceEdit workspaceEdit = ArcGisUtils.StratEdit(featureClass);

                IFeatureCursor featureCursor = featureClass.Insert(false);
                IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
                ISheet         sheet         = ExcelManager.ExcelRead.ReadExcelSheet(path, 0);

                foreach (NPOI.SS.UserModel.IRow row in sheet)
                {
                    IPointCollection pc         = new Polygon();
                    string[]         pcStrArray = row.GetCell(2).StringCellValue.Split(',');
                    foreach (string ptStr in pcStrArray)
                    {
                        string[] ptArray = ptStr.Split(':');
                        IPoint   point   = new PointClass();
                        point.PutCoords(double.Parse(ptArray[0]), double.Parse(ptArray[1]));
                        pc.AddPoint(point);
                    }
                    IPolygon polygon = ArcGisUtils.CreatePolygon(pc);
                    featureBuffer.Shape    = polygon;
                    featureBuffer.Value[3] = row.GetCell(0).StringCellValue;
                    featureBuffer.Value[4] = row.GetCell(1).StringCellValue;
                    featureCursor.InsertFeature(featureBuffer);
                }

                //IList<IFeature> list = ArcGisUtils.GetEntitysList("", "ZJD");
                ArcGisDao.EndEdit(workspaceEdit);
            }
        }
Example #2
0
        /// <summary>
        /// 得到图幅号
        /// </summary>
        /// <param name="ev"></param>
        /// <returns></returns>
        public static void CreateTuFuFeautre(IEnvelope ev, IFeatureClass featureClass)
        {
            IPoint pt1 = ev.UpperLeft;

            if (pt1.IsEmpty)
            {
                return;
            }
            IPoint         pt2  = ev.UpperRight;
            IPoint         pt4  = ev.LowerRight;
            IList <string> list = new List <string>();
            double         y1   = pt1.Y;
            double         y4   = pt4.Y;

            IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
            IFeatureCursor cursor        = featureClass.Insert(true);
            int            index         = cursor.FindField("TuFu");

            while (y1 > y4)
            {
                double x1 = pt1.X;
                double x2 = pt2.X;
                while (x1 < x2)
                {
                    string tufu = GetTuFu(x1, y1);
                    list.Add(tufu);
                    IPointCollection pc      = GeTuPointCollection(x1, y1);
                    IPolygon         polygon = ArcGisUtils.CreatePolygon(pc);

                    featureBuffer.Shape = polygon;
                    featureBuffer.set_Value(3, tufu);
                    cursor.InsertFeature(featureBuffer);

                    x1 += 500;
                }
                y1 -= 500;
            }
        }