当我们在webgis 想要把某个地块或者多个地块导出dwg或者shp文件的时候怎么办?这个时候最好就是用后台的方式。首先把web gis上的graphic 的polygon提取为坐标的形式(类似于x,y x,y x,y),如果这个图形你知道在某个sde库的,也可以提取它的主键属性信息,方便在后台直接查询,减少坐标传输,地块特别大的很麻烦。后台首先要把坐标存到一个内存的featureclass

         //创建内存图层
private IFeatureClass createMemoryFeatureClass(string coord)
{
IField oField = new FieldClass();
IFields oFields = new FieldsClass();
IGeometryDef geometryDef = new GeometryDefClass(); IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
IWorkspaceName workspaceName = workspaceFactory.Create("", "MyWorkspace", null, );
IName name = (IName)workspaceName;
IWorkspace inmemWorkSpace = (IWorkspace)name.Open(); IFieldsEdit oFieldsEdit = null;
IFieldEdit oFieldEdit = null; IFeatureLayer oFeatureLayer = null;
IFeatureClass outputFeatureClass = null;
IFeatureCursor outputFeatureCursor = null;
try
{ oFieldsEdit = oFields as IFieldsEdit;
oFieldEdit = oField as IFieldEdit; IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
geometryDefEdit.AvgNumPoints_2 = ;
geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
geometryDefEdit.GridCount_2 = ;
geometryDefEdit.HasM_2 = false;
geometryDefEdit.HasZ_2 = false; //ISpatialReferenceFactory ispfac = new SpatialReferenceEnvironmentClass();
//IGeographicCoordinateSystem igeocoorsys = ispfac.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
//igeocoorsys.SetDomain(76000, 180000, 0, 104000);
geometryDefEdit.SpatialReference_2 = getSpatialReference(); oFieldEdit.Name_2 = "SHAPE";
oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
oFieldEdit.GeometryDef_2 = geometryDef;
oFieldEdit.IsNullable_2 = true;
oFieldEdit.Required_2 = true;
oFieldsEdit.AddField(oField); outputFeatureClass = (inmemWorkSpace as IFeatureWorkspace).CreateFeatureClass("selectedPoints", oFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
outputFeatureCursor = outputFeatureClass.Insert(true);
IFeatureBuffer outputFeatureBuffer = outputFeatureClass.CreateFeatureBuffer(); IWorkspaceEdit inmemWorkspaceEdit = inmemWorkSpace as IWorkspaceEdit;
inmemWorkspaceEdit.StartEditing(false); //Start Editing
inmemWorkspaceEdit.StartEditOperation();
if (coord != "")
{
outputFeatureBuffer.Shape = ArcGISUtil.StringToPolygon(coord);
outputFeatureCursor.InsertFeature(outputFeatureBuffer); }
inmemWorkspaceEdit.StopEditOperation();
inmemWorkspaceEdit.StopEditing(true); IGeoDataset outputGeodataset = (IGeoDataset)outputFeatureClass; oFeatureLayer = new FeatureLayerClass();
oFeatureLayer.FeatureClass = outputFeatureClass;
oFeatureLayer.Name = "fa";
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(e.StackTrace);
}
finally
{
ArcGISUtil.FinalReleaseComObject(outputFeatureCursor);
ArcGISUtil.FinalReleaseComObject(oField);
ArcGISUtil.FinalReleaseComObject(oFields);
ArcGISUtil.FinalReleaseComObject(geometryDef);
ArcGISUtil.FinalReleaseComObject(workspaceFactory);
ArcGISUtil.FinalReleaseComObject(outputFeatureClass);
}
return oFeatureLayer.FeatureClass;
}

得到的内存图层,如果是要转shp,可以直接转,如果是要转dwg,先要转为gdb,直接转dwg会失败,目前找不到原因。

  //要素转shp 或者gdb
private void feature2GDB(IFeatureClass sourceFeatureClass, IQueryFilter pQueryFilter, string name, string type, string _fileShortName)
{
try
{
string fileShortName = string.Empty;
if (type == "gdb")
{
fileShortName = _fileShortName; }
else
{
fileShortName = name;
} string parentDirectory = HttpContext.Current.Server.MapPath(@"\Checkservices\gdbpath\"); IFeatureClassName sourceFeatureClassName = new FeatureClassNameClass();
IDataset pOutDataset = (IDataset)sourceFeatureClass;
sourceFeatureClassName = (IFeatureClassName)pOutDataset.FullName; IWorkspaceFactory wsf = null;
if (type == "gdb")
{
wsf = new FileGDBWorkspaceFactoryClass();
}
else if (type == "shp")
{
wsf = new ShapefileWorkspaceFactoryClass();
} IWorkspaceName pInWorkspaceName = new WorkspaceNameClass();
pInWorkspaceName = wsf.Create(parentDirectory, name, null, ); IFeatureClassName pInFeatureClassName = new FeatureClassNameClass();
IDatasetName pInDatasetClassName;
pInDatasetClassName = (IDatasetName)pInFeatureClassName;
pInDatasetClassName.Name = fileShortName;
pInDatasetClassName.WorkspaceName = pInWorkspaceName; long iCounter;
IFields pOutFields, pInFields;
IField pGeoField;
IEnumFieldError pEnumFieldError = null;
pInFields = sourceFeatureClass.Fields;
IFieldChecker pFieldChecker = new FieldChecker();
//pFieldChecker.InputWorkspace = pOutDataset.Workspace; pFieldChecker.Validate(pInFields, out pEnumFieldError, out pOutFields);
pGeoField = null;
for (iCounter = ; iCounter < pOutFields.FieldCount; iCounter++)
{
if (pOutFields.get_Field((int)iCounter).Type == esriFieldType.esriFieldTypeGeometry)
{
pGeoField = pOutFields.get_Field((int)iCounter);
break;
}
} IGeometryDef pOutGeometryDef;
IGeometryDefEdit pOutGeometryDefEdit;
pOutGeometryDef = pGeoField.GeometryDef;
pOutGeometryDefEdit = (IGeometryDefEdit)pOutGeometryDef; IFeatureDataConverter pShpToClsConverter = new FeatureDataConverterClass();
pShpToClsConverter.ConvertFeatureClass(sourceFeatureClassName, pQueryFilter,
null, pInFeatureClassName, pOutGeometryDef, pOutFields, "", , ); ArcGISUtil.FinalReleaseComObject(wsf);
ArcGISUtil.FinalReleaseComObject(pInWorkspaceName);
ArcGISUtil.FinalReleaseComObject(pInFeatureClassName);
ArcGISUtil.FinalReleaseComObject(pFieldChecker);
ArcGISUtil.FinalReleaseComObject(pShpToClsConverter);
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(e.StackTrace);
}
} private IFeatureClass openFeatureClass(String layerName, String sde)
{
IFeatureClass fc = null;
try
{
fc = SdeConnectManager.getFeatureClass(layerName, sde);
}
catch
{
return null;
}
return fc;
}

要转dwg可以直接调用AO接口

         private void gdb2Cad(string gdbfilePath, string cadfilePath, int num = )
{
Geoprocessor gp = new Geoprocessor();
try
{
ExportCAD tool = new ExportCAD();
tool.in_features = gdbfilePath;
tool.Output_File = cadfilePath;
tool.Output_Type = "DWG_R2004";
gp.Execute(tool, null);
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(e.StackTrace);
System.Diagnostics.Trace.Write("dwg");
}
}

但是如果导出dwg图形有注记的话,AO这个方法就行不通了,貌似arcgis对导出dwg图形带标注支持的不好,后面会有专门的文章讲怎么导出带有注记的dwg。

gis 导出 dwg,shp的更多相关文章

  1. shp文件转dwg并创建文本标注

    不得不说,ArcGIS 和 CAD 之间的兼容性非常差,shapefile文件和dwg文件之间互相转换会丢失各种属性,但是很多时候他们之间的转换对我们来说是刚需.通常我们都是通过第三方软件(如FME) ...

  2. AutoCAD批量导出点坐标

    需求背景: 需要批量导出DWG文件中的散点树的位置信息,以Excel文件格式存储. 实现方法: 在AutoCAD2012打开dwg文件,点击“插入”选项卡中的“提取数据”工具(或输入DATAEXTRA ...

  3. ArcMAP中Excel数据转换为shp数据

    参考百度知道:http://jingyan.baidu.com/article/f7ff0bfc1cf22c2e26bb138d.html 将数据库中带有X.Y坐标的二维表转换为空间点数据:从数据中将 ...

  4. NX二次开发-NXOPEN工程图导出CAD图纸DxfdwgCreator *dxfdwgCreator1;

    没有什么可以看的,NXOPEN直接录制一下导出CAD就可以了.录制出来自己挑需要的代码拿过来改一下. NX9+VS2012 #include <NXOpen/Part.hxx> #incl ...

  5. Tilemill + tilestream + mapbox.js 自制地图

    感谢Mapbox,带来了一整套完整的地图方案. 你可以把你的地图放在Mapbox的网站上.也可以使用他们提供的开源软件自己架设地图服务. Mapbox的地图方案包括web,ios和android. 不 ...

  6. 室内地图1:从CAD到Map(画图,发布,路径导航)

    首先这个教程整理,比较偏细节. 因为我本身不是做GIS,所以可能有点流水账,当然错漏难免,恳请指正. 当我们做定位的时候,想要可视化展示,室外当然可以直接使用google,百度的底图.对于室内,有两种 ...

  7. PostGIS 快速入门(转)

    原文:http://live.osgeo.org/zh/quickstart/postgis_quickstart.html PostGIS 是 PostgreSQL 关系数据库的空间操作扩展.它为 ...

  8. 外业数据采集平台(GPS+Android Studio+Arcgis for android 100.2.1)

    外业数据采集平台 1. 综述 在室外,通过平板或者手机接收GPS坐标,实时绘制点.线.面数据,以便为后续进行海域监测.土地确权.地图绘图提供有效数据和依据. 2. 技术路线 Android studi ...

  9. ArcGIS数据生产与精细化制图之中国年降水量分布图的制作

    原文:ArcGIS数据生产与精细化制图之中国年降水量分布图的制作 楼主按:在今年的Esri中国用户大会上,我听了几场关于ArcGIS用于制图方面的讲座,也在体验区与Esri中国的技术老师有一些交流.一 ...

随机推荐

  1. SPOJ #692. Fruit Farm

    Another palindrome related problem. Actually nothing too theoretical here, but please keep following ...

  2. SQLite介绍、学习笔记、性能测试

    SQLite介绍.学习笔记.性能测试 哪些人,哪些公司或软件在用SQLite: Nokia's Symbian,Mozilla,Abobe,Google,阿里旺旺,飞信,Chrome,FireFox可 ...

  3. 查看CentOS版本方法

    查看内核版本 这个命令适用于所有的linux,包括Redhat.SuSE.Debian.Centos等发行版. root@MyMail ~ # uname Linux root@MyMail ~ # ...

  4. (C#) System.BadImageFormatException: An attempt was made to load a program with an incorrect format.

    ASP.NET: System.BadImageFormatException: An attempt was made to load a program with an incorrect for ...

  5. (C# ) 解析XML。

    解析XML有很多方法,之前用专门写的XMLProcess 或XMLHelper 解析类.其实有个较简单的解析就是用Linq查询. 例如有如下XML <?xml version="1.0 ...

  6. SecureCRT控制台显示中文字符的设置

  7. 由csdn开源项目评选中闹出刷票问题想到投票程序的设计

    帖子<#CSDN刷票门# 有没有人在恶意刷票?CSDN请告诉我!用24小时监控数据说话!> http://www.cnblogs.com/sanshi/p/3155946.html 网站投 ...

  8. Web上传文件

      客户端      相对于FTP文件上传,Web文件上传速度慢一些,但使用方便,不需要客户端,而且权限比FTP容易控制. Web文件上传采用POST方式,上传文件需要设置FORM的entype属性为 ...

  9. XML封装与验证消息

    Document document = DocumentHelper.createDocument(); document.setXMLEncoding(ChARSET_UTF_8); Element ...

  10. Workflow_如何处理标准异常和自定义异常(案例)

    2014-05-31 Created By BaoXinjian