有没有人使用.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类型(我的边界变量),为什么当我尝试投射它时它是null。
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();
)?
答案 0 :(得分: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;
答案 1 :(得分: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);