GIS二次開發(fā)第4課_第1頁(yè)
GIS二次開發(fā)第4課_第2頁(yè)
GIS二次開發(fā)第4課_第3頁(yè)
GIS二次開發(fā)第4課_第4頁(yè)
GIS二次開發(fā)第4課_第5頁(yè)
已閱讀5頁(yè),還剩74頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

GIS二次開發(fā)第四課幾何對(duì)象——GEOMETRY幾何對(duì)象概述使用幾何對(duì)象空間參考地理變換幾何對(duì)象概述Geometry對(duì)象用于表達(dá)要素(Feature)或圖形元素(Graphic

Element)的幾何形狀。ArcGIS的幾何對(duì)象被分為兩個(gè)層次高級(jí)幾何對(duì)象:用于定義要素的幾何形狀;構(gòu)件幾何對(duì)象:用于構(gòu)建高級(jí)幾何對(duì)象。高級(jí)幾何對(duì)象包括以下類型:Point:具有X、Y坐標(biāo)值,以及可選的屬性,如高程(Z值),測(cè)量值(M)和ID號(hào)。Multipoint:是無(wú)序點(diǎn)的群集,它用于表示具有相同屬性設(shè)置的同一組點(diǎn)。Polyline:是一個(gè)有序路徑(Path)的集合,這些路徑既可以是連續(xù)的,也可以是離散的。Polygon:是環(huán)(Ring)的集合,環(huán)是一種封閉的路徑。Polygon可以由一個(gè)或者多個(gè)環(huán)組成,甚至環(huán)內(nèi)套環(huán),形成島環(huán)的情況,但是內(nèi)外環(huán)之間不能重疊。MultiPatch

:用于描述三維幾何形體面。幾何構(gòu)件:

路徑(Path)、環(huán)(Ring)、線段(Segment)、三角形帶(TriangleStrip)、三角形扇(TriangleFan)及三角形用于構(gòu)建多段線(polyline)、多邊形(polygon)和多面體(MultiPatch).Polylinescontainpaths,polygonscontainringsandMultiPatchescontainTriangleStrips,TriangleFans,triangles,andrings.Pathsandringsaresequencesofverticesconnectedbysegments.Asegmentisaparametricfunctionthatdefinestheshapeofthecurveconnectingitsvertices.SegmenttypesincludeCircularArc,Line,EllipticArc,andBezierCurve.Envelope:Envelopesdescribethespatialextentofothergeometries,是一個(gè)矩形,它用于表示要素的空間范圍。它覆蓋了幾何對(duì)象的最小坐標(biāo)和最大坐標(biāo)、Z值和M值的變化范圍。

GeometryBags

provideoperationsoncollectionsofgeometries.一個(gè)幾何對(duì)象的每個(gè)頂點(diǎn),除了有XY坐標(biāo)值外,還可以有其它可選屬性,如Z值、M值和ID。IZAwareIMAware

IPointIDAwareIPointpnt=newPointClass()asIPoint;pnt.PutCoords(1,1);IZAwarezAware=pntasIZAware;zAware.ZAware=true;pnt.Z=11.1;Multipoint,polyline,polygon和MultiPatch幾何對(duì)象在它們的幾何形狀上都有約束條件如多邊形的內(nèi)部必須明確定義,且必須與之外部分開。當(dāng)幾何對(duì)象上的所有約束條件都滿足時(shí),我們說(shuō)這個(gè)幾何對(duì)象是簡(jiǎn)單的幾何對(duì)象;當(dāng)有一個(gè)約束條件未滿足或不知道這個(gè)約束條件是否滿足時(shí),我們說(shuō)這個(gè)幾何對(duì)象是非簡(jiǎn)單(non-simple)的幾何對(duì)象。ITopologicalOperator、IPolygon2~I(xiàn)Polygon4和IPolyline2~I(xiàn)Polyline5接口中提供了檢測(cè)和強(qiáng)化幾何對(duì)象簡(jiǎn)單性的操作。幾何對(duì)象,特別是線段類型,有一套豐富的方法用于定義它們的位置。例如,IConstructCircularArc

