2

有没有人使用.Net 拓扑套件?我有点卡住了,我正在尝试获取信封,以便验证尺寸

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

我正在采用 IGeometry 类型(边界)并将该多边形的包络投射到 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();)?

4

2 回答 2

4

我也面临同样的问题。这是 API 开发人员使用奇怪的 Envelope 命名约定的问题。IGeometry.Envelope实际上是一个 IGeometry 对象。您应该改为使用IGeometry.EnvelopeInternal

IGeometry boundary;

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

IEnvelope envelope = boundary.EnvelopeInternal;
于 2012-08-07T11:42:35.533 回答
1

我不确定 OSGBGeometryFactory.Factory 做了什么,因为读者通常需要一些 WKT。这是一个执行您想要的示例的示例,其中 WKT 是通过在 postgis 中缓冲一个点来创建的,值得一提。

        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);
于 2012-05-09T12:30:51.447 回答