当我们在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. WIN 8.1 x64 环境下 COM Surrogate 停止工作解决方案

    我的笔记本电脑是THINKPAD T420 4180AT8,NVIDIA NVS 4200M,Intel(R) HD Graphics 3000,WIN 8.1 x64操作系统.在安装完NVIDIA独 ...

  2. Redis作者谈Redis应用场景(转)

    毫无疑问,Redis开创了一种新的数据存储思路,使用Redis,我们不用在面对功能单调的数据库时,把精力放在如何把大象放进冰箱这样的问题上,而是利用Redis灵活多变的数据结构和数据操作,为不同的大象 ...

  3. [UEditor]百度编辑器配置总结

    前端配置文件ueditor.config.js 前端有两个重要的配置属性: UEDITOR_HOME_URL: 配置百度编辑器的资源目录路径,你可以手动指定此路径,默认是有URL变量指定,而URL变量 ...

  4. PLSQL_PLSQL Hint用法总结(概念)

    2014-06-20 Created By BaoXinjian

  5. PLSQL_性能优化工具系列09_SQL Plan Management

    2014-09-24 Created By BaoXinjian

  6. ZOJ 4257 MostPowerful(状压DP,简单)

    题目大意:不超过10种气体,两两之间相互碰撞可以产生一定的能量,如a碰b,那么b气体就消失,自身不能碰自身,问最后所能得到的最大能量. 原代码链接:http://blog.csdn.net/accry ...

  7. js复习(一)

    一.常用数据框1.alert(""):警告对话框,作用是弹出一个警告对话框 2.confirm(""):确定对话框,弹出一个带确定和取消按钮的对话框--确定返回 ...

  8. 更改EGit的user settings中默认的location

    在系统的环境变量中添加变量HOME,值为C:\Users\Kane.Sun\ 记得要讲users改为首字母大写,不然可能会有问题.

  9. heredoc和nowdoc的区别

    heredoc使用 <<< EOT 的标示符,而nowdoc使用 <<< 'EOT' 这样的标示符,其中nowdoc是PHP5.3引进的新技术,它包含了heredo ...

  10. Java多线程之线程中断

    该例子说明,Sleep可以被中断,但是I/O和synchronized不能被中断. package Thread.Interrupting; import java.io.IOException; i ...