2012-05-08 54 views
1

有沒有人使用.Net拓撲套件? 我有點卡住,我試圖讓信封,所以我可以確認尺寸使用.Net拓撲套件從IGeometry類型獲取IEnvelope

根據http://resources.esri.com/help/9.3/arcgisengine/dotnet/c6e6b26c-be52-4176-b1e5-bb628d10acd0.htm(使用頁面底部的C#示例)

我正在和IGeometry類型(邊界)和流延多邊形的信封與我希望能看一下width和height屬性

但信封的IEnvelope(信封)總是空

IGeometry boundary; 

    var wktReader = new WKTReader(OSGBGeometryFactory.Factory); 
    boundary = wktReader.Read(projectDTO.BoundaryWKT); 

    IEnvelope envelope = boundary.Envelope as IEnvelope; 

任何人的幫助,這是我第一次與這個套件。


我正在試圖找出是,如果下面的這個例子,我已經有一個IGeometry類型(我的邊界變量)爲什麼是空當我嘗試投它。

using ESRI.ArcGIS.Geometry; 

class temp 
{ 
    public void test() 
    { 
    // Create an empty polygon object. 
    IArea areaPolygon = new PolygonClass(); 

    // Cast to the IGeometry interface of the polygon object. 
    IGeometry geometryPolygon = (IGeometry)areaPolygon; 

    // Use the .Envelope property on the IGeometry interface of the 
    // polygon object to get an envelope object. 
    IEnvelope envelope = geometryPolygon.Envelope; 

    // Test to make sure you have an envelope object. 
    if (envelope is Envelope) 
    { 
     // The polygon object and resulting envelope are empty. 
     if (envelope.IsEmpty) 
     { 
     System.Windows.Forms.MessageBox.Show("The envelope is empty."); 
     } 
    } 
    } 
} 

我需要創建一個新的多邊形,並嘗試流延(即複製IArea areaPolygon = new PolygonClass();)?

回答

1

我不確定OSGBGeometryFactory.Factory會做什麼,因爲讀者通常需要一些WKT。下面是一個例子,它通過緩衝postgis中的一個點來創建WKT,它的價值是什麼。

 WKTReader rdr = new WKTReader(); 
     Polygon poly =(Polygon) rdr.Read(
       "POLYGON((10 0,9.23879532511287 -3.82683432365089,7.07106781186548 -7.07106781186547,3.82683432365091 -9.23879532511286,1.61554255216634e-14 -10,-3.82683432365088 -9.23879532511287,-7.07106781186546 -7.07106781186549,-9.23879532511286 -3.82683432365092,-10 -3.23108510433268e-14,-9.23879532511288 3.82683432365086,-7.0710678118655 7.07106781186545,-3.82683432365094 9.23879532511285,-4.62458305157398e-14 10,3.82683432365085 9.23879532511289,7.07106781186544 7.07106781186551,9.23879532511284 3.82683432365095,10 0))"); 
     GeoAPI.Geometries.ICoordinate [] coords = poly.Envelope.Coordinates; 
     double width = coords[2].X - coords[0].X; 
     double height = coords[2].Y - coords[0].Y; 

     Console.WriteLine("width={0:f}, height={1:f}", width, height); 
3

我也面臨同樣的問題。這是API開發人員爲Envelope使用一種奇怪的命名約定的問題。 IGeometry.Envelope實際上是一個IGeometry對象。您應改爲使用IGeometry.EnvelopeInternal

IGeometry boundary; 

var wktReader = new WKTReader(OSGBGeometryFactory.Factory); 
boundary = wktReader.Read(projectDTO.BoundaryWKT); 

IEnvelope envelope = boundary.EnvelopeInternal;