Esempio n. 1
0
        public List <Orchestrator.WebUI.Services.Point> GetConcentricCirclesForLatLong(Orchestrator.WebUI.Services.Point selectedPoint)
        {
            List <Orchestrator.WebUI.Services.Point> points = new List <Orchestrator.WebUI.Services.Point>();

            points.Add(selectedPoint);

            try
            {
                SqlGeography position = this.BuildGeography(new List <LatLong>()
                {
                    new LatLong()
                    {
                        Latitude = selectedPoint.Latitude, Longitude = selectedPoint.Longitude
                    }
                }, OpenGisGeographyType.Point);

                List <KeyValuePair <int, double> > distances = new List <KeyValuePair <int, double> >();

                double metresPerMile          = 1609.344;
                KeyValuePair <int, double> cc = new KeyValuePair <int, double>(1, (metresPerMile / 2));
                distances.Add(cc);

                for (int i = 1; i <= 2; i++)
                {
                    KeyValuePair <int, double> tc = new KeyValuePair <int, double>(Convert.ToInt32(5 * Math.Pow(2, i - 1)), (5 * Math.Pow(2, i - 1)) * (metresPerMile));// / 2));
                    distances.Add(tc);
                }

                foreach (KeyValuePair <int, double> kvp in distances)
                {
                    SqlGeography sqlGeofence = position.STBuffer(kvp.Value);

                    Orchestrator.WebUI.Services.Point point = new Orchestrator.WebUI.Services.Point();
                    point.GeofencePoints = new List <LatLong>();
                    point.Description    = kvp.Key.ToString();
                    point.Latitude       = selectedPoint.Latitude;
                    point.Longitude      = selectedPoint.Longitude;

                    for (int i = 0; i < sqlGeofence.STNumPoints(); i++)
                    {
                        SqlGeography p       = sqlGeofence.STPointN(i + 1);
                        LatLong      latLong = new LatLong();
                        latLong.Latitude  = (double)p.Lat;
                        latLong.Longitude = (double)p.Long;
                        point.GeofencePoints.Add(latLong);
                    }

                    points.Add(point);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(points);
        }
Esempio n. 2
0
        public List <Orchestrator.WebUI.Services.Point> GetPointsPenetrated(List <LatLong> latLongs)
        {
            List <Orchestrator.WebUI.Services.Point> points = new List <Orchestrator.WebUI.Services.Point>();

            if (latLongs.Count > 0)
            {
                SqlGeographyBuilder geogBuilder = new SqlGeographyBuilder();
                geogBuilder.SetSrid(4326);
                geogBuilder.BeginGeography(OpenGisGeographyType.LineString);

                LatLong firstLatLong       = null;
                bool    firstLatLongStored = false;
                foreach (LatLong latLong in latLongs)
                {
                    if (!firstLatLongStored)
                    {
                        firstLatLong = latLong;
                        geogBuilder.BeginFigure(firstLatLong.Latitude, firstLatLong.Longitude);
                        firstLatLongStored = true;
                    }
                    else
                    {
                        geogBuilder.AddLine(latLong.Latitude, latLong.Longitude);
                    }
                }

                //geogBuilder.AddLine(firstLatLong.Latitude, firstLatLong.Longitude); //Note: Last Point same as First
                geogBuilder.EndFigure();

                geogBuilder.EndGeography();
                SqlGeography rectangle = null;

                try
                {
                    rectangle = geogBuilder.ConstructedGeography;
                }
                catch (Exception ex)
                {
                    //SqlGeometryBuilder gb = new SqlGeometryBuilder();
                    //gb.SetSrid(4326);
                    //gb.BeginGeometry(OpenGisGeometryType.Polygon);

                    //firstLatLong = null;
                    //firstLatLongStored = false;
                    //foreach (LatLong latLong in latLongs)
                    //{
                    //    if (!firstLatLongStored)
                    //    {
                    //        firstLatLong = latLong;
                    //        gb.BeginFigure(firstLatLong.Latitude, firstLatLong.Longitude);
                    //        firstLatLongStored = true;
                    //    }
                    //    else
                    //        gb.AddLine(latLong.Latitude, latLong.Longitude);
                    //}

                    //gb.AddLine(firstLatLong.Latitude, firstLatLong.Longitude); //Note: Last Point same as First
                    //gb.EndFigure();

                    //gb.EndGeometry();

                    //SqlGeometry geom = null;
                    //geom = gb.ConstructedGeometry.MakeValid();

                    ////geom = geom.MakeValid().STUnion(geom.STStartPoint());

                    //rectangle = SqlGeography.STPolyFromText(geom.STAsText(), 4326);
                }

                SqlDataReader dr = null;
                try
                {
                    BusinessLogicLayer.IPoint busPoint = new BusinessLogicLayer.Point();

                    dr = busPoint.GetPointsIntersected(rectangle);

                    while (dr.Read())
                    {
                        Orchestrator.WebUI.Services.Point point = new Orchestrator.WebUI.Services.Point();
                        point.GeofencePoints = new List <LatLong>();
                        point.Description    = dr["PointName"].ToString();
                        point.Latitide       = dr["WGS84Latitude"] != DBNull.Value ? Convert.ToDouble(dr["WGS84Latitude"]) : 0;
                        point.Longitude      = dr["WGS84Longitude"] != DBNull.Value ? Convert.ToDouble(dr["WGS84Longitude"]) : 0;
                        point.PointID        = int.Parse(dr["PointId"].ToString());
                        SqlGeography geofence = (SqlGeography)dr["Geofence"];

                        for (int i = 0; i < geofence.STNumPoints(); i++)
                        {
                            SqlGeography p       = geofence.STPointN(i + 1);
                            LatLong      latLong = new LatLong();
                            latLong.Latitude  = (double)p.Lat;
                            latLong.Longitude = (double)p.Long;
                            point.GeofencePoints.Add(latLong);
                        }
                        points.Add(point);
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
                finally
                {
                    dr.Close();
                }
            }

            return(points);
        }