Exemplo n.º 1
0
        /// <summary>
        /// populate all the grid cells between two consecutive intersections with shape's value
        /// </summary>
        private bool ScanLine2(System.Collections.ArrayList vettore, double xref,
            ref System.Collections.ArrayList pixels, ref MapWinGIS.Grid gr, MapWinGIS.GridHeader header,
            object value, MapWinGIS.ICallback cback)
        {
            bool result = false;
            bool control;
            double yll, ystart, yend, ycellstart;
            double pxsize;
            int c, r, v;
            r = 0;
            GridPixel curPx;

            control = false;
            yll = header.YllCenter;
            pxsize = header.dX;

            ystart = 0;
            for (v = vettore.Count - 1; v >= 0; --v)
            {
                if (control == false)
                {
                    ystart = (double)vettore[v];
                    control = true;
                }
                else
                {
                    yend = (double)vettore[v];
                    ycellstart = FirstLineXY(ystart, yll, pxsize, -1);

                    do
                    {
                        gr.ProjToCell(xref, ycellstart, out c, out r);
                        curPx.col = c;
                        curPx.row = r;
                        pixels.Add(curPx);
                        ycellstart = ycellstart - pxsize;
                    }
                    while (ycellstart >= yend);
                    control = false;
                }
            }
            return result;
        }