接口中有不同的方法定義圓弧線段。典型情況下,名字中包含“construct”的接口或方法使用多個(gè)輸入?yún)?shù)來(lái)完全定義目標(biāo)幾何對(duì)象。高級(jí)幾何對(duì)象支持經(jīng)典的集合運(yùn)算來(lái)產(chǎn)生新的幾何對(duì)象,這些集合運(yùn)算包括集合的并(union)、交(intersection)、差(difference)和對(duì)稱差分(symmetricdifference,也即異或運(yùn)算)。這些操作定義在ITopologicalOperator接口中,且通常情況下這些運(yùn)算一次操作兩個(gè)幾何對(duì)象,但其中的ConstructUnion運(yùn)算可作用于多于2個(gè)幾何對(duì)象。高級(jí)幾何對(duì)象還支持IRelationalOperator接口,其中定義了用于檢測(cè)2個(gè)幾何對(duì)象之間的空間關(guān)系方法,如檢測(cè)2個(gè)幾何對(duì)象是否相離(disjoint)、是否相接(touch)、是否包含(contain)等,這些方法返回布爾類型的值。Polyline(多段線)對(duì)象Polyline(多段線)對(duì)象是相連或不相連的路徑對(duì)象的有序集合,它可以分別是單個(gè)路徑、多個(gè)不相連的路徑和多個(gè)相連路徑的集合。路徑(Path)是連續(xù)Segment對(duì)象的集合,除了路徑的第一個(gè)和最后一個(gè)Segment外,每一個(gè)Segment的起始點(diǎn)都是前一個(gè)Segment的終止點(diǎn),即路徑對(duì)象中的Segment不能出現(xiàn)分離的情況。路徑可以是任意數(shù)目的Line、CircularArc、EllipticArc和BezierCurve的組合。一個(gè)或多個(gè)路徑對(duì)象組成一個(gè)Polyline對(duì)象。GeometryCurvePathsPolyCurveBezierCurveCircularArcEllipticArcLinePolylineIscomposedofPathsArecomposedofSegmentsSegmentscanbeof4differentTypesSegmentsPolyline及相關(guān)對(duì)象結(jié)構(gòu)圖PointsareusedtobuildSegmentsorPolylinePointsPolygon對(duì)象Polygon(多邊形)對(duì)象是一個(gè)有序環(huán)對(duì)象的集合,這些環(huán)可以是一個(gè)或者多個(gè)。多邊形對(duì)象通常可以用于描述具有面積的多邊形離散矢量對(duì)象。GeometryCurveRingsPolyCurveBezierCurveCircularArcEllipticArcLinePolygonIscomposedofRingsArecomposedofSegmentsSegmentscanbeof4differentTypesSegmentsPolygon及相關(guān)對(duì)象結(jié)構(gòu)圖PointsareusedtobuildSegmentsorPolygonPointsMultiPatchMultiPatchesdescribe3Dgeometriesthatcanhavemultiple,texturedsurfaces.Theycanalsostorevertexnormals(頂點(diǎn)法線),vertexids,vertexmeasuresandseveralpart-levelattributes.YoucancreateMultiPatchesbyimportingdatafromavarietyofdifferentfileformats(3DStudioMax.3dsfiles,OpenFlight.fltfiles,Sketchup.skpfiles,VRML.wrlfiles).

TriangleStrips

(條、帶)TriangleFans(扇)

RingsasusedinMultiPatchesPoint

andMultiPointPoint幾何對(duì)象IPointpPoint=newPointClass();pPoint.X=100;pPoint.Y=100;MultiPoint幾何對(duì)象構(gòu)建Multipoint對(duì)象//定義第一個(gè)點(diǎn) IPointpPoint1=newPointClass();

pPoint1.X=100;

pPoint1.Y=100;//定義第二個(gè)點(diǎn) IPointpPoint2=newPointClass(); pPoint2.X=200;

pPoint2.Y=200;……//構(gòu)建其他點(diǎn) IPointCollectionpMultipoint=newMultipointClass(); objecto=Type.Missing;//添加第一個(gè)點(diǎn),不需要設(shè)置點(diǎn)的順序,參數(shù)設(shè)置為Type.Missing pMultipoint.AddPoint(pPoint1,refo,refo);//添加第二個(gè)點(diǎn),不需要設(shè)置點(diǎn)的順序,參數(shù)設(shè)置為Type.Missing pMultipoint.AddPoint(pPoint2,refo,refo);

……//添加其他點(diǎn)Segment幾何對(duì)象Path

andRingPath幾何對(duì)象Path是連續(xù)的Segment的集合除第一個(gè)Segment和最后一個(gè)Segment外其余Segment的起始點(diǎn)都是前一個(gè)Segment的終止點(diǎn),即Path對(duì)象的中的Segment不能出現(xiàn)分離Path可以是任意數(shù)的Line,CircularArc,EllipticArc和BezierCurve的組合一個(gè)或多個(gè)Path組成一個(gè)Polyline對(duì)象Path

andRingRing幾何對(duì)象Ring是一個(gè)封閉的Path即起始和終止點(diǎn)有相同的坐標(biāo)值。它有內(nèi)部和外部屬性一個(gè)或多個(gè)Ring對(duì)象組成一個(gè)Polygon對(duì)象Polyline

andPolygonPolyline幾何對(duì)象由一個(gè)或多個(gè)相連或者不相連的path對(duì)象的有序集合可以是單個(gè)Path對(duì)象組成,也可以多個(gè)相連的Path對(duì)象組成,或者是多個(gè)分離的Path組成Polyline

