Exemple #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);
            }
        }
Exemple #2
0
 public static IFeatureLayer GetJZDLayer()
 {
     return(ArcGisUtils.GetFeatureLayer2(JZDLayer));
 }