gis 导出 dwg,shp
当我们在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的更多相关文章
- shp文件转dwg并创建文本标注
不得不说,ArcGIS 和 CAD 之间的兼容性非常差,shapefile文件和dwg文件之间互相转换会丢失各种属性,但是很多时候他们之间的转换对我们来说是刚需.通常我们都是通过第三方软件(如FME) ...
- AutoCAD批量导出点坐标
需求背景: 需要批量导出DWG文件中的散点树的位置信息,以Excel文件格式存储. 实现方法: 在AutoCAD2012打开dwg文件,点击“插入”选项卡中的“提取数据”工具(或输入DATAEXTRA ...
- ArcMAP中Excel数据转换为shp数据
参考百度知道:http://jingyan.baidu.com/article/f7ff0bfc1cf22c2e26bb138d.html 将数据库中带有X.Y坐标的二维表转换为空间点数据:从数据中将 ...
- NX二次开发-NXOPEN工程图导出CAD图纸DxfdwgCreator *dxfdwgCreator1;
没有什么可以看的,NXOPEN直接录制一下导出CAD就可以了.录制出来自己挑需要的代码拿过来改一下. NX9+VS2012 #include <NXOpen/Part.hxx> #incl ...
- Tilemill + tilestream + mapbox.js 自制地图
感谢Mapbox,带来了一整套完整的地图方案. 你可以把你的地图放在Mapbox的网站上.也可以使用他们提供的开源软件自己架设地图服务. Mapbox的地图方案包括web,ios和android. 不 ...
- 室内地图1:从CAD到Map(画图,发布,路径导航)
首先这个教程整理,比较偏细节. 因为我本身不是做GIS,所以可能有点流水账,当然错漏难免,恳请指正. 当我们做定位的时候,想要可视化展示,室外当然可以直接使用google,百度的底图.对于室内,有两种 ...
- PostGIS 快速入门(转)
原文:http://live.osgeo.org/zh/quickstart/postgis_quickstart.html PostGIS 是 PostgreSQL 关系数据库的空间操作扩展.它为 ...
- 外业数据采集平台(GPS+Android Studio+Arcgis for android 100.2.1)
外业数据采集平台 1. 综述 在室外,通过平板或者手机接收GPS坐标,实时绘制点.线.面数据,以便为后续进行海域监测.土地确权.地图绘图提供有效数据和依据. 2. 技术路线 Android studi ...
- ArcGIS数据生产与精细化制图之中国年降水量分布图的制作
原文:ArcGIS数据生产与精细化制图之中国年降水量分布图的制作 楼主按:在今年的Esri中国用户大会上,我听了几场关于ArcGIS用于制图方面的讲座,也在体验区与Esri中国的技术老师有一些交流.一 ...
随机推荐
- 8张图带你深入理解Java
1.字符串的不变性 下图展示了如下的代码运行过程: String s = "abcd";s = s.concat("ef"); 备注:String refe ...
- android如何播放资源文件夹raw中的视频
转自这里 videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/&qu ...
- AngularJS PhoneCat代码分析
转载自:http://www.tuicool.com/articles/ym6Jfen AngularJS 官方网站提供了一个用于学习的示例项目:PhoneCat.这是一个Web应用,用户可以浏览一些 ...
- 使用 as 和 is 运算符安全地进行强制转换
由于对象是多态的,因此基类类型的变量可以保存派生类型. 若要访问派生类型的方法,需要将值强制转换回该派生类型. 不过,在这些情况下,如果只尝试进行简单的强制转换,会导致引发 InvalidCastEx ...
- 黄聪:C#设置窗体打开位置(在显示器的右下角打开)
; ; this.SetDesktopLocation(x, y); 注释:System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size.Wid ...
- Codeforces Round #367 (Div. 2) Hard problem
Hard problem 题意: 有n个字符串,对第i个字符串进行反转操作代价为ci. 要使n个字符串按照字典序从小到大排列,最小的代价是多少. 题解: 反转就是reverse操作,比如说45873反 ...
- 深入研究java.lang.ThreadLocal类(转)
引用:http://lavasoft.blog.51cto.com/62575/51926/ 一.概述 ThreadLocal是什么呢?其实ThreadLocal并非是一个线程的本地实现版本,它并 ...
- java静态代理
WorkIF.java package com.wzh.test; public interface WorkIf { void doWork(String name);} work.java pac ...
- ruby 字符串学习笔记3
ascii转字符或者字符串转ascii "a".ord # => 97 "!".ord # => 33 "\n".ord # = ...
- 配置sql server 2000以允许远程访问 及 连接中的四个最常见错误
地址:http://www.cnblogs.com/JoshuaDreaming/archive/2010/12/01/1893242.html 配置sql server 2000以允许远程访问适合故 ...