1

I am working on GIS based desktop application using C#. I am using dotspatial library in this project.

Now I need to create a grid of features on polygon. This grid cell (rectangle) should be 20*20 Meter Square.

I have worked on it and able to create grid but facing issue regarding to cell size. Whenever polygon size changed cell size also reduced. My code.

         // Polygon Width = 2335
        // Polygon Height = 2054

        int RowsCount = 111;
        int ColumnsCount = 111;

        var maxPointX = Polygon.Extent.MaxPointX;
        var minPointX = Polygon.Extent.MinPointX;

        var maxPointY = Polygon.Extent.MaxPointY;
        var minPointY = Polygon.Extent.MinPointY;

        var dXStep = (maxPointX - minPointX) / (ColumnsCount - 1);
        var dYStep = (maxPointY - minPointY) / (RowsCount - 1);

        var gridColumnsPoints = new double[1000000];
        var gridRowPoints = new double[1000000];

        //   Calculate the coordinates of grid
        var nextPointX = minPointX;

        for (int i = 1; i <= ColumnsCount; i++)
        {
            gridColumnsPoints[i - 1] = nextPointX;
            nextPointX = nextPointX + dXStep;
        }

        var nextPointY = minPointY;

        for (int i = 1; i <= RowsCount; i++)
        {
            gridRowPoints[i - 1] = nextPointY;
            nextPointY = nextPointY + dYStep;
        }

Output enter image description here

Now when I tried this code on small size of Polygon then grid cell size also decreased.

enter image description here

I know my approach is not correct, So I have searched on it and got some tools. like

Creating spatially projected polygon grid with ArcMap?

But I want to create it in C# and unable to found any algorithm or any other helping material.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.