Exemplo n.º 2
0
        private bool Multipoint2Grid(MapWinGIS.Shapefile MultipointSf, int FldID, MapWinGIS.Grid Newgrd,
            MapWinGIS.GridHeader header, MapWinGIS.GridDataType grType, MapWinGIS.ICallback cback)
        {
            //count the number of shapes
            int s, p;
            MapWinGIS.Shape shp;
            MapWinGIS.Point pt;
            ArrayList pixels = new ArrayList();
            object val;
            GridPixel px;
            int nShps = MultipointSf.NumShapes;
            int nPts = 0;
            int perc = 1;
            int shpsPerc = NumPercentShapes(perc, nShps); //percent of progress

            for (s = 0; s < nShps; ++s)
            {
            //get the shape
            shp = MultipointSf.get_Shape(s);

            //exclude shapes which are completely outside of the grid extents
            if (!IsGridContainsShape(shp, header))
            {
                continue;
            }

            //get the shape's value
            val = GetCellValue(MultipointSf, FldID, s, header.NodataValue);

            nPts = shp.numPoints;
            for (p = 0; p < nPts; ++p)
            {
                //write pixel values
                pt = shp.get_Point(p);
                Newgrd.ProjToCell(pt.x, pt.y, out px.col, out px.row);
                pixels.Add(px);
                writePxList(Newgrd, grType, pixels, val, cback);
            }

            //report the progress
            if (s >= shpsPerc)
            {
                reportProgress(shpsPerc, nShps, "shapefile to grid", cback);
                perc = (int)((s * 100) / nShps);
                shpsPerc = NumPercentShapes(perc + 1, nShps);
            }
            }
            return true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// convert point shapefile to grid
        /// </summary>   
        private bool Point2Grid(MapWinGIS.Shapefile PointSf, int FldID, MapWinGIS.Grid Newgrd,
            MapWinGIS.GridHeader header, MapWinGIS.GridDataType grType, MapWinGIS.ICallback cback)
        {
            //count the number of shapes
            int s;
            MapWinGIS.Shape shp;
            MapWinGIS.Point pt = new MapWinGIS.Point();
            object val;
            GridPixel px;
            int nShps = PointSf.NumShapes;
            int perc = 1;
            int shpsPerc = NumPercentShapes(perc, nShps); //percent of progress

            for (s = 0; s < nShps; ++s)
            {
            //get the point
            shp = PointSf.get_Shape(s);

            //exclude shapes which are completely outside of the grid extents
            if (!IsGridContainsShape(shp, header))
            {
                continue;
            }

            if (shp.numPoints > 0)
            {
                pt = shp.get_Point(0);
                if (pt != null)
                {
                    //return the shape's value and write the pixel
                    val = GetCellValue(PointSf, FldID, s, header.NodataValue);
                    Newgrd.ProjToCell(pt.x, pt.y, out px.col, out px.row);
                    writePx(Newgrd, grType, px, val, cback);
                }
            }

            //report the progress
            if (s >= shpsPerc)
            {
                perc = (int)((s * 100) / nShps);
                shpsPerc = NumPercentShapes(perc + 1, nShps);
                reportProgress(shpsPerc, nShps, "shapefile to grid", cback);
            }
            }
            return true;
        }
Exemplo n.º 4
0
        /// <summary>
        /// converts a Line shapefile to grid using Bresenham algorithm
        /// </summary>
        /// <param name="PolySf">Polygon shapefile object</param>
        /// <param name="FldID">Field index</param>
        /// <param name="Newgrd">New grid object</param>
        /// <param name="header">Grid header</param>
        /// <param name="nodatavalue"></param>
        /// <param name="cback">optional, for reporting progress</param>
        /// <returns>true if successful</returns>
        private bool Line2Grid(MapWinGIS.Shapefile LineSf, int FldID, MapWinGIS.Grid Newgrd,
            MapWinGIS.GridHeader header, MapWinGIS.GridDataType grType, MapWinGIS.ICallback cback)
        {
            int numParts, numPoints;
            int curPartStart, curPartEnd, vertexCol, vertexRow, lastCol, lastRow;
            int nShps = LineSf.NumShapes;
            int perc = 1;
            int shpsPerc = NumPercentShapes(perc, nShps); //percent of progress
            int s = 0; //shape number
            int p = 0; //part number
            int k = 0; //point number
            MapWinGIS.Shape LineShp = new MapWinGIS.Shape();
            MapWinGIS.Point curPoint;
            //Rasterization ras = new Rasterization(); //rasterization class, contains the code of
            //lineToGrid methods independent on MapWinGIS functions
            ArrayList vertices = new ArrayList(); //list of line vertex points
            ArrayList pixels = new ArrayList();   //list of calculated pixels on the line
            GridPixel px;

            object val; //the shape's value

            for (s = 0; s < nShps; ++s)
            {
            LineShp = LineSf.get_Shape(s);
            numParts = LineShp.NumParts;
            numPoints = LineShp.numPoints;

            //exclude shapes which are completely outside of the grid extents
            if (!IsGridContainsShape(LineShp, header))
            {
                continue;
            }

            //get the shape's value
            val = GetCellValue(LineSf, FldID, s, header.NodataValue);

            //process each part of the polyline
            curPartStart = 0;
            for (p = 0; p < numParts; ++p)
            {
                vertices.Clear();
                pixels.Clear();

                curPartStart = LineShp.get_Part(p);

                // check for multi-part lines
                if (p < numParts - 1)
                {
                    curPartEnd = LineShp.get_Part(p + 1) - 1;
                }
                else
                {
                    curPartEnd = numPoints - 1;
                }

                //go to next part if there's zero points
                if (numPoints <= 0)
                {
                    continue;
                }

                // add all points of current part to rasterization list
                // always add the first point of the part (convert its coordinates to
                // grid row and column)
                curPoint = LineShp.get_Point(curPartStart);
                Newgrd.ProjToCell(curPoint.x, curPoint.y,
                        out vertexCol, out vertexRow);
                px.col = vertexCol;
                px.row = vertexRow;
                vertices.Add(px);
                lastCol = vertexCol; lastRow = vertexRow;

                // add all other points with different grid coordinates
                for (k = curPartStart + 1; k <= curPartEnd; ++k)
                {
                    // (check if it has a different row or column than the previous point)
                    curPoint = LineShp.get_Point(k);
                    Newgrd.ProjToCell(curPoint.x, curPoint.y,
                        out vertexCol, out vertexRow);
                    if (vertexCol != lastCol || vertexRow != lastRow)
                    {
                        px.col = vertexCol;
                        px.row = vertexRow;
                        vertices.Add(px);
                        lastCol = vertexCol;
                        lastRow = vertexRow;
                    }
                }

                // convert the polyline and write pixels to grid
                LineBresenham(vertices, pixels);
                writePxList(Newgrd, grType, pixels, val, cback);

            }

            //report the progress
            if (s >= shpsPerc)
            {
                reportProgress(shpsPerc, nShps, "shapefile to grid", cback);
                perc = (int)((s * 100) / nShps);
                shpsPerc = NumPercentShapes(perc + 1, nShps);
            }
            }
            return true;
        }