Esempio n. 1
0
    private void FillAllContours()
    {
        var contoursTool = ComponentManager.Instance.GetOrNull <ContoursTool>();

        if (contoursTool == null)
        {
            return;
        }

        ContoursMapLayer contoursLayer = contoursTool.ContoursLayer;

        if (contoursLayer != null)
        {
            var pg = planningLayer.Grid;
            var cg = contoursLayer.Grid;

            double planningResolutionX = pg.countX / (pg.east - pg.west);
            double planningResolutionY = pg.countY / (pg.south - pg.north);

            double invResolutionX = (cg.east - cg.west) / cg.countX;
            double invResolutionY = (cg.north - cg.south) / cg.countY;

            double coordsOffsetX = cg.west + 0.5 * invResolutionX;
            double coordsOffsetY = cg.north - 0.5 * invResolutionY;

            double scaleX = planningResolutionX * invResolutionX;
            double scaleY = planningResolutionY * invResolutionY;

            double offsetX = (cg.west - pg.west) * planningResolutionX + 0.5 * scaleX;
            double offsetY = (cg.north - pg.north) * planningResolutionY - 0.5 * scaleY;

            Coordinate coords;

            int contoursCount = cg.values.Length;
            for (int i = 0; i < contoursCount; i++)
            {
                float contoursValue = cg.values[i];
                if (contoursValue != 0)
                {
                    int y = i / cg.countX;
                    int x = i - y * cg.countX;

                    coords.Longitude = coordsOffsetX + x * invResolutionX;
                    coords.Latitude  = coordsOffsetY - y * invResolutionY;

                    x = (int)Math.Floor(offsetX + x * scaleX);
                    y = (int)Math.Floor(offsetY - y * scaleY);
                    if (x >= 0 && x <= pg.countX && y >= 0 && y <= pg.countY)
                    {
                        int index = y * pg.countX + x;
                        planner.ChangeTypology(index, x, y, coords);
                    }
                }
            }

            planner.FinishChangingTypologies();
        }
    }