andPolygon

使用IGeometryCollection接口創(chuàng)建一個(gè)Polyline對(duì)象//定義第一個(gè)點(diǎn) IPointpPoint1=newPointClass();

pPoint1.X=100;

pPoint1.Y=100;//定義第二個(gè)點(diǎn) IPointpPoint2=newPointClass();

pPoint2.X=200; pPoint2.Y=200;//創(chuàng)建一個(gè)Line對(duì)象 ILinepLine=newLineClass();//設(shè)置Line對(duì)象的起始終止點(diǎn) pLine.PutCoords(pPoint1,pPoint2);//QI到ISegment ISegmentpSegment=pLineasISegment;//創(chuàng)建一個(gè)Path對(duì)象 ISegmentCollectionpPath=newPathClass(); objecto=Type.Missing;//通過(guò)ISegmentCollection接口為Path對(duì)象添加Segment對(duì)象 pPath.AddSegment(pSegment,refo,refo);//創(chuàng)建一個(gè)Polyline對(duì)象 IGeometryCollectionpPolyline=newPolylineClass();//通過(guò)IGeometryCollection為Polyline對(duì)象添加Path對(duì)象 pPolyline.AddGeometry(pPathasIGeometry,refo,refo);Polyline

andPolygon

Polygon對(duì)象由一個(gè)或多個(gè)Ring對(duì)象的有序集合,它可以由單個(gè)Ring對(duì)象構(gòu)成,也可以使用多個(gè)Ring組成。Ring可以分為OuterRing(外環(huán))和Inner

Ring(內(nèi)環(huán))之分。外環(huán)和內(nèi)環(huán)都是有方向的,它們的區(qū)別是外環(huán)的方向是順時(shí)針的,內(nèi)環(huán)的方向是逆時(shí)針。Polyline

andPolygon//創(chuàng)建一個(gè)Ring對(duì)象,通過(guò)ISegmentCollection接口向其中添加Segment對(duì)象 ISegmentCollectionpSegCollection=newRingClass(); objecto=Type.Missing; pSegCollection.AddSegment(pSegment1,refo,refo); pSegCollection.AddSegment(pSegment2,refo,refo);//QI到IRing接口封閉Ring對(duì)象,使其有效 IRingpRing=pSegCollectionasIRing; pRing.Close();//使用Ring對(duì)象構(gòu)建Polygon對(duì)象 IGeometryCollectionpGeometryColl=newPolygonClass(); pGeometryColl.AddGeometry(pRing,refo,refo);Envelope幾何對(duì)象Envelope是所有幾何對(duì)象的外接矩形,所有的幾何對(duì)象都有一個(gè)Envelope對(duì)象IEnvelope是Envelope對(duì)象的主要接口可以獲取幾何對(duì)象的Xmax,Xmin,Ymax,Ymin,Height,Width等屬性通過(guò)IEnvelope的Expand方法可以按比例縮放Envelope對(duì)象的范圍Curve對(duì)象-1除Point,MultiPoint和Envelope外,其他所有的幾何體都可以看做是Curve(曲線)。Line,Polyline,Polygon,CircularArc,BezierCurve,EllipticArc和CircularArc都是曲線的一種它們都實(shí)現(xiàn)了ICurve接口。Curve對(duì)象-2Length屬性返回一個(gè)Curve對(duì)象的長(zhǎng)度FromPoint和ToPoint屬性獲得Curve對(duì)象的起止點(diǎn)Reverseorientation方法改變Curve對(duì)象的節(jié)點(diǎn)次序IsClosed屬性判斷起始點(diǎn)和終止點(diǎn)是否在一個(gè)位置上GetSubcurve方法復(fù)制一條Curve對(duì)象的特定部分Curve對(duì)象獲取2-5千米處的公路曲線代碼://QI到ICurve接口(PolyLine實(shí)現(xiàn)了ICurVe接口) ICurvepCurve=pPolylineasICurve;//創(chuàng)建一個(gè)Polyline對(duì)象 ICurvepNewCurve=newPolylineClass(); boolbtrue=true;//獲取2-5千米間的曲線對(duì)象 pCurve.GetSubcurve(2,5,btrue,outpNewCurve);Geometry集合接口MultiPoint對(duì)象是點(diǎn)的集合Path對(duì)象是Segment對(duì)象的集合Polyline對(duì)象是Path對(duì)象的集合Polygon對(duì)象是Ring對(duì)象的集合三個(gè)主要的幾何圖形集合接口IPointCollectionISegmentCollectionIGeometryCollectionIGeometryCollection接口IGeometryCollection接口被Polygon,Polyline,Multipoint等實(shí)現(xiàn)Geometry屬性通過(guò)一個(gè)索引值返回組成該幾何對(duì)象的某個(gè)子對(duì)象GeometryCount返回組成該幾何對(duì)象的子對(duì)象的數(shù)目AddGeometry和AddGeometries方法都用于向一個(gè)幾何對(duì)象添加子對(duì)象通過(guò)IGometryCollection創(chuàng)建Polygon時(shí),需使用ITopologicalOperator的Simplify方法保證其有效性。通過(guò)IGeometryCollection創(chuàng)建Polygon對(duì)象privateIPolygonConstructorPolygon(List<IRing>pRingList){try{IGeometryCollectionpGCollection=newPolygonClass();//創(chuàng)建一個(gè)Polygon對(duì)象objecto=Type.Missing;for(inti=0;i<pRingList.Count;i++)//遍歷Ring集合{pGCollection.AddGeometry(pRingList,refo,refo);}//QI至ITopologicalOperatorITopologicalOperatorpTopological=pGCollectionasITopologicalOperator;pTopological.Simplify();//執(zhí)行Simplify操作IPolygonpPolygon=pGCollectionasIPolygon;returnpPolygon;//返回Polygon對(duì)象}catch(ExceptionErr){MessageBox.Show(Err.Message,"提示",MessageBoxButtons.OK,,MessageBoxIcon.Information);returnnull;}}

