Exemplo n.º 1
0
        //-----------------------------------------------------------------------------------------------------------

        private Orchestrator.WebUI.Services.Point GetPointForWebService(int pointID)
        {
            Orchestrator.Facade.IPoint        facPoint      = new Orchestrator.Facade.Point();
            Orchestrator.Entities.Point       selectedPoint = facPoint.GetPointForPointId(pointID);
            Orchestrator.WebUI.Services.Point p             = new Orchestrator.WebUI.Services.Point();

            p.PointID     = selectedPoint.PointId;
            p.Description = selectedPoint.Description;
            p.Latitide    = (double)selectedPoint.Latitude;
            p.Latitude    = (double)selectedPoint.Latitude; // added a correctly spelt version but left the old one to prevent having to change everything.

            p.Longitude          = (double)selectedPoint.Longitude;
            p.ClosestTownID      = selectedPoint.PostTown.TownId;
            p.ClosestTown        = selectedPoint.PostTown.TownName;
            p.IdentityID         = selectedPoint.IdentityId;
            p.OrganisationName   = selectedPoint.OrganisationName;
            p.PointNotes         = selectedPoint.PointNotes;
            p.PointCode          = selectedPoint.PointCode;
            p.PhoneNumber        = selectedPoint.PhoneNumber;
            p.AddressID          = selectedPoint.Address.AddressId;
            p.AddressLine1       = selectedPoint.Address.AddressLine1;
            p.AddressLine2       = selectedPoint.Address.AddressLine2;
            p.AddressLine3       = selectedPoint.Address.AddressLine3;
            p.PostTown           = selectedPoint.Address.PostTown;
            p.County             = selectedPoint.Address.County;
            p.PostCode           = selectedPoint.Address.PostCode;
            p.CountryID          = selectedPoint.Address.CountryId;
            p.CountryDescription = selectedPoint.Address.CountryDescription;

            p.GeofencePoints = new List <LatLong>();

            string points = string.Empty;

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

            return(p);
        }
Exemplo n.º 2
0
        public List <Point> GetPointsPenetrated(List <LatLong> latLongs)
        {
            List <Point> points = new List <Point>();

            SqlGeographyBuilder geogBuilder = new SqlGeographyBuilder();

            geogBuilder.SetSrid(4326);
            geogBuilder.BeginGeography(OpenGisGeographyType.Polygon);

            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())
                {
                    Point point = new 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);
        }