当我们在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. mysql的主从配置以及主主配置

    基础环境 系统:linuxmysql版本:5.5主服务器IP:192.168.1.101从服务器IP:192.168.1.102 1.主服务器(master)要打开二进制日志2.从服务器(slave) ...

  2. CentOS 7.0 安装中文输入法

    这是个蛋疼的问题 1.Applications -- System Tools -- Setting -- Regin & Language 2.input source -- + -- mo ...

  3. gcc链接参数--whole-archive的作用

    // a.h extern void foo(); // a.cpp #include <stdio.h> void foo() { printf("foo\n"); ...

  4. Linux常见设备及相应/dev/xxx文件名、Mount Point、挂载点、Mount命令、fstab、挂载分区

    Linux 中的设备有2种类型:字符设备(无缓冲且只能顺序存取).块设备(有缓冲且可以随机存取).这些设备中,有些设备是对实际存在的物理硬件的抽象,而有些设备则是内核自身提供的功能(不依赖于特定的物理 ...

  5. 静态HTML页面不缓存js文件的方法

    今天做项目时候遇到一个问题,由于采用了生成静态的CMS系统,但是页面头部需要显示用户登录的信息,也就是,没有登录时,显示登录框,用户登录后,则显 示登录信息.于是用到了js调用php文件的方法.但是由 ...

  6. jQurey基础简介

    随着WEB2.0及ajax思想在互联网上的快速发展传播,陆续出现了一些优秀的Js框架,其中比较著名的有Prototype.YUI.jQuery. mootools.Bindows以及国内的JSVM框架 ...

  7. MySql语句大全:创建、授权、查询、修改等

    林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 一.用户创建.权限.删除 1.连接MySQL操作 连接:mysql -h 主机地址 -u 用户 ...

  8. CMake使用教程

    转自 RichardXG 原文 CMake使用教程 CMake是一个比make更高级的编译配置工具,它可以根据不同平台.不同的编译器,生成相应的Makefile或者vcproj项目. 通过编写CMak ...

  9. webview--网络超时

    package com.test.js2java; import java.util.Timer; import java.util.TimerTask; import android.app.Act ...

  10. db2删除数据库

    1.断开所有连接  db2 stop application all   force 2.停止数据库    db2stop 3.删除数据库(系统管理员权限下)db2 drop  数据库name