合并兩個(gè)Polygon對(duì)象為一個(gè)Polgyone對(duì)象privateIPolygonMergePolygons(IPolygonfirstPolygon,IPolygonSecondPolygon){try{IGeometryCollectionpGCollection1=newPolygonClass();//創(chuàng)建一個(gè)Polygon對(duì)象IGeometryCollectionpGCollection2=firstPolygonasIGeometryCollection;IGeometryCollectionpGCollection3=SecondPolygonasIGeometryCollection;pGCollection1.AddGeometryCollection(pGCollection2);//添加firstPolygonpGCollection1.AddGeometryCollection(pGCollection3);//添加SecondPolygonITopologicalOperatorpTopological=pGCollection1asITopologicalOperator;//QI至ITopologicalOperatorpTopological.Simplify();//執(zhí)行Simplify操作IPolygonpPolygon=pGCollection1asIPolygon;returnpPolygon;//返回Polygon對(duì)象}catch(ExceptionErr){MessageBox.Show(Err.Message,"提示",MessageBoxButtons.OK,,MessageBoxIcon.Information);returnnull;}}ISegmentCollection接口被Path,Ring,Polyline和Polygon四個(gè)類所實(shí)現(xiàn),它們被稱作是Segment集合對(duì)象處理組成Segment集合對(duì)象中的每一個(gè)子Segment對(duì)象。為Segment集合對(duì)象添加,插入,刪除Segment子對(duì)象。SetCircle和SetRectangle方法提供了一種簡(jiǎn)單不需要添加Segment的情況下構(gòu)建一個(gè)完成的Path,Ring,Polyline和Polygon的方法。

IPointCollection接口被多個(gè)幾何對(duì)象類所實(shí)現(xiàn):Mullipoint,Path,Ring,Polyline,Polygon等獲取,添加,插入,查詢,移除幾何對(duì)象中的某頂點(diǎn)。AddPoint方法向PointCollection對(duì)象中的特定索引位添加一個(gè)點(diǎn)對(duì)象,如果不指定位置,則添加到最后。Point屬性通過(guò)頂點(diǎn)索引可以得到某一頂點(diǎn)。

幾何對(duì)象小結(jié)空間參考空間參考(SpatialReference)是GIS數(shù)據(jù)的骨骼框架,能夠?qū)⒖臻g數(shù)據(jù)定位到相應(yīng)的位置,為地圖中的每一點(diǎn)提供準(zhǔn)確的坐標(biāo)。Geodatabase中新建一個(gè)要素?cái)?shù)據(jù)集或一個(gè)單獨(dú)的要素類都必須設(shè)置它們的空間參考。

