public SarfController()
 {
     sarfDao = new SarfDao();
 }
Ejemplo n.º 2
0
        private int GenerateHubs(Polygon polygon)
        {
            try
            {
                var polyArray = GeneratePolyArray(polygon.Vertices);
                SetCoordinates(polygon.Vertices);
                List <LatLong> latLongs = new List <LatLong>();

                decimal hubLat;
                decimal hubLong;
                decimal latAddSub;
                decimal longAddSub;
                decimal decMidLat  = (decMinLat + decMaxLat) / 2;
                decimal decMidLong = (decMinLong + decMaxLong) / 2;

                //for (decimal latDivider = 0.1M, longDivider = 0.1M;
                //latDivider <= 0.9M && longDivider <= 0.9M;
                //latDivider += 0.15M, longDivider += 0.15M)
                for (decimal latDivider = 0.1M; latDivider <= 0.6M; latDivider += 0.2M)
                {
                    for (decimal longDivider = 0.2M; longDivider <= 0.8M; longDivider += 0.3M)
                    {
                        //Top Left
                        latAddSub  = (decMaxLat - decMidLat) * latDivider;
                        longAddSub = (decMaxLong - decMidLong) * longDivider;
                        hubLat     = decMidLat + latAddSub;
                        hubLong    = decMidLong + longAddSub;
                        latLongs.Add(new LatLong()
                        {
                            Latitude = hubLat, Longitude = hubLong
                        });

                        //Botton Left
                        latAddSub  = (decMidLat - decMinLat) * latDivider;
                        hubLat     = decMidLat - latAddSub;
                        longAddSub = (decMaxLong - decMidLong) * longDivider;
                        hubLong    = decMidLong + longAddSub;
                        latLongs.Add(new LatLong()
                        {
                            Latitude = hubLat, Longitude = hubLong
                        });

                        //Botton Right
                        latAddSub  = (decMidLat - decMinLat) * latDivider;
                        hubLat     = decMidLat - latAddSub;
                        longAddSub = (decMidLong - decMinLong) * longDivider;
                        hubLong    = decMidLong - longAddSub;
                        latLongs.Add(new LatLong()
                        {
                            Latitude = hubLat, Longitude = hubLong
                        });

                        ////Top Right
                        //latAddSub = (decMidLat - decMinLat) * latDivider;
                        //hubLat = decMidLat + latAddSub;
                        //longAddSub = (decMidLong - decMinLong) * longDivider;
                        //hubLong = decMidLong - longAddSub;
                        //latLongs.Add(new LatLong() { Latitude = hubLat, Longitude = hubLong });
                    }
                }

                for (decimal latDivider = 0.4M; latDivider <= 0.9M; latDivider += 0.3M)
                {
                    for (decimal longDivider = 0.3M; longDivider <= 0.9M; longDivider += 0.35M)
                    {
                        //Top Left
                        latAddSub  = (decMaxLat - decMidLat) * latDivider;
                        longAddSub = (decMaxLong - decMidLong) * longDivider;
                        hubLat     = decMidLat + latAddSub;
                        hubLong    = decMidLong + longAddSub;
                        latLongs.Add(new LatLong()
                        {
                            Latitude = hubLat, Longitude = hubLong
                        });

                        //Botton Left
                        //latAddSub = (decMidLat - decMinLat) * latDivider;
                        //hubLat = decMidLat - latAddSub;
                        //longAddSub = (decMaxLong - decMidLong) * longDivider;
                        //hubLong = decMidLong + longAddSub;
                        //latLongs.Add(new LatLong() { Latitude = hubLat, Longitude = hubLong });

                        //Botton Right
                        latAddSub  = (decMidLat - decMinLat) * latDivider;
                        hubLat     = decMidLat - latAddSub;
                        longAddSub = (decMidLong - decMinLong) * longDivider;
                        hubLong    = decMidLong - longAddSub;
                        latLongs.Add(new LatLong()
                        {
                            Latitude = hubLat, Longitude = hubLong
                        });

                        //Top Right
                        latAddSub  = (decMidLat - decMinLat) * latDivider;
                        hubLat     = decMidLat + latAddSub;
                        longAddSub = (decMidLong - decMinLong) * longDivider;
                        hubLong    = decMidLong - longAddSub;
                        latLongs.Add(new LatLong()
                        {
                            Latitude = hubLat, Longitude = hubLong
                        });
                    }
                }

                sarfDao      = new SarfDao();
                pointsToDraw = new List <List <decimal> >();
                var sortedList = new List <List <decimal> >();
                foreach (var item in latLongs)
                {
                    point = new List <decimal>();
                    point.Add(item.Longitude);
                    point.Add(item.Latitude);
                    bool isValid = isPointInside(point, polyArray);
                    if (isValid)
                    {
                        pointsToDraw.Add(point);
                    }
                }
                sortedList   = pointsToDraw.OrderBy(p => p[0]).ToList();
                pointsToDraw = sortedList;
                int nodeCount = SaveHubs(pointsToDraw, polygon);
                return(nodeCount);
            }
            catch (Exception ex)
            {
                return(0);
            }
        }