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中国的技术老师有一些交流.一 ...
随机推荐
- AppCan做的图片上传代码
存在AppCan里的网页 index.html <!DOCTYPE html> <html class="um landscape min-width-240px min- ...
- 激活Maven profile的几种方式
首先简单介绍下 Maven 的 profile 是什么.对于人来说,profile 是指人的肖像,轮廓,比如论坛里每个人注册了帐号后,可以设置自己的 profile,放上照片,介绍等等.对于 Mave ...
- iframe获取父、子窗口的方法
jquery.js调用iframe父窗口与子窗口元素的方法 1. jquery在iframe子页面获取父页面元素代码如下: $("#objid",parent.document) ...
- 【freemaker】之eclipse安装freemaker-IDE
eclipse安装插件一般我喜欢手动安装,有种可控的感觉! 首先需要下载freemaker-IDEhttp://freemarker-ide.sourceforge.net/ 下载之后解压得到 在ec ...
- memcached简介(转)
背景 memcached是一个高性能.分布式的内存对象缓存系统. memcached广泛应用在大负载高并发的网站上,是一种非常成熟的产品(称为一项技术也未尝不可).像facebook,yout ...
- *.hbm.xml讲解
<!-- package声明pojo类所在的包,如果不写 那么在class中需要指明pojo类所在的包 schema指数据库模式 一个模式下可以有多张表 --> <hibernate ...
- DG_Oracle DataGuard Primary/Standby物理主备节点安装实践(案例)
2014-09-09 Created By BaoXinjian
- hdu 1536 S-Nim(sg函数模板)
转载自:http://blog.csdn.net/sr_19930829/article/details/23446173 解题思路: 这个题折腾了两三天,参考了两个模板,在这之间折腾过来折腾过去,终 ...
- c++学习-数组
int a[10]; //是个元素,在windows下回报错,linux会输出一个随机数 int a[10]={1,2}; //初始化,其他的为0 数组越界: 为了调高效率, 编译器不会对数组越界做检 ...
- 《精通SQL Server 2008》笔记
7.3触发器的使用 7.4游标的使用 8索引/关系图/完整性 9用户管理