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.

Ideally the definiotion of the function would like bellow:

public IPoint Create_Random_Point(IGeometry inGeom)
有帮助吗?

解决方案 2

Just for future reference I created a custom function that tries to find a random point within the extends of the 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;
        }

其他提示

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). Have a look:

http://resources.arcgis.com/en/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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top