Example #1
0
        public LatLng GetLocation(int?regionId)
        {
            RegionServices regSrv  = new RegionServices();
            var            regions = regSrv.Get(new RegionModel()
            {
                RegionId = regionId
            });
            var regions2 = new List <RegionModel>();

            foreach (var r in regions)
            {
                RegionShape shape = new RegionShape(r.Coordenates.ToArray());
                shape.CutEar();
                for (int i = 0; i < shape.NumberOfPolygons; i++)
                {
                    var reg = new RegionModel();
                    reg.Coordenates = new List <LatLng>();
                    int nPoints = shape.Polygons(i).Length;
                    for (int j = 0; j < nPoints; j++) //Triangulo
                    {
                        reg.Coordenates.Add(new LatLng()
                        {
                            Lat = shape.Polygons(i)[j].Lat, Lng = shape.Polygons(i)[j].Lng
                        });
                    }
                    regions2.Add(reg);
                }
            }
            var tRandom = regions2[new Random().Next((regions2.Count - 1))];

            return(getRandomPoint(getAreaTriangule(tRandom.Coordenates[0], tRandom.Coordenates[1], tRandom.Coordenates[2]),
                                  tRandom.Coordenates[0], tRandom.Coordenates[1], tRandom.Coordenates[2]));//tRandom.Coordenates.ToArray().GetCentroid();
        }
Example #2
0
        public ActionResult Regions()
        {
            RegionServices regSrv   = new RegionServices();
            var            regions  = regSrv.Get(new RegionModel());
            var            regions2 = new List <RegionModel>();

            foreach (var r in regions)
            {
                RegionShape shape = new RegionShape(r.Coordenates.ToArray());
                shape.CutEar();
                for (int i = 0; i < shape.NumberOfPolygons; i++)
                {
                    var reg = new RegionModel();
                    reg.Coordenates = new List <LatLng>();
                    int nPoints = shape.Polygons(i).Length;
                    for (int j = 0; j < nPoints; j++)
                    {
                        reg.Coordenates.Add(new LatLng()
                        {
                            Lat = shape.Polygons(i)[j].Lat, Lng = shape.Polygons(i)[j].Lng
                        });
                    }
                    regions2.Add(reg);
                }
            }
            RegionServices vesSrv   = new RegionServices();
            var            location = vesSrv.GetLocation(1);

            return(Json(regions2));
        }