空間參考包括以下屬性:坐標(biāo)系(地理坐標(biāo)系、投影坐標(biāo)系、垂直坐標(biāo)系)分辨率與空間域容差GEOGCS["GCS_Xian_1980",DATUM["D_Xian_1980",SPHEROID["Xian_1980",6378140.0,298.257]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]PROJCS["Xian_1980_3_Degree_GK_Zone_38",GEOGCS["GCS_Xian_1980",DATUM["D_Xian_1980",SPHEROID["Xian_1980",6378140.0,298.257]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Gauss_Kruger"],PARAMETER["False_Easting",38500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",114.0],PARAMETER["Scale_Factor",1.0],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]UsetheSpatialReferenceEnvironmentArcObjects包含大量的預(yù)定義的空間參考系以及空間參考系的構(gòu)建塊(buildingblocks).每個(gè)預(yù)定義的對(duì)象由一個(gè)工廠代碼識(shí)別(afactorycode)。工廠代碼由esriSR開頭的枚舉集合定義,一般使用枚舉宏(enumerationmacro)而不是整數(shù)值來(lái)生成預(yù)定義的對(duì)象。ISpatialReferenceFactory接口提供的方法使用FactoryCode來(lái)生成預(yù)定義的空間參考對(duì)象,這個(gè)接口提供了三種類型的方法:返回單個(gè)對(duì)象的方法返回同類對(duì)象集合的方法基于PRJ文件或PRJ字符串表達(dá)來(lái)導(dǎo)入/導(dǎo)出空間參考對(duì)象的方法privatevoidPrintPreDefinedProjections(){ISpatialReferenceFactoryspatialReferenceFactory=newSpatialReferenceEnvironmentClass();ISetprojectionSet=spatialReferenceFactory.CreatePredefinedProjections();MessageBox.Show("NumberofpredefinedProjections="+projectionSet.Count);projectionSet.Reset();for(inti=0;i<projectionSet.Count;i++){IProjectionprojection=projectionSet.Next()asIProjection;MessageBox.Show(projection.Name);}}privatevoidCreateGeographicCoordinateSystem()

{//SpatialReferenceEnvironmentisasingletonobjectandneedstousetheActivatorclass.

Typet=Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");

System.Objectobj=Activator.CreateInstance(t);

ISpatialReferenceFactorysrFact=objasISpatialReferenceFactory;

//Usetheenumerationtocreateaninstanceofthepredefinedobject.

IGeographicCoordinateSystemgeographicCS=srFact.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_NAD1983);

}單實(shí)例對(duì)象的創(chuàng)建與釋放RuntimecallablewrappersandtheSystem._COMObjecttype在.NET中,每個(gè)類、接口、枚舉類型等通過(guò)其類型進(jìn)行描述。Type類(.NET框架中的類)包含一個(gè)數(shù)據(jù)類型的數(shù)據(jù)成員及函數(shù)成員的有關(guān)信息。當(dāng)在.NET中通過(guò)interop創(chuàng)建COM對(duì)象時(shí),你獲得了該對(duì)象的引用(該對(duì)象被包裝在RCW中)

在.NET應(yīng)用程序內(nèi)部,RCW擁有對(duì)該COM對(duì)象的引用。代碼1:ISimpleMarkerSymbolsym=newSimpleMarkerSymbolClass();Debug.WriteLine(sym.GetType().FullName);運(yùn)行以上代碼時(shí),sym的類型是SimpleMarkerSymbolClass,sym擁有了SimpleMarkerSymbolClass的ISimpleMarkerSymbol的引用。代碼2:ISimpleMarkerSymbolsym=rend.SymbolasISimpleMarkerSymbol;Debug.WriteLine(sym.GetType().FullName);上述代碼中,sym通過(guò)另一個(gè)對(duì)象rend(ISimpleRenderer)的屬性獲得對(duì)一個(gè)RCW(SimpleMarkerSymbol)的引用.分析比較:代碼1中,通過(guò)new關(guān)鍵字創(chuàng)建了一個(gè)SimpleMarkerSymbolClass類型的符號(hào)sym。當(dāng)代碼編譯的時(shí)候,編譯器使用Reflection機(jī)制能夠發(fā)現(xiàn)變量的確切類型,且將該類型的元數(shù)據(jù)保存到編譯后的代碼中。當(dāng)代碼運(yùn)行的時(shí)候,運(yùn)行時(shí)擁有變量類型的所有信息。代碼2中,通過(guò)ISimpleRenderer的Symbol屬性設(shè)置了sym變量的值。當(dāng)代碼編譯的時(shí)候,編譯器能夠發(fā)現(xiàn)的元數(shù)據(jù)只有Symbol屬性返回的對(duì)ISymbol的引用,其對(duì)象的確切類型不能被發(fā)現(xiàn)。

盡管可以使用接口查詢獲得sym變量的ISimpleMarkerSymbol,但代碼運(yùn)行的時(shí)候,運(yùn)行時(shí)沒有所需的元數(shù)據(jù)來(lái)發(fā)現(xiàn)變量的確切類型。在這種情況下,當(dāng)訪問(wèn)Symbol屬性時(shí),.NET運(yùn)行時(shí)將對(duì)COM對(duì)象的引用包裝在通用的RCW:System._ComObject中。System._ComObject是.NET框架內(nèi)部的類,用于引用任何類型的COM對(duì)象,其目的是扮演一個(gè)未知類型的COM對(duì)象的RCW。單實(shí)例對(duì)象僅支持對(duì)象的一個(gè)實(shí)例。當(dāng)使用new關(guān)鍵字實(shí)例化一個(gè)單實(shí)例的COM對(duì)象(singleton)時(shí),如果之前該COM類已經(jīng)實(shí)例化了,你將獲得對(duì)一個(gè)已經(jīng)存在的對(duì)象的引用,而不是又產(chǎn)生一個(gè)實(shí)例對(duì)象。在ArcObjects中,單實(shí)例對(duì)象需要通過(guò)Activator類實(shí)例化,

并需要通過(guò)ComReleaser類明確釋放(explicitrelease)。Typet=Type.GetTypeFromProgID("esriDisplay.ServerStyleGallery");System.Objectobj=Activator.CreateInstance(t);IStyleGallerysg=objasIStyleGallery;privateIProjectedCoordinateSystemLoadProjectedCoordinateSystem(){ISpatialReferenceFactoryspatialReferenceFactory=newSpatialReferenceEnvironmentClass();

IProjectedCoordinateSystemprojectedCoordinateSystem=spatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile("C:\\ProgramFiles\\ArcGIS\\CoordinateSystems\\ProjectedCoordinateSystems\\World\\Mollweide(world).prj")asIProjectedCoordinateSystem;

returnprojectedCoordinateSystem;}privatevoidCreateProjectedCoordinateSystem()

{//SpatialReferenceEnvironmentisasingletonobjectandneedstousetheActivatorclass.

Typet=Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");

System.Objectobj=Activator.CreateInstance(t);

ISpatialReferenceFactorysrFact=objasISpatialReferenceFactory;

//Usetheenumerationtocreateaninstanceofthepredefinedobject.

IProjectedCoordinateSystemprojectedCS=srFact.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_11N);

}CreatingapredefinedverticalcoordinatesystemprivatestaticvoidGetVCSList(){ISpatialReferenceFactory3srFact3=newSpatialReferenceEnvironmentClass()asISpatialReferenceFactory3;

ISetvcsSet=srFact3.CreatePredefinedVerticalCoordinateSystems();vcsSet.Reset();

IVerticalCoordinateSystemvcs;for(inti=0;i<vcsSet.Count;i++){vcs=vcsSet.Next()asIVerticalCoordinateSystem;Console.WriteLine("VCSName:{0}(Code:{1})",vcs.Name,vcs.FactoryCode);}}privatevoidCreateVerticalReferenceSystem(){

ISpatialReferenceFactory3spatialReferenceFactory3=newSpatialReferenceEnvironmentClass();IVerticalCoordinateSystemverticalCoordinateSystem=spatialReferenceFactory3.CreateVerticalCoordinateSystem((int)esriSRVerticalCSType.esriSRVertCS_Alicante);}Creatingacustomgeographiccoordinatesystem地理坐標(biāo)系包含坐標(biāo)系的名稱、角度單位、大地基準(zhǔn)(datum,包含橢球體)及本初子午線(primemeridian)。通過(guò)IGeographicCoordinateSystem2接口提供的屬性、方法可以訪問(wèn)、創(chuàng)建地理坐標(biāo)系的相關(guān)對(duì)象。盡管絕大多數(shù)開發(fā)人員無(wú)須創(chuàng)建自定義的地理坐標(biāo)系,但I(xiàn)GeographicCoordinateSystemEdit

