DGN格式导入Arcgis

  当大家在webgis
想要把某部地块恐怕多个地块导出dwg恐怕shp文件的时候如何做?这年最棒固然用后台的格局。首先把web
gis上的graphic 的polygon提取为坐标的花样(类似于x,y x,y
x,y),假设这些图片你驾驭在某些sde库的,也得以提取它的主键属性新闻,方便在后台一贯询问,减弱坐标传输,地块极度大的很麻烦。后台首先要把坐标存到七个内存的featureclass

骨子里本来,作者正是内需把三个autocad的dwg/dgn格式的东西导入到google
earth里面;不过首先本人对dwg/dgn格式的事物根本就不熟;其次笔者获得的dwg/dgn格式文件是用的HK80
grid coordinate(Hong Kong80网格坐标连串);而google
earth中用的是WGS84全球经纬度坐标种类。于是就有了上述难点中的流程。

 1         //创建内存图层 
 2         private IFeatureClass createMemoryFeatureClass(string coord)
 3         {
 4             IField oField = new FieldClass();
 5             IFields oFields = new FieldsClass();
 6             IGeometryDef geometryDef = new GeometryDefClass();
 7 
 8             IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
 9             IWorkspaceName workspaceName = workspaceFactory.Create("", "MyWorkspace", null, 0);
10             IName name = (IName)workspaceName;
11             IWorkspace inmemWorkSpace = (IWorkspace)name.Open();
12 
13             IFieldsEdit oFieldsEdit = null;
14             IFieldEdit oFieldEdit = null;
15 
16             IFeatureLayer oFeatureLayer = null;
17             IFeatureClass outputFeatureClass = null;
18             IFeatureCursor outputFeatureCursor = null;
19             try
20             {
21 
22                 oFieldsEdit = oFields as IFieldsEdit;
23                 oFieldEdit = oField as IFieldEdit;
24 
25                 IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
26                 geometryDefEdit.AvgNumPoints_2 = 5;
27                 geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
28                 geometryDefEdit.GridCount_2 = 1;
29                 geometryDefEdit.HasM_2 = false;
30                 geometryDefEdit.HasZ_2 = false;
31 
32                 //ISpatialReferenceFactory ispfac = new SpatialReferenceEnvironmentClass();
33                 //IGeographicCoordinateSystem igeocoorsys = ispfac.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
34                 //igeocoorsys.SetDomain(76000, 180000, 0, 104000);
35                 geometryDefEdit.SpatialReference_2 = getSpatialReference();
36 
37                 oFieldEdit.Name_2 = "SHAPE";
38                 oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
39                 oFieldEdit.GeometryDef_2 = geometryDef;
40                 oFieldEdit.IsNullable_2 = true;
41                 oFieldEdit.Required_2 = true;
42                 oFieldsEdit.AddField(oField);
43 
44                 outputFeatureClass = (inmemWorkSpace as IFeatureWorkspace).CreateFeatureClass("selectedPoints", oFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
45                 outputFeatureCursor = outputFeatureClass.Insert(true);
46                 IFeatureBuffer outputFeatureBuffer = outputFeatureClass.CreateFeatureBuffer();
47 
48                 IWorkspaceEdit inmemWorkspaceEdit = inmemWorkSpace as IWorkspaceEdit;
49                 inmemWorkspaceEdit.StartEditing(false);      //Start Editing
50                 inmemWorkspaceEdit.StartEditOperation();
51                 if (coord != "")
52                 {
53                     outputFeatureBuffer.Shape = ArcGISUtil.StringToPolygon(coord);
54                     outputFeatureCursor.InsertFeature(outputFeatureBuffer);
55 
56                 }
57                 inmemWorkspaceEdit.StopEditOperation();
58                 inmemWorkspaceEdit.StopEditing(true);
59 
60                 IGeoDataset outputGeodataset = (IGeoDataset)outputFeatureClass;
61 
62 
63 
64                 oFeatureLayer = new FeatureLayerClass();
65                 oFeatureLayer.FeatureClass = outputFeatureClass;
66                 oFeatureLayer.Name = "fa";
67             }
68             catch (Exception e)
69             {
70                 System.Diagnostics.Trace.WriteLine(e.StackTrace);
71             }
72             finally
73             {
74                 ArcGISUtil.FinalReleaseComObject(outputFeatureCursor);
75                 ArcGISUtil.FinalReleaseComObject(oField);
76                 ArcGISUtil.FinalReleaseComObject(oFields);
77                 ArcGISUtil.FinalReleaseComObject(geometryDef);
78                 ArcGISUtil.FinalReleaseComObject(workspaceFactory);
79                 ArcGISUtil.FinalReleaseComObject(outputFeatureClass);
80             }
81             return oFeatureLayer.FeatureClass;
82         }

 

 
获得的内部存款和储蓄器图层,假使是要转shp,能够直接转,假诺是要转dwg,先要转为gdb,直接转dwg会失利,这两天找不到原因。

1、dwg格式导入Arcgis

 1  //要素转shp 或者gdb
 2         private void feature2GDB(IFeatureClass sourceFeatureClass, IQueryFilter pQueryFilter, string name, string type, string _fileShortName)
 3         {
 4             try
 5             {
 6                 string fileShortName = string.Empty;
 7                 if (type == "gdb")
 8                 {
 9                     fileShortName = _fileShortName;                  
10                    
11                 }
12                 else
13                 {
14                     fileShortName = name;
15                 }
16 
17                 string parentDirectory = HttpContext.Current.Server.MapPath(@"\Checkservices\gdbpath\");
18 
19                 IFeatureClassName sourceFeatureClassName = new FeatureClassNameClass();
20                 IDataset pOutDataset = (IDataset)sourceFeatureClass;
21                 sourceFeatureClassName = (IFeatureClassName)pOutDataset.FullName;
22 
23                 IWorkspaceFactory wsf = null;
24                 if (type == "gdb")
25                 {
26                     wsf = new FileGDBWorkspaceFactoryClass();
27                 }
28                 else if (type == "shp")
29                 {
30                     wsf = new ShapefileWorkspaceFactoryClass();
31                 }
32 
33                 IWorkspaceName pInWorkspaceName = new WorkspaceNameClass();
34                 pInWorkspaceName = wsf.Create(parentDirectory, name, null, 0);
35 
36                 IFeatureClassName pInFeatureClassName = new FeatureClassNameClass();
37                 IDatasetName pInDatasetClassName;
38                 pInDatasetClassName = (IDatasetName)pInFeatureClassName;
39                 pInDatasetClassName.Name = fileShortName;
40                 pInDatasetClassName.WorkspaceName = pInWorkspaceName;
41 
42                 long iCounter;
43                 IFields pOutFields, pInFields;
44                 IField pGeoField;
45                 IEnumFieldError pEnumFieldError = null;
46                 pInFields = sourceFeatureClass.Fields;
47                 IFieldChecker pFieldChecker = new FieldChecker();
48                 //pFieldChecker.InputWorkspace = pOutDataset.Workspace;
49 
50                 pFieldChecker.Validate(pInFields, out pEnumFieldError, out pOutFields);
51                 pGeoField = null;
52                 for (iCounter = 0; iCounter < pOutFields.FieldCount; iCounter++)
53                 {
54                     if (pOutFields.get_Field((int)iCounter).Type == esriFieldType.esriFieldTypeGeometry)
55                     {
56                         pGeoField = pOutFields.get_Field((int)iCounter);
57                         break;
58                     }
59                 }
60 
61                 IGeometryDef pOutGeometryDef;
62                 IGeometryDefEdit pOutGeometryDefEdit;
63                 pOutGeometryDef = pGeoField.GeometryDef;
64                 pOutGeometryDefEdit = (IGeometryDefEdit)pOutGeometryDef;
65 
66                 IFeatureDataConverter pShpToClsConverter = new FeatureDataConverterClass();
67                 pShpToClsConverter.ConvertFeatureClass(sourceFeatureClassName, pQueryFilter,
68                     null, pInFeatureClassName, pOutGeometryDef, pOutFields, "", 1000, 0);
69 
70                 ArcGISUtil.FinalReleaseComObject(wsf);
71                 ArcGISUtil.FinalReleaseComObject(pInWorkspaceName);
72                 ArcGISUtil.FinalReleaseComObject(pInFeatureClassName);
73                 ArcGISUtil.FinalReleaseComObject(pFieldChecker);
74                 ArcGISUtil.FinalReleaseComObject(pShpToClsConverter);
75             }
76             catch (Exception e)
77             {
78                 System.Diagnostics.Trace.WriteLine(e.StackTrace);
79             }
80         }
81 
82         private IFeatureClass openFeatureClass(String layerName, String sde)
83         {
84             IFeatureClass fc = null;
85             try
86             {
87                 fc = SdeConnectManager.getFeatureClass(layerName, sde);
88             }
89             catch
90             {
91                 return null;
92             }
93             return fc;
94         }

实际本来啊,作者是想把dwg/dgn格式存成图片格式(tiff)的,然后用envi只怕erdas在google
earth上开展贰个几何校勘的……后来恰恰被路过的助教看见了,于是伊粗暴地鄙视了自小编如故不用Arcgis的弱智的主张,行吗,固然笔者不是学GIS的,但此次看似真的用Arcgis方便一些……越发是本身操作的dwg文件是八个矢量数据,并不是栅格数据

  要转dwg能够一向调用AO接口

 

 1         private void gdb2Cad(string gdbfilePath, string cadfilePath, int num = 0)
 2         {
 3             Geoprocessor gp = new Geoprocessor();
 4             try
 5             {              
 6                 ExportCAD tool = new ExportCAD();
 7                 tool.in_features = gdbfilePath;
 8                 tool.Output_File = cadfilePath;
 9                 tool.Output_Type = "DWG_R2004";
10                 gp.Execute(tool, null);
11             }
12             catch (Exception e)
13             {
14                 System.Diagnostics.Trace.WriteLine(e.StackTrace);
15                 System.Diagnostics.Trace.Write("dwg");
16             }
17         }

于是在本身的系统上装了arcgis9.3,进程按下不表……

 
但是如果导出dwg图形有注记的话,AO那些法子就不行了,貌似arcgis对导出dwg图形带声明补助的不得了,前边会有极度的稿子讲怎么导出带有注记的dwg。

 

 

下一场开掘其实dwg/dgn格式能够在arcgis中一贯展开,根本没有须要中间转播。真是太土了我。还跑去装什么样autocad什么的。

要时刻铭记咱是学地理的,要正式!

 

想要浏览dwg/dgn文件,直接打开arcmap,点击‘Add
Data’,把dwg/dgn格式的文本拖进去就好。Arcgis会自动根据原先的dwg/dgn文件中的要素类型将其分为点、线、面、注释等门类,展现出来。也足以双击该dwg/dgn文件,只浏览当中的某三个因素。

 

如图所示:

图片 1

倘若留意看侧边的图层栏,能够看出导入的dwg文件已经被依照矢量的性质分为注释、点、线、面等结构。当然你也能够只开拓其中的三个属性值。

何况请小心右下角的坐标值,这里用的是HK80 Grid
Coordinate,数值是确实无疑的,但是显著在arcgis中是尚未影子的音讯的,这一个大家姑且要增加。

 

2、dwg/dgn格式转化为shp

倒车成shp文件只是为了一会儿开展地理坐标转变的时候方便。第一,好像dwg不能调换地理坐标参照系,恐怕反正很辛劳,至少自个儿未能如愿;再其次,都开采arcgis了,当然要用arcgis自个儿的数码格式操作才方便快速嘛。

 

改造的历程如下:

图片 2

 右击你要转化的图层->Data->Export Data就可以了。

 

3、转变地理坐标

那些历程包罗五个部分。第二个是丰裕地理坐标;第四个是地理坐标的转化。

 

增添地理坐标的进度如下:

对于本身这么的,已经有了地理坐标的数字,只是增添坐标的新闻而已。即使连那几个都未曾,就要团结地理编码了。

重复开窗口->导入你刚好获得的Shp文件->右击你的Shp图像体现框->Data
Frame Properties
;

出去新的对话框,选取Coordinate System选项卡。

图片 3

 直接选用你的地理坐标系统,点击应用,明确。

 

回到主分界面,那时候的地理音信已经有了坐标的单位了。

图片 4

 

 

中间转播地理坐标的历程如下:

实在相当粗略,展开Arctoolbox,正是上边一排工具栏里的那几个Logo图片 5,然后Data
Management Tools->Projections and
Transformations->Feature->Project.

 

参数采取如下:

图片 6

 

因为笔者是要转移到谷歌 Earth里面,所以自然选用的是GE的参照系:WGS84. 

然后点击Okay, 就获取了最终的结果。

 

重新张开新的转移获得的shp文件,结果如下:

图片 7

 能够明确看出,最终的结果已经是在经纬度坐标里面展现了。

 

4、导入Google Earth

末段一步很简短,一样点击ArcToolbox->Conversion Tools->To
KML->Layer to KML.

图片 8

 选取好参数后,点击OKAY就能够,就能够获得最后的KML文件了。

 

关闭Arcgis,张开google
earth,导入刚才获得的文本,就能够把那些矢量文件在谷歌 Earth上出示了。

图片 9

 

本条图上只怕看不老聃;不过细心相比较转变过坐标的dwg格式的文件的边缘,和GoogleEarth新加坡岸线的边缘部分,依旧重合地很好的。那就印证更动的坐标的历程是大功告成的。