Web直接導入導出SHP/CAD實現探討。
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結構也可以直接寫代碼。
///
///
/// 要素對象
///
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 = 0; i < pPoints.PointCount; i++)
{
pPoint = pPoints.get_Point(i);
pPoint.QueryCoords(out x, out y);
sb.Append("[" + x + "," + y + "],");
}
sb.Remove(sb.Length - 1, 1);
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 = 0; i < pPoints.PointCount; i++)
{
pPoint = pPoints.get_Point(i);
pPoint.QueryCoords(out x, out y);
sb.Append("[" + x + "," + y + "],");
}
sb.Remove(sb.Length - 1, 1);
sb.Append("]]" + @",""spatialReference"":" + @"{""wkid"":" + wkid + "}");
break;
#endregion
}
sb.Append("}");
return sb.ToString;
}
提取feature的geometry,並將其轉換為json對象
(2)GP服務(要素轉JSON),在高版本中工具箱——轉換(Conversion)——JSON,執行後發布為GP服務,前端調用GPServer實現讀取轉為JSON。
$.ajax({ 後台服務AJAX實現可視化 2、導出SHP/CAD文件
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
導出是導入的逆向過程,要求從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;
}
}
///
///
///
///
///
///
static ColorDXF GetColorDXF(ColorDXF c)
{
IDictionary
#region Dictionary Color
//item: colore come valore RGB, key: colore equivalent in AutoCAD
dct.Add(0, "0|0|0");
dct.Add(1, "255|0|0");
dct.Add(2, "255|255|0");
dct.Add(3, "0|255|0");
dct.Add(4, "0|255|255");
dct.Add(5, "0|0|255");
dct.Add(6, "255|0|255");
dct.Add(7, "255|255|255");
dct.Add(8, "65|65|65");
dct.Add(9, "128|128|128");
dct.Add(10, "255|0|0");
dct.Add(11, "255|170|170");
dct.Add(12, "189|0|0");
dct.Add(13, "189|126|126");
dct.Add(14, "129|0|0");
dct.Add(15, "129|86|86");
dct.Add(16, "104|0|0");
dct.Add(17, "104|69|69");
dct.Add(18, "79|0|0");
dct.Add(19, "79|53|53");
dct.Add(20, "255|63|0");
dct.Add(21, "255|191|170");
dct.Add(22, "189|46|0");
dct.Add(23, "189|141|126");
dct.Add(24, "129|31|0");
dct.Add(25, "129|96|86");
dct.Add(26, "104|25|0");
dct.Add(27, "104|78|69");
dct.Add(28, "79|19|0");
dct.Add(29, "79|59|53");
dct.Add(30, "255|127|0");
dct.Add(31, "255|212|170");
dct.Add(32, "189|94|0");
dct.Add(33, "189|157|126");
dct.Add(34, "129|64|0");
dct.Add(35, "129|107|86");
dct.Add(36, "104|52|0");
dct.Add(37, "104|86|69");
dct.Add(38, "79|39|0");
dct.Add(39, "79|66|53");
dct.Add(40, "255|191|0");
dct.Add(41, "255|234|170");
dct.Add(42, "189|141|0");
dct.Add(43, "189|173|126");
dct.Add(44, "129|96|0");
dct.Add(45, "129|118|86");
dct.Add(46, "104|78|0");
dct.Add(47, "104|95|69");
dct.Add(48, "79|59|0");
dct.Add(49, "79|73|53");
dct.Add(50, "255|255|0");
dct.Add(51, "255|255|170");
dct.Add(52, "189|189|0");
dct.Add(53, "189|189|126");
dct.Add(54, "129|129|0");
dct.Add(55, "129|129|86");
dct.Add(56, "104|104|0");
dct.Add(57, "104|104|69");
dct.Add(58, "79|79|0");
dct.Add(59, "79|79|53");
dct.Add(60, "191|255|0");
dct.Add(61, "234|255|170");
dct.Add(62, "141|189|0");
dct.Add(63, "173|189|126");
dct.Add(64, "96|129|0");
dct.Add(65, "118|129|86");
dct.Add(66, "78|104|0");
dct.Add(67, "95|104|69");
dct.Add(68, "59|79|0");
dct.Add(69, "73|79|53");
dct.Add(70, "127|255|0");
dct.Add(71, "212|255|170");
dct.Add(72, "94|189|0");
dct.Add(73, "157|189|126");
dct.Add(74, "64|129|0");
dct.Add(75, "107|129|86");
dct.Add(76, "52|104|0");
dct.Add(77, "86|104|69");
dct.Add(78, "39|79|0");
dct.Add(79, "66|79|53");
dct.Add(80, "63|255|0");
dct.Add(81, "191|255|170");
dct.Add(82, "46|189|0");
dct.Add(83, "141|189|126");
dct.Add(84, "31|129|0");
dct.Add(85, "96|129|86");
dct.Add(86, "25|104|0");
dct.Add(87, "78|104|69");
dct.Add(88, "19|79|0");
dct.Add(89, "59|79|53");
dct.Add(90, "0|255|0");
dct.Add(91, "170|255|170");
dct.Add(92, "0|189|0");
dct.Add(93, "126|189|126");
dct.Add(94, "0|129|0");
dct.Add(95, "86|129|86");
dct.Add(96, "0|104|0");
dct.Add(97, "69|104|69");
dct.Add(98, "0|79|0");
dct.Add(99, "53|79|53");
dct.Add(100, "0|255|63");
dct.Add(101, "170|255|191");
dct.Add(102, "0|189|46");
dct.Add(103, "126|189|141");
dct.Add(104, "0|129|31");
dct.Add(105, "86|129|96");
dct.Add(106, "0|104|25");
dct.Add(107, "69|104|78");
dct.Add(108, "0|79|19");
dct.Add(109, "53|79|59");
dct.Add(110, "0|255|127");
dct.Add(111, "170|255|212");
dct.Add(112, "0|189|94");
dct.Add(113, "126|189|157");
dct.Add(114, "0|129|64");
dct.Add(115, "86|129|107");
dct.Add(116, "0|104|52");
dct.Add(117, "69|104|86");
dct.Add(118, "0|79|39");
dct.Add(119, "53|79|66");
dct.Add(120, "0|255|191");
dct.Add(121, "170|255|234");
dct.Add(122, "0|189|141");
dct.Add(123, "126|189|173");
dct.Add(124, "0|129|96");
dct.Add(125, "86|129|118");
dct.Add(126, "0|104|78");
dct.Add(127, "69|104|95");
dct.Add(128, "0|79|59");
dct.Add(129, "53|79|73");
dct.Add(130, "0|255|255");
dct.Add(131, "170|255|255");
dct.Add(132, "0|189|189");
dct.Add(133, "126|189|189");
dct.Add(134, "0|129|129");
dct.Add(135, "86|129|129");
dct.Add(136, "0|104|104");
dct.Add(137, "69|104|104");
dct.Add(138, "0|79|79");
dct.Add(139, "53|79|79");
dct.Add(140, "0|191|255");
dct.Add(141, "170|234|255");
dct.Add(142, "0|141|189");
dct.Add(143, "126|173|189");
dct.Add(144, "0|96|129");
dct.Add(145, "86|118|129");
dct.Add(146, "0|78|104");
dct.Add(147, "69|95|104");
dct.Add(148, "0|59|79");
dct.Add(149, "53|73|79");
dct.Add(150, "0|127|255");
dct.Add(151, "170|212|255");
dct.Add(152, "0|94|189");
dct.Add(153, "126|157|189");
dct.Add(154, "0|64|129");
dct.Add(155, "86|107|129");
dct.Add(156, "0|52|104");
dct.Add(157, "69|86|104");
dct.Add(158, "0|39|79");
dct.Add(159, "53|66|79");
dct.Add(160, "0|63|255");
dct.Add(161, "170|191|255");
dct.Add(162, "0|46|189");
dct.Add(163, "126|141|189");
dct.Add(164, "0|31|129");
dct.Add(165, "86|96|129");
dct.Add(166, "0|25|104");
dct.Add(167, "69|78|104");
dct.Add(168, "0|19|79");
dct.Add(169, "53|59|79");
dct.Add(170, "0|0|255");
dct.Add(171, "170|170|255");
dct.Add(172, "0|0|189");
dct.Add(173, "126|126|189");
dct.Add(174, "0|0|129");
dct.Add(175, "86|86|129");
dct.Add(176, "0|0|104");
dct.Add(177, "69|69|104");
dct.Add(178, "0|0|79");
dct.Add(179, "53|53|79");
dct.Add(180, "63|0|255");
dct.Add(181, "191|170|255");
dct.Add(182, "46|0|189");
dct.Add(183, "141|126|189");
dct.Add(184, "31|0|129");
dct.Add(185, "96|86|129");
dct.Add(186, "25|0|104");
dct.Add(187, "78|69|104");
dct.Add(188, "19|0|79");
dct.Add(189, "59|53|79");
dct.Add(190, "127|0|255");
dct.Add(191, "212|170|255");
dct.Add(192, "94|0|189");
dct.Add(193, "157|126|189");
dct.Add(194, "64|0|129");
dct.Add(195, "107|86|129");
dct.Add(196, "52|0|104");
dct.Add(197, "86|69|104");
dct.Add(198, "39|0|79");
dct.Add(199, "66|53|79");
dct.Add(200, "191|0|255");
dct.Add(201, "234|170|255");
dct.Add(202, "141|0|189");
dct.Add(203, "173|126|189");
dct.Add(204, "96|0|129");
dct.Add(205, "118|86|129");
dct.Add(206, "78|0|104");
dct.Add(207, "95|69|104");
dct.Add(208, "59|0|79");
dct.Add(209, "73|53|79");
dct.Add(210, "255|0|255");
dct.Add(211, "255|170|255");
dct.Add(212, "189|0|189");
dct.Add(213, "189|126|189");
dct.Add(214, "129|0|129");
dct.Add(215, "129|86|129");
dct.Add(216, "104|0|104");
dct.Add(217, "104|69|104");
dct.Add(218, "79|0|79");
dct.Add(219, "79|53|79");
dct.Add(220, "255|0|191");
dct.Add(221, "255|170|234");
dct.Add(222, "189|0|141");
dct.Add(223, "189|126|173");
dct.Add(224, "129|0|96");
dct.Add(225, "129|86|118");
dct.Add(226, "104|0|78");
dct.Add(227, "104|69|95");
dct.Add(228, "79|0|59");
dct.Add(229, "79|53|73");
dct.Add(230, "255|0|127");
dct.Add(231, "255|170|212");
dct.Add(232, "189|0|94");
dct.Add(233, "189|126|157");
dct.Add(234, "129|0|64");
dct.Add(235, "129|86|107");
dct.Add(236, "104|0|52");
dct.Add(237, "104|69|86");
dct.Add(238, "79|0|39");
dct.Add(239, "79|53|66");
dct.Add(240, "255|0|63");
dct.Add(241, "255|170|191");
dct.Add(242, "189|0|46");
dct.Add(243, "189|126|141");
dct.Add(244, "129|0|31");
dct.Add(245, "129|86|96");
dct.Add(246, "104|0|25");
dct.Add(247, "104|69|78");
dct.Add(248, "79|0|19");
dct.Add(249, "79|53|59");
dct.Add(250, "51|51|51");
dct.Add(251, "80|80|80");
dct.Add(252, "105|105|105");
dct.Add(253, "130|130|130");
dct.Add(254, "190|190|190");
dct.Add(255, "255|255|255");
#endregion Dictionary Color
string sColorCAD; //tutti possibili colori della collection
byte bGCAD, bRCAD, bBCAD; //valori RGB di tutti colori
byte color = 0;
//color nearest of collection
double dblTemp = Double.MaxValue;
double dblDistance;
foreach (byte idx in dct.Keys)
{
sColorCAD = dct[idx].Split("|");
bRCAD = byte.Parse(sColorCAD[0]);
bGCAD = byte.Parse(sColorCAD[1]);
bBCAD = byte.Parse(sColorCAD[2]);
dblDistance = System.Math.Sqrt((bRCAD - c.Red) ^ 2 + (bGCAD - c.Green) ^ 2 + (bBCAD - c.Blue) ^ 2);
if (dblDistance < dblTemp)
{
dblTemp = dblDistance;
color = idx;
if (dblTemp == 0)
break;
}
}
//color "0" (not defined) -> color "7" (default of AutoCAD)
if (color == 0)
color = 7;
string r = dct[color].Split("|");
return new ColorDXF(byte.Parse(r[0]), byte.Parse(r[1]), byte.Parse(r[2]));
}
static IFormatProvider GetFormatProvider
{
NumberFormatInfo nfi = new NumberFormatInfo;
nfi.CurrencyDecimalSeparator = ".";
return nfi;
}
void BeginSection(string Tag)
{
m_tw.WriteLine(0);
m_tw.WriteLine("SECTION");
m_tw.WriteLine(2);
m_tw.WriteLine(Tag);
}
void EndSection
{
m_tw.WriteLine(0);
m_tw.WriteLine("ENDSEC");
}
void EOF
{
m_tw.WriteLine(0);
m_tw.WriteLine("EOF");
}
void Point(IPointCollection pPoints, string LayerName, byte? Color)
{
for (int i = 0; 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(0);
m_tw.WriteLine("POINT");
m_tw.WriteLine(8);
m_tw.WriteLine(LayerName);
m_tw.WriteLine(62);
if (Color != null)
m_tw.WriteLine(Color);
m_tw.WriteLine(10);
m_tw.WriteLine(pPoint.X.ToString(GetFormatProvider));
m_tw.WriteLine(20);
m_tw.WriteLine(pPoint.Y.ToString(GetFormatProvider));
m_tw.WriteLine(39); //Thickness
m_tw.WriteLine(3);
}
void Header(IEnvelope extent)
{
IPoint LLExtents = extent.LowerLeft;
IPoint URExtents = extent.UpperRight;
BeginSection(TagDXF.HEADER);
m_tw.WriteLine(9);
m_tw.WriteLine("$EXTMIN");
m_tw.WriteLine(10);
m_tw.WriteLine(LLExtents.X.ToString(GetFormatProvider));
m_tw.WriteLine(20);
m_tw.WriteLine(LLExtents.Y.ToString(GetFormatProvider));
m_tw.WriteLine(30);
m_tw.WriteLine(0);
m_tw.WriteLine(9);
m_tw.WriteLine("$EXTMAX");
m_tw.WriteLine(10);
m_tw.WriteLine(URExtents.X.ToString(GetFormatProvider));
m_tw.WriteLine(20);
m_tw.WriteLine(URExtents.Y.ToString(GetFormatProvider));
m_tw.WriteLine(30);
m_tw.WriteLine(0);
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 = 0; j < geometryCollection.GeometryCount; j++)
{
ISegmentCollection pSegColl = geometryCollection.get_Geometry(j) as ISegmentCollection;
bool bFirstSeg = true;
ICircularArc pCA = null;
ISegment pSeg = null;
for (int i = 0; i < pSegColl.SegmentCount; i++)
{
pSeg = pSegColl.get_Segment(i);
switch (pSeg.GeometryType)
{
case esriGeometryType.esriGeometryLine:
if (bFirstSeg)
{
m_tw.WriteLine(0);
m_tw.WriteLine("POLYLINE");
m_tw.WriteLine(8);
m_tw.WriteLine(LayerName);
m_tw.WriteLine(66);
m_tw.WriteLine(1);
if (Color != null)
{
m_tw.WriteLine(62);
m_tw.WriteLine(Color);
}
m_tw.WriteLine(6);
m_tw.WriteLine("CONTINUOUS");
//from point
m_tw.WriteLine(0);
m_tw.WriteLine("VERTEX");
m_tw.WriteLine(8);
m_tw.WriteLine(LayerName);
m_tw.WriteLine(10);
m_tw.WriteLine(pSeg.FromPoint.X.ToString(GetFormatProvider));
m_tw.WriteLine(20);
m_tw.WriteLine(pSeg.FromPoint.Y.ToString(GetFormatProvider));
bFirstSeg = !bFirstSeg;
}
// to point
m_tw.WriteLine(0);
m_tw.WriteLine("VERTEX");
m_tw.WriteLine(8);
m_tw.WriteLine(LayerName);
m_tw.WriteLine(10);
m_tw.WriteLine(pSeg.ToPoint.X.ToString(GetFormatProvider));
m_tw.WriteLine(20);
m_tw.WriteLine(pSeg.ToPoint.Y.ToString(GetFormatProvider));
if (i == (pSegColl.SegmentCount - 1))
{
m_tw.WriteLine(0);
m_tw.WriteLine("SEQEND");
m_tw.WriteLine(8);
m_tw.WriteLine(LayerName);
}
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryCircularArc:
if (!bFirstSeg)
{
m_tw.WriteLine(0);
m_tw.WriteLine("SEQEND");
m_tw.WriteLine(8);
m_tw.WriteLine(LayerName);
}
pCA = pSeg as ICircularArc;
m_tw.WriteLine(0);
m_tw.WriteLine("ARC");
m_tw.WriteLine(8);
m_tw.WriteLine(LayerName);
m_tw.WriteLine(10);
m_tw.WriteLine(pCA.CenterPoint.X.ToString(GetFormatProvider));
m_tw.WriteLine(20);
m_tw.WriteLine(pCA.CenterPoint.Y.ToString(GetFormatProvider));
m_tw.WriteLine(40);
m_tw.WriteLine(pCA.Radius);
string sFromAngle = (pCA.FromAngle * 180 / Math.PI).ToString(GetFormatProvider);
string sToAngle = (pCA.ToAngle * 180 / Math.PI).ToString(GetFormatProvider);
m_tw.WriteLine(50);
m_tw.WriteLine(pCA.IsCounterClockwise ? sFromAngle : sToAngle);
m_tw.WriteLine(51);
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 = 7;
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
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
※Http批量非同步發送和數據保存
※釘釘微應用的開發——主前端
※java橋連接sql server--關於登錄驗證及對資料庫增刪改查應用
※原創源碼角度分析Android的消息機制系列(六)——Handler的工作原理
※優化mysql資料庫的幾個步驟
TAG:達人科技 |
※SpreadJS ExcelIO實現伺服器端Excel導入導出
※Python腳本將ABAQUS結果導出到excel的方法
※在.Net Core WebAPI下給Swagger增加導出離線文檔功能
※eclipse如何導出WAR包
※MySQL 導出數據
※開源工具Blender將增加glTF格式導入和導出
※mongodb 如何導入導出備份恢復
※LibreOffice 6.0即將發布:支持導出EPUB3格式
※如何將數據從Hadoop導出到關係型和NoSQL資料庫?
※GCC/G++ 符號導出控制
※入門MySQL資料庫導入與導出及重置root密碼
※Ian Goodfellow:生成對抗網路 GAN 的公式是怎樣推導出來的
※iOS取證技巧:在無損的情況下完整導出SQLite資料庫
※VirtualBox 6.0正式發布:支持虛擬機導出至Oracle Cloud架構
※Pore X Tightening Mask(黑頭導出液)功效
※普天同慶!Sketch格式完美導出Psd格式,終於和Ae可以無縫對接了
※滲透技巧——利用Masterkey離線導出Chrome瀏覽器中保存的密碼
※如何導出VENUE日誌?
※imp/exp導入導出的一些錯誤
※redis-cli pipe方式導入mysql sql查詢導出redisProtocol格式數據