還是提供了Define()及DefineEx()方法.

publicvoidDefine(

refobjectName,refobjectAlias,refobjectAbbreviation,refobjectRemarks,refobjectuseage,refobjectDatum,refobjectPrimeMeridian,refobjectgeographicUnit);publicvoidDefineEx(stringName,stringAlias,stringAbbreviation,stringRemarks,stringuseage,IDatumDatum,IPrimeMeridianPrimeMeridian,IAngularUnitgeographicUnit);privateIGeographicCoordinateSystemCreateGeographicCoordinateSystem()

{ISpatialReferenceFactory3spatialReferenceFactory=newSpatialReferenceEnvironmentClass();

IDatumdatum=spatialReferenceFactory.CreateDatum((int)esriSRDatumType.esriSRDatum_OSGB1936);

IPrimeMeridianprimeMeridian=spatialReferenceFactory.CreatePrimeMeridian((int)esriSRPrimeMType.esriSRPrimeM_Greenwich);

IUnitunit=spatialReferenceFactory.CreateUnit((int)esriSRUnitType.esriSRUnit_Degree);

IGeographicCoordinateSystemEditgeographicCoordinateSystemEdit=newGeographicCoordinateSystemClass();

objectname="UserDefinedGeographicCoordinateSystem";

objectalias="UserDefinedGCS";

objectabbreviation="UserDefined";

objectremarks="UserDefinedGeographicCoordinateSystembasedonOSGB1936";

objectusage="SuitablefortheUK";

objectdatumObject=datumasobject;

objectprimeMeridianObject=primeMeridianasobject;

objectunitObject=unitasobject;geographicCoordinateSystemEdit.Define

(refname,refalias,refabbreviation,refremarks,refusage,refdatumObject,refprimeMeridianObject,refunitObject);

IGeographicCoordinateSystemuserDefinedGeographicCoordinateSystem=geographicCoordinateSystemEditasIGeographicCoordinateSystem;returnuserDefinedGeographicCoordinateSystem;

}Creatingacustomprojectedcoordinatesystem投影坐標(biāo)系的組成部分,如投影(projection)、線性單位、地理坐標(biāo)系等都是對(duì)象,都支持ISpatialReference2

