简体   繁体   English

在C#中使用arcobjects在多边形内创建随机点?

[英]Create a random point within a polygon using arcobjects in C#?

Im trying to create a function in C# that would return a random IPoint feature that whould be within a selected polygon, but I'm complete buffed on how to proceed. 我试图在C#中创建一个函数,该函数将返回一个随机的IPoint功能,该功能将在选定的多边形内,但是我对如何进行操作完全满意。

Ideally the definiotion of the function would like bellow: 理想情况下,该函数的定义应如下所示:

public IPoint Create_Random_Point(IGeometry inGeom)

There is a geoprocessing tool called CreateRandomPoints which can be used to generate points within a particular boundary (for example within the window extent, within a polygon, or along a line). 有一个名为CreateRandomPoints的地理处理工具,可用于生成特定边界内的点(例如,在窗口范围内,多边形内或沿线)。 Have a look: 看一看:

http://resources.arcgis.com/en/help/arcobjects-java/api/arcobjects/com/esri/arcgis/geoprocessing/tools/datamanagementtools/CreateRandomPoints.html http://resources.arcgis.com/zh-CN/help/arcobjects-java/api/arcobjects/com/esri/arcgis/geoprocessing/tools/datamanagementtools/CreateRandomPoints.html

Geoprocessing tools are fairly easy to implement into arcobjects code, but can sometimes be a little slow to execute. 地理处理工具相当容易实现到arcobjects代码中,但是有时执行起来会有些慢。

Just for future reference I created a custom function that tries to find a random point within the extends of the polgon. 仅供以后参考,我创建了一个自定义函数,该函数尝试在polgon的延伸范围内查找随机点。

 private double GetRandomDouble(double Min, double Max)
        {
            //TODO:
            // seed
            Random random = new Random();
            return random.NextDouble() * (Max - Min) + Min;
        }



private IPoint Create_Random_Point(IGeometry inGeom)
        {

                double x = GetRandomDouble(inGeom.Envelope.XMin, inGeom.Envelope.XMax);
                double y = GetRandomDouble(inGeom.Envelope.YMin, inGeom.Envelope.YMax);


                IPoint p = new PointClass();
                p.X = x;
                p.Y = y;

                return p;
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM