1、导入SHP/CAD文件
WEB具有直接美观展现功能,功能实现到可视化最好不要超过3S,那么就要限制导入文件的大小和优化算法了。
1.1、SHP导入实现思路
SHP格式开源,Git上随便可以找到读取SHP的源码,读取后一般返回GeoJson或JSON格式的要素,然后解析GeoJson实现可视化,ArcGIS体系或OpenLayers体系。
1 var jsonf = GeoJsonConverter();//GeoJson转Esri
2 shp(filename).then(function (data) {
3 var json = jsonf.toEsri(data);//ESRI要素
4 window.map.graphics.clear();
5 var featsarray = [];
6 for (var j = 0; j < json.features.length; j++) {
7 var ss = Graphic(json.features[j]);
8 ss.setSymbol(fillSymbol);
9 ss.geometry.setSpatialReference(window.map.spatialReference);
10 window.map.graphics.add(ss);
11 featsarray.push(ss);
12 }
13 var ptcen = featsarray[0].geometry.getExtent().getCenter();
14 window.map.setScale(4000);
15 window.map.centerAt(ptcen);
16 });
ArcGIS实现加载SHP文件
1.2、CAD导入实现思路
CAD格式封闭,只好通过后台服务(AO/AE开发)或GP服务(要素转JSON,貌似ArcGIS10.3及以上才有),原理也是读取CAD文件后将其转为JSON格式,WEB前端解析JSON可视化显示。
(1)读取CAD:AO/AE开发读取,比较简单;读取后转为JSON可借助类JSONConverterGeometryClass,熟悉JSON结构也可以直接写代码。
/// <summary>
/// 提取feature的geometry,并将其转换为json对象
/// </summary>
/// <param name="pFeature">要素对象</param>
/// <returns></returns>
public static string feature2JsonGeometry(ESRI.ArcGIS.Geodatabase.IFeature pFeature)
{
ESRI.ArcGIS.Geometry.IGeometry pGeo = pFeature.Shape;
//return GeometryToJsonString(pGeo);
int wkid = pGeo.SpatialReference.FactoryCode;
ESRI.ArcGIS.Geometry.IPoint pPoint = null;
ESRI.ArcGIS.Geometry.IPointCollection pPoints = null;
double x, y;
StringBuilder sb = new StringBuilder("{"); switch (pGeo.GeometryType)
{
#region Point2Json
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
pPoint = pGeo as ESRI.ArcGIS.Geometry.IPoint;
pPoint.QueryCoords(out x, out y);
string json = @"""x"":" + x + @",""y"":" + y + @",""spatialReference"":" + @"{""wkid"":" + wkid + "}";
sb.Append(json);
break;
#endregion #region Polyline2Json
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
pPoints = pGeo as ESRI.ArcGIS.Geometry.IPointCollection;
sb.Append(@"""paths"":[[");
for (int i = ; i < pPoints.PointCount; i++)
{
pPoint = pPoints.get_Point(i);
pPoint.QueryCoords(out x, out y);
sb.Append("[" + x + "," + y + "],");
}
sb.Remove(sb.Length - , );
sb.Append("]]" + @",""spatialReference"":" + @"{""wkid"":" + wkid + "}");
break; #endregion #region Polygon2Json
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
pPoints = pGeo as ESRI.ArcGIS.Geometry.IPointCollection;
sb.Append(@"""rings"":[[");
for (int i = ; i < pPoints.PointCount; i++)
{
pPoint = pPoints.get_Point(i);
pPoint.QueryCoords(out x, out y);
sb.Append("[" + x + "," + y + "],");
}
sb.Remove(sb.Length - , );
sb.Append("]]" + @",""spatialReference"":" + @"{""wkid"":" + wkid + "}"); break;
#endregion
}
sb.Append("}");
return sb.ToString();
}
提取feature的geometry,并将其转换为json对象
(2)GP服务(要素转JSON),在高版本中工具箱——转换(Conversion)——JSON,执行后发布为GP服务,前端调用GPServer实现读取转为JSON。
$.ajax({
type: "post",
url: window.top.RootPath + "/fastGIS/pro/FastService.asmx/GetCADGraphicContent",
contentType: "application/json; charset=utf-8",
data: "{fileName:'" + filename + "'}",
success: function (result) {
console.log(result);
var jsons = result.d.split("|");
if (jsons) {
for(var i=0;i<jsons.length;i++){
var geore = JsonUtils.fromJson(JSON.parse(jsons[i]));//ArcGIS JS API函数解析
geore.setSpatialReference(window.top.map.spatialReference);
switch (geore.type) {
case "polygon":
window.top.map.graphics.add(Graphic(geore, fillSymbol));
break;
case "polyline":
window.top.map.graphics.add(Graphic(geore, lineSymbol));
break;
default:
break;
}
window.top.map.centerAt(geore.getPoint(0, 0));
}
}
window.top.map.setScale(4000);
},
error: function (err) {
console.log(err);
}
});
后台服务AJAX实现可视化
2、导出SHP/CAD文件
导出是导入的逆向过程,要求从WebGIS的地图上(各种可视化地图)按照需求(比如按区域、按绘制范围)导出对应的图形和属性数据,前后台联合进行。
2.1 导出SHP文件实现思路
在地图前台操作,肯定是需要通过绘制范围、选择对象查询符合区域的数据,将该区域的相关对象前台或后台处理;有2种方式,一种直接后台转JSON再输出为SHP文件,另一种就是全部后台运作,通过ArcGIS后台开发保存为SHP文件。
此处参考博客:【http://blog.csdn.net/gis0911178/article/details/52162477】详细说明SHP文件,开源读取并生成SHP文件。【引用已说明出处,尊重原作】
2.2 导出CAD文件实现思路
前面已说明CAD的DWG格式文件封闭,但DXF格式开源,因此可以直接写DXF输出文件;另外一种思路则是直接通过AO/AE开发后台,“导出SHP—转为CAD”这种思路输出DWG文件。
Geoprocessor gp = new Geoprocessor();
ExportCAD exCAD = new ExportCAD();//工具箱中的转为CAD工具
exCAD.Output_File = @fileDir + ".dwg";
exCAD.Output_Type = "DWG_R2004";
exCAD.in_features = @fileDir + "\\" + fileName + ".shp";
exCAD.Ignore_FileNames = "False";
try
{
var res = gp.Execute(exCAD, null);
return "/TemporaryFile/createSHP/" + fileName + ".dwg";
}
catch (Exception ee)
{ }
Geoprocessor实现SHP转CAD
另外写DXF输出文件也提供源码。
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Globalization; using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Carto; namespace Fast.FastMan.BUS.GisPro.CommonGIS
{
public class ConvertDXFArgs : System.EventArgs
{
bool result = false;
Exception ex = null; public ConvertDXFArgs()
{
result = true;
} public ConvertDXFArgs(Exception ex)
{
this.ex = ex;
} public bool Result
{
get { return result; }
} public Exception Exception
{
get { return ex; }
}
} public class ConvertDXF
{
public delegate void OnCompleted(object sender, ConvertDXFArgs e);
public event OnCompleted completed; struct ColorDXF
{
public byte Red;
public byte Green;
public byte Blue;
public ColorDXF(byte r, byte g, byte b)
{
Red = r;
Green = g;
Blue = b;
}
} struct TagDXF
{
public const string HEADER = "HEADER";
public const string TABLES = "TABLES";
public const string ENTITIES = "ENTITIES";
public const string BLOCKS = "BLOCKS";
} string m_Filename = null;
IFeatureLayer m_FeatureLayer = null;
TextWriter m_tw = null; public ConvertDXF(string filename, IFeatureLayer featureLayer)
{
m_Filename = filename;
m_FeatureLayer = featureLayer;
} public void Convert()
{
if ((m_FeatureLayer == null) || (string.IsNullOrEmpty(m_Filename)))
{
completed(this, new ConvertDXFArgs(new Exception("FeatureLayer is null or Filename is null")));
} try
{
m_tw = new StreamWriter(m_Filename); IEnvelope envelope = m_FeatureLayer.AreaOfInterest;
IFeatureClass featureClass = m_FeatureLayer.FeatureClass; Header(envelope);
Tables();
Blocks();
Entities(); completed(this, new ConvertDXFArgs());
}
catch (Exception ex)
{
completed(this, new ConvertDXFArgs(ex));
}
finally
{
m_tw.Close();
m_tw.Dispose();
m_tw = null;
} } /// <summary>
/// return color nearest Autocad
/// </summary>
/// <param name="intR"></param>
/// <param name="intG"></param>
/// <param name="intB"></param>
/// <returns></returns>
static ColorDXF GetColorDXF(ColorDXF c)
{
IDictionary<byte, string> dct = new Dictionary<byte, string>();
#region Dictionary Color
//item: colore come valore RGB, key: colore equivalent in AutoCAD
dct.Add(, "0|0|0");
dct.Add(, "255|0|0");
dct.Add(, "255|255|0");
dct.Add(, "0|255|0");
dct.Add(, "0|255|255");
dct.Add(, "0|0|255");
dct.Add(, "255|0|255");
dct.Add(, "255|255|255");
dct.Add(, "65|65|65");
dct.Add(, "128|128|128");
dct.Add(, "255|0|0");
dct.Add(, "255|170|170");
dct.Add(, "189|0|0");
dct.Add(, "189|126|126");
dct.Add(, "129|0|0");
dct.Add(, "129|86|86");
dct.Add(, "104|0|0");
dct.Add(, "104|69|69");
dct.Add(, "79|0|0");
dct.Add(, "79|53|53");
dct.Add(, "255|63|0");
dct.Add(, "255|191|170");
dct.Add(, "189|46|0");
dct.Add(, "189|141|126");
dct.Add(, "129|31|0");
dct.Add(, "129|96|86");
dct.Add(, "104|25|0");
dct.Add(, "104|78|69");
dct.Add(, "79|19|0");
dct.Add(, "79|59|53");
dct.Add(, "255|127|0");
dct.Add(, "255|212|170");
dct.Add(, "189|94|0");
dct.Add(, "189|157|126");
dct.Add(, "129|64|0");
dct.Add(, "129|107|86");
dct.Add(, "104|52|0");
dct.Add(, "104|86|69");
dct.Add(, "79|39|0");
dct.Add(, "79|66|53");
dct.Add(, "255|191|0");
dct.Add(, "255|234|170");
dct.Add(, "189|141|0");
dct.Add(, "189|173|126");
dct.Add(, "129|96|0");
dct.Add(, "129|118|86");
dct.Add(, "104|78|0");
dct.Add(, "104|95|69");
dct.Add(, "79|59|0");
dct.Add(, "79|73|53");
dct.Add(, "255|255|0");
dct.Add(, "255|255|170");
dct.Add(, "189|189|0");
dct.Add(, "189|189|126");
dct.Add(, "129|129|0");
dct.Add(, "129|129|86");
dct.Add(, "104|104|0");
dct.Add(, "104|104|69");
dct.Add(, "79|79|0");
dct.Add(, "79|79|53");
dct.Add(, "191|255|0");
dct.Add(, "234|255|170");
dct.Add(, "141|189|0");
dct.Add(, "173|189|126");
dct.Add(, "96|129|0");
dct.Add(, "118|129|86");
dct.Add(, "78|104|0");
dct.Add(, "95|104|69");
dct.Add(, "59|79|0");
dct.Add(, "73|79|53");
dct.Add(, "127|255|0");
dct.Add(, "212|255|170");
dct.Add(, "94|189|0");
dct.Add(, "157|189|126");
dct.Add(, "64|129|0");
dct.Add(, "107|129|86");
dct.Add(, "52|104|0");
dct.Add(, "86|104|69");
dct.Add(, "39|79|0");
dct.Add(, "66|79|53");
dct.Add(, "63|255|0");
dct.Add(, "191|255|170");
dct.Add(, "46|189|0");
dct.Add(, "141|189|126");
dct.Add(, "31|129|0");
dct.Add(, "96|129|86");
dct.Add(, "25|104|0");
dct.Add(, "78|104|69");
dct.Add(, "19|79|0");
dct.Add(, "59|79|53");
dct.Add(, "0|255|0");
dct.Add(, "170|255|170");
dct.Add(, "0|189|0");
dct.Add(, "126|189|126");
dct.Add(, "0|129|0");
dct.Add(, "86|129|86");
dct.Add(, "0|104|0");
dct.Add(, "69|104|69");
dct.Add(, "0|79|0");
dct.Add(, "53|79|53");
dct.Add(, "0|255|63");
dct.Add(, "170|255|191");
dct.Add(, "0|189|46");
dct.Add(, "126|189|141");
dct.Add(, "0|129|31");
dct.Add(, "86|129|96");
dct.Add(, "0|104|25");
dct.Add(, "69|104|78");
dct.Add(, "0|79|19");
dct.Add(, "53|79|59");
dct.Add(, "0|255|127");
dct.Add(, "170|255|212");
dct.Add(, "0|189|94");
dct.Add(, "126|189|157");
dct.Add(, "0|129|64");
dct.Add(, "86|129|107");
dct.Add(, "0|104|52");
dct.Add(, "69|104|86");
dct.Add(, "0|79|39");
dct.Add(, "53|79|66");
dct.Add(, "0|255|191");
dct.Add(, "170|255|234");
dct.Add(, "0|189|141");
dct.Add(, "126|189|173");
dct.Add(, "0|129|96");
dct.Add(, "86|129|118");
dct.Add(, "0|104|78");
dct.Add(, "69|104|95");
dct.Add(, "0|79|59");
dct.Add(, "53|79|73");
dct.Add(, "0|255|255");
dct.Add(, "170|255|255");
dct.Add(, "0|189|189");
dct.Add(, "126|189|189");
dct.Add(, "0|129|129");
dct.Add(, "86|129|129");
dct.Add(, "0|104|104");
dct.Add(, "69|104|104");
dct.Add(, "0|79|79");
dct.Add(, "53|79|79");
dct.Add(, "0|191|255");
dct.Add(, "170|234|255");
dct.Add(, "0|141|189");
dct.Add(, "126|173|189");
dct.Add(, "0|96|129");
dct.Add(, "86|118|129");
dct.Add(, "0|78|104");
dct.Add(, "69|95|104");
dct.Add(, "0|59|79");
dct.Add(, "53|73|79");
dct.Add(, "0|127|255");
dct.Add(, "170|212|255");
dct.Add(, "0|94|189");
dct.Add(, "126|157|189");
dct.Add(, "0|64|129");
dct.Add(, "86|107|129");
dct.Add(, "0|52|104");
dct.Add(, "69|86|104");
dct.Add(, "0|39|79");
dct.Add(, "53|66|79");
dct.Add(, "0|63|255");
dct.Add(, "170|191|255");
dct.Add(, "0|46|189");
dct.Add(, "126|141|189");
dct.Add(, "0|31|129");
dct.Add(, "86|96|129");
dct.Add(, "0|25|104");
dct.Add(, "69|78|104");
dct.Add(, "0|19|79");
dct.Add(, "53|59|79");
dct.Add(, "0|0|255");
dct.Add(, "170|170|255");
dct.Add(, "0|0|189");
dct.Add(, "126|126|189");
dct.Add(, "0|0|129");
dct.Add(, "86|86|129");
dct.Add(, "0|0|104");
dct.Add(, "69|69|104");
dct.Add(, "0|0|79");
dct.Add(, "53|53|79");
dct.Add(, "63|0|255");
dct.Add(, "191|170|255");
dct.Add(, "46|0|189");
dct.Add(, "141|126|189");
dct.Add(, "31|0|129");
dct.Add(, "96|86|129");
dct.Add(, "25|0|104");
dct.Add(, "78|69|104");
dct.Add(, "19|0|79");
dct.Add(, "59|53|79");
dct.Add(, "127|0|255");
dct.Add(, "212|170|255");
dct.Add(, "94|0|189");
dct.Add(, "157|126|189");
dct.Add(, "64|0|129");
dct.Add(, "107|86|129");
dct.Add(, "52|0|104");
dct.Add(, "86|69|104");
dct.Add(, "39|0|79");
dct.Add(, "66|53|79");
dct.Add(, "191|0|255");
dct.Add(, "234|170|255");
dct.Add(, "141|0|189");
dct.Add(, "173|126|189");
dct.Add(, "96|0|129");
dct.Add(, "118|86|129");
dct.Add(, "78|0|104");
dct.Add(, "95|69|104");
dct.Add(, "59|0|79");
dct.Add(, "73|53|79");
dct.Add(, "255|0|255");
dct.Add(, "255|170|255");
dct.Add(, "189|0|189");
dct.Add(, "189|126|189");
dct.Add(, "129|0|129");
dct.Add(, "129|86|129");
dct.Add(, "104|0|104");
dct.Add(, "104|69|104");
dct.Add(, "79|0|79");
dct.Add(, "79|53|79");
dct.Add(, "255|0|191");
dct.Add(, "255|170|234");
dct.Add(, "189|0|141");
dct.Add(, "189|126|173");
dct.Add(, "129|0|96");
dct.Add(, "129|86|118");
dct.Add(, "104|0|78");
dct.Add(, "104|69|95");
dct.Add(, "79|0|59");
dct.Add(, "79|53|73");
dct.Add(, "255|0|127");
dct.Add(, "255|170|212");
dct.Add(, "189|0|94");
dct.Add(, "189|126|157");
dct.Add(, "129|0|64");
dct.Add(, "129|86|107");
dct.Add(, "104|0|52");
dct.Add(, "104|69|86");
dct.Add(, "79|0|39");
dct.Add(, "79|53|66");
dct.Add(, "255|0|63");
dct.Add(, "255|170|191");
dct.Add(, "189|0|46");
dct.Add(, "189|126|141");
dct.Add(, "129|0|31");
dct.Add(, "129|86|96");
dct.Add(, "104|0|25");
dct.Add(, "104|69|78");
dct.Add(, "79|0|19");
dct.Add(, "79|53|59");
dct.Add(, "51|51|51");
dct.Add(, "80|80|80");
dct.Add(, "105|105|105");
dct.Add(, "130|130|130");
dct.Add(, "190|190|190");
dct.Add(, "255|255|255"); #endregion Dictionary Color string[] sColorCAD; //tutti possibili colori della collection
byte bGCAD, bRCAD, bBCAD; //valori RGB di tutti colori
byte color = ; //color nearest of collection
double dblTemp = Double.MaxValue;
double dblDistance; foreach (byte idx in dct.Keys)
{
sColorCAD = dct[idx].Split('|');
bRCAD = byte.Parse(sColorCAD[]);
bGCAD = byte.Parse(sColorCAD[]);
bBCAD = byte.Parse(sColorCAD[]); dblDistance = System.Math.Sqrt((bRCAD - c.Red) ^ + (bGCAD - c.Green) ^ + (bBCAD - c.Blue) ^ ); if (dblDistance < dblTemp)
{
dblTemp = dblDistance;
color = idx;
if (dblTemp == )
break; }
} //color "0" (not defined) -> color "7" (default of AutoCAD)
if (color == )
color = ; string[] r = dct[color].Split('|');
return new ColorDXF(byte.Parse(r[]), byte.Parse(r[]), byte.Parse(r[]));
}
static IFormatProvider GetFormatProvider()
{
NumberFormatInfo nfi = new NumberFormatInfo();
nfi.CurrencyDecimalSeparator = ".";
return nfi;
} void BeginSection(string Tag)
{
m_tw.WriteLine();
m_tw.WriteLine("SECTION");
m_tw.WriteLine();
m_tw.WriteLine(Tag);
}
void EndSection()
{
m_tw.WriteLine();
m_tw.WriteLine("ENDSEC");
} void EOF()
{
m_tw.WriteLine();
m_tw.WriteLine("EOF");
} void Point(IPointCollection pPoints, string LayerName, byte? Color)
{
for (int i = ; i < pPoints.PointCount; i++)
{
Point(pPoints.get_Point(i), LayerName, Color);
}
} void Blocks()
{
BeginSection(TagDXF.BLOCKS);
EndSection();
} void Tables()
{
BeginSection(TagDXF.TABLES);
EndSection();
} void Point(IPoint pPoint, string LayerName, byte? Color)
{
m_tw.WriteLine();
m_tw.WriteLine("POINT");
m_tw.WriteLine();
m_tw.WriteLine(LayerName);
m_tw.WriteLine();
if (Color != null)
m_tw.WriteLine(Color); m_tw.WriteLine();
m_tw.WriteLine(pPoint.X.ToString(GetFormatProvider()));
m_tw.WriteLine();
m_tw.WriteLine(pPoint.Y.ToString(GetFormatProvider())); m_tw.WriteLine(); //Thickness
m_tw.WriteLine();
} void Header(IEnvelope extent)
{
IPoint LLExtents = extent.LowerLeft;
IPoint URExtents = extent.UpperRight; BeginSection(TagDXF.HEADER); m_tw.WriteLine();
m_tw.WriteLine("$EXTMIN");
m_tw.WriteLine();
m_tw.WriteLine(LLExtents.X.ToString(GetFormatProvider()));
m_tw.WriteLine();
m_tw.WriteLine(LLExtents.Y.ToString(GetFormatProvider()));
m_tw.WriteLine();
m_tw.WriteLine();
m_tw.WriteLine();
m_tw.WriteLine("$EXTMAX");
m_tw.WriteLine();
m_tw.WriteLine(URExtents.X.ToString(GetFormatProvider()));
m_tw.WriteLine();
m_tw.WriteLine(URExtents.Y.ToString(GetFormatProvider()));
m_tw.WriteLine();
m_tw.WriteLine(); EndSection();
} void Polyline(IGeometry pShape, string LayerName, byte? Color)
{ IGeometryCollection geometryCollection; if (pShape is IGeometryCollection)
geometryCollection = pShape as IGeometryCollection;
else
{
object o = Type.Missing;
geometryCollection = new Polygon() as IGeometryCollection;
geometryCollection.AddGeometry(pShape, ref o, ref o);
} for (int j = ; j < geometryCollection.GeometryCount; j++)
{
ISegmentCollection pSegColl = geometryCollection.get_Geometry(j) as ISegmentCollection; bool bFirstSeg = true;
ICircularArc pCA = null;
ISegment pSeg = null; for (int i = ; i < pSegColl.SegmentCount; i++)
{
pSeg = pSegColl.get_Segment(i); switch (pSeg.GeometryType)
{
case esriGeometryType.esriGeometryLine: if (bFirstSeg)
{
m_tw.WriteLine();
m_tw.WriteLine("POLYLINE"); m_tw.WriteLine(); m_tw.WriteLine(LayerName); m_tw.WriteLine();
m_tw.WriteLine(); if (Color != null)
{
m_tw.WriteLine();
m_tw.WriteLine(Color);
}
m_tw.WriteLine();
m_tw.WriteLine("CONTINUOUS");
//from point
m_tw.WriteLine();
m_tw.WriteLine("VERTEX");
m_tw.WriteLine(); m_tw.WriteLine(LayerName); m_tw.WriteLine();
m_tw.WriteLine(pSeg.FromPoint.X.ToString(GetFormatProvider()));
m_tw.WriteLine();
m_tw.WriteLine(pSeg.FromPoint.Y.ToString(GetFormatProvider())); bFirstSeg = !bFirstSeg;
} // to point
m_tw.WriteLine();
m_tw.WriteLine("VERTEX");
m_tw.WriteLine();
m_tw.WriteLine(LayerName); m_tw.WriteLine();
m_tw.WriteLine(pSeg.ToPoint.X.ToString(GetFormatProvider()));
m_tw.WriteLine();
m_tw.WriteLine(pSeg.ToPoint.Y.ToString(GetFormatProvider()));
if (i == (pSegColl.SegmentCount - ))
{
m_tw.WriteLine();
m_tw.WriteLine("SEQEND");
m_tw.WriteLine();
m_tw.WriteLine(LayerName); }
break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryCircularArc:
if (!bFirstSeg)
{ m_tw.WriteLine();
m_tw.WriteLine("SEQEND");
m_tw.WriteLine();
m_tw.WriteLine(LayerName);
} pCA = pSeg as ICircularArc; m_tw.WriteLine();
m_tw.WriteLine("ARC");
m_tw.WriteLine();
m_tw.WriteLine(LayerName);
m_tw.WriteLine();
m_tw.WriteLine(pCA.CenterPoint.X.ToString(GetFormatProvider()));
m_tw.WriteLine();
m_tw.WriteLine(pCA.CenterPoint.Y.ToString(GetFormatProvider()));
m_tw.WriteLine();
m_tw.WriteLine(pCA.Radius); string sFromAngle = (pCA.FromAngle * / Math.PI).ToString(GetFormatProvider());
string sToAngle = (pCA.ToAngle * / Math.PI).ToString(GetFormatProvider()); m_tw.WriteLine();
m_tw.WriteLine(pCA.IsCounterClockwise ? sFromAngle : sToAngle);
m_tw.WriteLine();
m_tw.WriteLine(pCA.IsCounterClockwise ? sToAngle : sFromAngle); bFirstSeg = true;
break;
}
}
}
} void Polygon(IGeometry pShape, string LayerName, byte? Color)
{
IPolygon4 polygon = pShape as IPolygon4;
IGeometryBag exteriorRings = polygon.ExteriorRingBag; //For each exterior rings find the interior rings associated with it
IEnumGeometry exteriorRingsEnum = exteriorRings as IEnumGeometry;
exteriorRingsEnum.Reset();
IRing currentExteriorRing = exteriorRingsEnum.Next() as IRing; while (currentExteriorRing != null)
{
Polyline(currentExteriorRing, LayerName, Color); IGeometryBag interiorRings = polygon.get_InteriorRingBag(currentExteriorRing);
IEnumGeometry interiorRingsEnum = interiorRings as IEnumGeometry;
interiorRingsEnum.Reset();
IRing currentInteriorRing = interiorRingsEnum.Next() as IRing;
while (currentInteriorRing != null)
{
Polyline(currentInteriorRing, LayerName, Color);
currentInteriorRing = interiorRingsEnum.Next() as IRing;
}
currentExteriorRing = exteriorRingsEnum.Next() as IRing;
}
} void Entities()
{
BeginSection(TagDXF.ENTITIES); byte? Color = ;
string LayerName = m_FeatureLayer.Name; IFeatureClass featureClass = m_FeatureLayer.FeatureClass;
IFeatureCursor featureCursor = featureClass.Search(null, true);
IFeature feature = featureCursor.NextFeature();
IGeometry shape = null; while (feature != null)
{
shape = feature.ShapeCopy;
//int? OID = feature.HasOID ? feature.OID : new Nullable<int>(); switch (shape.GeometryType)
{
case esriGeometryType.esriGeometryPoint:
Point(shape as IPoint, LayerName, Color);
break;
case esriGeometryType.esriGeometryMultipoint:
Point(shape as IPointCollection, LayerName, Color);
break;
case esriGeometryType.esriGeometryPolyline:
Polyline(shape, LayerName, Color);
break;
case esriGeometryType.esriGeometryPolygon:
Polygon(shape, LayerName, Color);
break;
case esriGeometryType.esriGeometryEnvelope:
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPath:
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryAny:
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryRing:
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryLine:
Polyline(shape, LayerName, Color);
break;
case esriGeometryType.esriGeometryCircularArc:
case esriGeometryType.esriGeometryBezier3Curve:
case esriGeometryType.esriGeometryEllipticArc:
break;
}
feature = featureCursor.NextFeature();
}
EndSection();
EOF();
}
}
}
转为DXF文件
至此,WEB直接导入导出SHP/CAD如愿实现,共勉。
【转载请说明出处,尊重知识传播】2017-06-30