和ISpatialReferenceFactory.

當(dāng)定義定制的投影坐標(biāo)系時(shí),可以使用多種esriSR*枚舉集合中預(yù)定義的對(duì)象。

通過(guò)IProjectedCoordinateSystem5接口提供的屬性、方法可以訪問(wèn)、創(chuàng)建投影坐標(biāo)系相關(guān)對(duì)象。

IProjectedCoordinateSystemEdit

接口中包含了Define(),用于定義定制的投影坐標(biāo)系。publicvoidDefine(

refobject

Name,refobject

Alias,refobject

Abbreviation,refobject

Remarks,refobject

useage,refobject

gcs,refobject

projectedUnit,refobject

Projection,refobject

parameters);ISpatialReferenceFactory

接口中的CreateProjectedCoordinateSystem()方法,可以訪問(wèn)幾百個(gè)預(yù)定義的投影坐標(biāo)系。預(yù)定義的投影坐標(biāo)系包含在esriSRProjCSType,esriSRProjCS2Type,esriSRProjCS3Type,和esriSRProjCS4Type

枚舉類型中。privateIProjectedCoordinateSystemCreateProjectedCoordinateSystem(){ISpatialReferenceFactory2spatialReferenceFactory=newSpatialReferenceEnvironmentClass();

IProjectionGENprojection=spatialReferenceFactory.CreateProjection((int)esriSRProjectionType.esriSRProjection_Sinusoidal)asIProjectionGEN;

IGeographicCoordinateSystemgeographicCoordinateSystem=spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);

ILinearUnitunit=spatialReferenceFactory.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter)asILinearUnit;

IParameter[]parameters=projection.GetDefaultParameters();

IProjectedCoordinateSystemEditprojectedCoordinateSystemEdit=newProjectedCoordinateSystemClass();

objectname="Newfoundland";objectalias="NF_LAB";

objectabbreviation="NF";

objectremarks="MostEasternProvinceinCanada";

objectusage="WhenmakingmapsofNewfoundland";

objectgeographicCoordinateSystemObject=geographicCoordinateSystemasobject;

objectunitObject=unitasobject;

objectprojectionObject=projectionasobject;

objectparametersObject=parametersasobject;projectedCoordinateSystemEdit.Define(refname,refalias,refabbreviation,refremarks,refusage,refgeographicCoordinateSystemObject,refunitObject,refprojectionObject,refparametersObject);returnprojectedCoordinateSystemEditasIProjectedCoordinateSystem;}CreatingacustomverticalcoordinatesystemTheISpatialReferenceFactory3interfaceallowsyoutocreatetheDatum,VerticalDatum,andLinearUnitcomponentparts.ThesecomponentscanalsobecreatedusingasimilarDefinemethodavailableontheirclasses.privateIVerticalCoordinateSystemCreateVerticalCoordinateSystem()

{ISpatialReferenceFactory3spatialReferenceFactory=newSpatialReferenceEnvironmentClass();

IVerticalDatumverticalDatum=spatialReferenceFactory.CreateVerticalDatum((int)esriSRVerticalDatumType.esriSRVertDatum_Taranaki);

IHVDatumhvDatum=verticalDatumasIHVDatum;

ILinearUnitlinearUnit=spatialReferenceFactory.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter)asILinearUnit;

IVerticalCoordinateSystemEditverticalCoordinateSystemEdit=newVerticalCoordinateSystemClass();

objectname="NewVCoordinateSystem";

objectalias="VCoordinateSystemalias";

objectabbreviation="abbr";

objectremarks="Testforoptions";

objectusage="NewZealand";

objecthvDatumObject=hvDatumasobject;

objectunitObject=linearUnitasobject;

objectverticalShift=40asobject;

objectpositiveDirection=-1asobject;verticalCoordinateSystemEdit.Define(refname,refalias,refabbreviation,refremarks,refusage,refhvDatumObject,refunitObject,refverticalShift,refpositiveDirection);

IVerticalCoordinateSystemverticalCoordinateSystem=verticalCoordinateSystemEditasIVerticalCoordinateSystem;returnverticalCoordinateSystem;

}privateIVerticalCoordinateSystemCreateEllipsoidBasedVerticalCoordinateSystem()

{ISpatialReferenceFactory3spatialReferenceFactory=newSpatialReferenceEnvironmentClass();

IDatumdatum=spatialReferenceFactory.CreateDatum((int)esriSRDatumType.esriSRDatum_WGS1984);

IHVDatumhvDatum=datumasIHVDatum;

ILinearUnitlinearUnit=spatialReferenceFactory.CreateUnit((int)esriSRUnitType.esriSRUnit_Foot)asILinearUnit;

IVerticalCoordinateSystemEditverticalCoordinateSystemEdit=newVerticalCoordinateSystemClass();

objectname="WGS84vcs";

objectalias="WGS84ellipsoid";

objectabbreviation="w843d";

objectremarks="WGS84ell-basedvcs";

objectusage="everywhere!";

objecthvDatumObject=hvDatumasobject;

objectunitObject=linearUnitasobject;

objectverticalShift=0.4839asobject;

objectpositiveDirection=-1asobject;verticalCoordinateSystemEdit.Define(refname,refalias,refabbreviation,refremarks,refusage,refhvDatumObject,refunitObject,refverticalShift,refpositiveDirection);

IVerticalCoordinateSystemverticalCoordinateSystem=verticalCoordinateSystemEditasIVerticalCoordinateSystem;returnverticalCoordinateSystem;

}地理變換(Geotransformation)地理變換是一種數(shù)學(xué)運(yùn)算,它將點(diǎn)的坐標(biāo)從一個(gè)地理坐標(biāo)系變換到另一個(gè)地理坐標(biāo)系,也可以逆變換。地理變換包含名稱、2個(gè)地理坐標(biāo)系(源、目標(biāo)地理坐標(biāo)系)、變換的方法或類型、方法所需的任何參數(shù),每一種變換的方法或類型都是一個(gè)類。AO提供了以下類型的變換:

Geotransformationinterfaces地理變換類上的接口允許設(shè)置變換所需的參數(shù)。高精度參考網(wǎng)絡(luò)(HARN)、北美基準(zhǔn)轉(zhuǎn)換(NADCON)以及國(guó)家地理變換版本2(NTv2)是基于網(wǎng)格的地理變換,它們使用磁盤上的文件來(lái)計(jì)算數(shù)據(jù)的平移;使用IGridTransformation接口訪問(wèn)

磁盤上的信息,使用IGeoTransformation接口設(shè)置源和目標(biāo)空間參考。IGeometry2中的ProjectEx()方法有一個(gè)esriTransformDirection類型的參數(shù)

,當(dāng)?shù)乩碜儞Q的方向?yàn)樵纯臻g參考到目標(biāo)空間參考時(shí),將該參數(shù)設(shè)置為esriTransformForward;當(dāng)?shù)乩碜儞Q的方向?yàn)榉捶较驎r(shí),將該參數(shù)設(shè)置為esriTransformReverse.要訪問(wèn)預(yù)定義的地理變換,可以使用ISpatialReferenceFactory

中的CreateGeoTransformation()方法。預(yù)定義的地理變換由esriSRGeoTransformationType,esriSRGeoTransformation2Type,及esriSRGeoTransformation3Type

枚舉類型定義。CompositeGeoTransformation是多步驟的地理變換。地理變換中,當(dāng)需要使用中間過(guò)渡地理坐標(biāo)系時(shí),使用ICompositeGeoTransformation

接口。例如,北京54坐標(biāo)系與西安80坐標(biāo)系之間,不能直接轉(zhuǎn)換,但可以通過(guò)中間過(guò)渡地理坐標(biāo)系WGS84,間接轉(zhuǎn)換。privateIGeoTransformationCreateGeoTransformation(){TypefactoryType=Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");System.Objectobj=Activator.CreateInstance(factoryType);

ISpatialReferenceFactory2pSRF=objasISpatialReferenceFactory2;

IProjectedCoordinateSystem2pPCSin=(IProjectedCoordinateSystem2)pSRF.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_Abidjan1987UTM_30N);

IProjectedCoordinateSystem2pPCSout=(IProjectedCoordinateSystem2)pSRF.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_WGS1984UTM_30N);

IGeographicCoordinateSystem2pGCSfrom=(IGeographicCoordinateSystem2)pPCSin.GeographicCoordinateSystem;IGeographicCoordinateSystem2pGCSto=(IGeographicCoordinateSystem2)pPCSout.GeographicCoordinateSystem;ICoordinateFrameTransformationpCFT=newCoordinateFrameTransformationClass();pCFT.PutParameters(1.234,-2.345,658.3,4.3829,-2.48591,2.18943,2.48585);pCFT.PutSpatialReferences(pGCSfrom,pGCSto);pCFT.Name="CustomGeoTran";returnpCFTasIGeoTransformation;

}UsingtheIGeometry.Project/IGeometry2.ProjectExmethodDothefollowingstepstousethe

IGeometry.Projectmethod:Createa

spatialreferencefactory.Usethecreatedspatialreferencefactoryto

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論