Exemple #1
0
 /// <summary>
 /// Creates an enumeration of <see cref="GeoAPI.Geometries.Coordinate"/>s from an xml string
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="xml">the xml string</param>
 /// <returns>Coordinates</returns>
 public static System.Collections.Generic.IEnumerable <GeoAPI.Geometries.IGeometry> PointsFromXml(
     GeoAPI.Geometries.IGeometryFactory factory,
     System.IO.Stream xml)
 {
     foreach (var coordinate in CoordinatesFromXml(xml))
     {
         yield return(factory.CreatePoint(coordinate));
     }
 }
Exemple #2
0
            /// <summary>
            /// gets realtime data from public transport in city vilnius of lithuania
            /// </summary>
            private void GetVilniusTransportData(string line)
            {
                if (_isActive)
                {
                    return;
                }
                _isActive = true;

                //List<FeatureDataRow> newFeatures = new List<FeatureDataRow>();
                var fdt = VehicleDataTable();

                string url = "http://www.troleibusai.lt/puslapiai/services/vehiclestate.php?type=";

                switch (_transportType)
                {
                case TransportType.Bus:
                {
                    url += "bus";
                }
                break;

                case TransportType.TrolleyBus:
                {
                    url += "trolley";
                }
                break;
                }

                if (!string.IsNullOrEmpty(line))
                {
                    url += "&line=" + line;
                }

                url += "&app=SharpMap.WinFormSamples";

                var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);

                request.Timeout          = Timeout;
                request.ReadWriteTimeout = request.Timeout;
                request.Accept           = "*/*";
                request.KeepAlive        = false;

                string xml;

                using (var response = request.GetResponse() as System.Net.HttpWebResponse)
                {
                    if (response == null)
                    {
                        return;
                    }

                    using (var responseStream = response.GetResponseStream())
                    {
                        if (responseStream == null)
                        {
                            return;
                        }
                        using (var read = new System.IO.StreamReader(responseStream))
                        {
                            xml = read.ReadToEnd();
                        }
                    }
                }

                var doc = new System.Xml.XmlDocument();

                {
                    doc.LoadXml(xml);

                    var devices = doc.GetElementsByTagName("Device");
                    foreach (System.Xml.XmlNode dev in devices)
                    {
                        if (dev.Attributes == null)
                        {
                            continue;
                        }

                        double?lat = null, lng = null;
                        SharpMap.Data.FeatureDataRow dr = fdt.NewRow();
                        dr["Id"] = int.Parse(dev.Attributes["ID"].InnerText);
                        foreach (System.Xml.XmlElement elem in dev.ChildNodes)
                        {
                            // Debug.WriteLine(d.Id + "->" + elem.Name + ": " + elem.InnerText);

                            switch (elem.Name)
                            {
                            case "Lat":
                                lat = double.Parse(elem.InnerText, System.Globalization.CultureInfo.InvariantCulture);
                                break;

                            case "Lng":
                                lng = double.Parse(elem.InnerText, System.Globalization.CultureInfo.InvariantCulture);
                                break;

                            case "Bearing":
                                if (!string.IsNullOrEmpty(elem.InnerText))
                                {
                                    dr["Bearing"] = double.Parse(elem.InnerText, System.Globalization.CultureInfo.InvariantCulture);
                                }
                                break;

                            case "LineNum":
                                dr["Line"] = elem.InnerText;
                                break;

                            case "AreaName":
                                dr["AreaName"] = elem.InnerText;
                                break;

                            case "StreetName":
                                dr["StreetName"] = elem.InnerText;
                                break;

                            case "TrackType":
                                dr["TrackType"] = elem.InnerText;
                                break;

                            case "LastStop":
                                dr["LastStop"] = elem.InnerText;
                                break;

                            case "Time":
                                dr["Time"] = elem.InnerText;
                                break;
                            }
                        }

                        if (lat.HasValue && lng.HasValue)
                        {
                            dr.Geometry = _factory.CreatePoint(new GeoAPI.Geometries.Coordinate(lng.Value, lat.Value));
                            fdt.Rows.Add(dr);
                        }
                    }
                }

                Features.Clear();

                foreach (SharpMap.Data.FeatureDataRow featureDataRow in fdt.Rows)
                {
                    var fdr = Features.NewRow();
                    fdr.ItemArray = featureDataRow.ItemArray;
                    fdr.Geometry  = featureDataRow.Geometry;
                    Features.AddRow(fdr);
                }
                Features.AcceptChanges();

                _isActive = false;
            }
        public async Task <HttpResult> Search([FromBody] GymSearch q)
        {
            try
            {
                int takeAmount = 10;
                int pageNum    = q.Page;

                string k = q.Keywords.ToLower().Trim();
                //if (string.IsNullOrEmpty(k))
                //    k = " ";
                ////for some reason search takes less time if given keyword is not empty...

                List <string> queryWords = k.Replace(',', ' ').Split(' ').Where(x => x.Length > 0).ToList();

                IQueryable <GymFinderGym> gyms = (from g in db.GymFinderGym
                                                  //let citySearch = city.Id > 0
                                                  where
                                                  (
                                                      (g.Status == q.Status || q.Status == (int)Enums.GymStatus.Any)
                                                      &&
                                                      (
                                                          string.IsNullOrEmpty(k) ||
                                                          queryWords.Any(w => g.Name.ToLower().Contains(w)) ||
                                                          queryWords.Any(w => g.StreetAddress.ToLower().Contains(w)) ||
                                                          queryWords.Any(w => g.LocationCityName.ToLower().Contains(w)) ||
                                                          queryWords.Any(w => g.LocationCountryName.ToLower().Contains(w)) ||
                                                          queryWords.All(w => g.Description.ToLower().Contains(w))
                                                      )
                                                      //&&
                                                      //(
                                                      //      q.CityID == city.Id || !citySearch
                                                      //)
                                                      &&
                                                      (q.Cafe == g.Cafe || q.Cafe != 1)
                                                      &&
                                                      (q.CardioMachines == g.CardioMachines || q.CardioMachines != 1)
                                                      &&
                                                      (q.ChangingRooms == g.ChangingRooms || q.ChangingRooms != 1)
                                                      &&
                                                      (q.ClassesAvailable == g.ClassesAvailable || q.ClassesAvailable != 1)
                                                      &&
                                                      (q.Crossfit == g.Crossfit || q.Crossfit != 1)
                                                      &&
                                                      (q.FreeWeightsBarsPlates == g.FreeWeightsBarsPlates || q.FreeWeightsBarsPlates != 1)
                                                      &&
                                                      (q.FreeWeightsDumbbells == g.FreeWeightsDumbbells || q.FreeWeightsDumbbells != 1)
                                                      &&
                                                      (q.MembersOnly == g.MembersOnly || q.MembersOnly != 1)
                                                      &&
                                                      (q.NoMembershipRequired == g.NoMembershipRequired || q.NoMembershipRequired != 1)
                                                      &&
                                                      (q.OlympicLifting == g.OlympicLifting || q.OlympicLifting != 1)
                                                      &&
                                                      (q.Physio == g.Physio || q.Physio != 1)
                                                      &&
                                                      (q.Powerlifting == g.Powerlifting || q.Powerlifting != 1)
                                                      &&
                                                      (q.ResistanceMachines == g.ResistanceMachines || q.ResistanceMachines != 1)
                                                      &&
                                                      (q.Sauna == g.Sauna || q.Sauna != 1)
                                                      &&
                                                      (q.SwimmingPool == g.SwimmingPool || q.SwimmingPool != 1)
                                                      &&
                                                      (q.Toilets == g.Toilets || q.Toilets != 1)
                                                      &&
                                                      (q.TwentyFourHour == g.TwentyFourHour || q.TwentyFourHour != 1)
                                                      &&
                                                      (q.VendingMachine == g.VendingMachine || q.VendingMachine != 1)
                                                      &&
                                                      (q.Strongman == g.Strongman || q.Strongman != 1)
                                                      &&
                                                      (q.Lockers == g.Lockers || q.Lockers != 1)
                                                  )
                                                  select g);

                int total = gyms.Count();

                CityGeo city = await db.CityGeo.FindAsync(q.CityID);

                //if (city == null)
                //    city = new CityGeo { Id = 0 };

                if (city != null)
                {//sort by distance first if city selected
                    GeoAPI.Geometries.IGeometryFactory geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
                    GeoAPI.Geometries.IPoint           cityLocation    = geometryFactory.CreatePoint(new GeoAPI.Geometries.Coordinate((double)city.Latitude, (double)city.Longitude));

                    gyms = gyms
                           .OrderBy(x => new GeoAPI.Geometries.Coordinate(x.LocationLat, x.LocationLong).Distance(cityLocation.Coordinate))
                           .ThenByDescending(x => x.CreationDate);
                }
                else if (!string.IsNullOrEmpty(k))
                {//else sort by keyword relevance only
                    gyms = gyms
                           .OrderByDescending(x => x.Name.ToLower().StartsWith(k))
                           .ThenByDescending(x => x.CreationDate);
                }
                else
                {//else sort by rating
                    gyms = gyms.OrderByDescending(x => x.AverageRating);
                }

                gyms = gyms.Skip(pageNum * takeAmount).Take(takeAmount);

                return(new HttpResult(true, new { gyms, total }, ""));
            }
            catch (Exception e)
            {
                return(new HttpResult(false, null, Functions.ErrorMessage(e)));
            }
        }
        /// <summary>
        /// See http://www.gaia-gis.it/gaia-sins/BLOB-Geometry.html
        /// for the specification of the spatialite BLOB geometry format
        /// Derived from WKB, but unfortunately it is not practical to reuse existing
        /// WKB encoding/decoding code
        /// </summary>
        /// <param name="spatialliteGeom">The geometry blob</param>
        /// <param name="factory">The factory to create the result geometry</param>
        /// <returns>A geometry</returns>
        public static GeoAPI.Geometries.IGeometry Parse(byte[] spatialliteGeom, GeoAPI.Geometries.IGeometryFactory factory)
        {
            var nBytes = spatialliteGeom.Length;

            if (spatialliteGeom.Length < 44 ||
                spatialliteGeom[0] != 0 ||
                spatialliteGeom[38] != 0x7C ||
                spatialliteGeom[nBytes - 1] != 0xFE)
            {
                throw new ApplicationException("Corrupt SpatialLite geom");
            }

            bool isLittleEndian = spatialliteGeom[1] == 0x01;

            if (spatialliteGeom[1] != 0x00 && spatialliteGeom[1] != 0x01)
            {
                throw new ApplicationException("Corrupt SpatialLite geom");
            }



            int idx    = 39;
            int nGType = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);

            if (nGType < 1 || nGType > 7)
            {
                throw new ApplicationException("Unsupported geom type!");
            }

            /* -------------------------------------------------------------------- */
            /*      Point                                                           */
            /* -------------------------------------------------------------------- */
            if (nGType == 1)
            {
                return(factory.CreatePoint(ReadPoint(spatialliteGeom, ref idx, isLittleEndian)));
            }
            /* -------------------------------------------------------------------- */
            /*      LineString                                                      */
            /* -------------------------------------------------------------------- */
            else if (nGType == 2)
            {
                return(ReadLineString(spatialliteGeom, ref idx, isLittleEndian, factory));
            }
            /* -------------------------------------------------------------------- */
            /*      Polygon                                                      */
            /* -------------------------------------------------------------------- */
            else if (nGType == 3)
            {
                return(ReadPolygon(spatialliteGeom, ref idx, isLittleEndian, factory));
            }
            /* -------------------------------------------------------------------- */
            /*      MultiPoint                          */
            /* -------------------------------------------------------------------- */
            else if (nGType == 4)
            {
                List <GeoAPI.Geometries.IPoint> pts = new List <GeoAPI.Geometries.IPoint>();
                int numGeoms = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
                for (int i = 0; i < numGeoms; i++)
                {
                    if (spatialliteGeom[idx] != 0x69)
                    {
                        throw new ApplicationException("FormatError in SpatiaLIteGeom");
                    }
                    idx++;
                    int gt = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
                    if (gt != 1)
                    {
                        throw new ApplicationException("MultiPoint must Contain Point entities");
                    }

                    pts.Add(factory.CreatePoint(ReadPoint(spatialliteGeom, ref idx, isLittleEndian)));
                }
                return(factory.CreateMultiPoint(pts.ToArray()));
            }
            /* -------------------------------------------------------------------- */
            /*      MultiLineString                          */
            /* -------------------------------------------------------------------- */
            else if (nGType == 5)
            {
                List <GeoAPI.Geometries.ILineString> lss = new List <GeoAPI.Geometries.ILineString>();
                int numGeoms = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
                for (int i = 0; i < numGeoms; i++)
                {
                    if (spatialliteGeom[idx] != 0x69)
                    {
                        throw new ApplicationException("FormatError in SpatiaLIteGeom");
                    }
                    idx++;
                    int gt = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
                    if (gt != 2)
                    {
                        throw new ApplicationException("MultiLineString must contain LineString Entities");
                    }
                    lss.Add(ReadLineString(spatialliteGeom, ref idx, isLittleEndian, factory));
                }
                return(factory.CreateMultiLineString(lss.ToArray()));
            }
            /* -------------------------------------------------------------------- */
            /*      MultiPolygon                                                      */
            /* -------------------------------------------------------------------- */
            else if (nGType == 6)
            {
                List <GeoAPI.Geometries.IPolygon> polys = new List <GeoAPI.Geometries.IPolygon>();
                int numPolys = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
                for (int i = 0; i < numPolys; i++)
                {
                    if (spatialliteGeom[idx] != 0x69)
                    {
                        throw new ApplicationException("FormatError in SpatiaLIteGeom");
                    }
                    idx++;
                    int gt = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
                    if (gt != 3)
                    {
                        throw new ApplicationException("Multipolygon must contain Polygon Entities");
                    }

                    polys.Add(ReadPolygon(spatialliteGeom, ref idx, isLittleEndian, factory));
                }
                return(factory.CreateMultiPolygon(polys.ToArray()));
            }

            return(null);
        }
        public async Task <HttpResult> Search([FromBody] CoachSearch q)
        {
            try
            {
                int takeAmount = 15;
                int pageNum    = q.Page;

                string k = q.Keywords.ToLower().Trim();

                List <string> queryWords = k.Replace(',', ' ').Split(' ').Where(x => x.Length > 0).ToList();

                var coaches = (from u in db.User
                               //let citySearch = city.Id > 0
                               where
                               (
                                   u.IsCoach == 1
                                   &&
                                   (u.Status == q.Status || q.Status == (int)Enums.UserStatus.Active)
                                   &&
                                   (
                                       string.IsNullOrEmpty(k) ||
                                       queryWords.Any(w => u.FirstName.ToLower().Contains(w)) ||
                                       queryWords.Any(w => u.LastName.ToLower().Contains(w)) ||
                                       queryWords.Any(w => u.CityName.ToLower().Contains(w)) ||
                                       queryWords.Any(w => u.CountryName.ToLower().Contains(w)) ||
                                       queryWords.All(w => u.CoachBio.ToLower().Contains(w))
                                   )
                                   &&
                                   (u.IsVerified == q.IsVerfied || q.IsVerfied != 1)
                                   &&
                                   (u.CoachBodybuilding == q.CoachBodybuilding || q.CoachBodybuilding != 1)
                                   &&
                                   (u.CoachClasses == q.CoachClasses || q.CoachClasses != 1)
                                   &&
                                   (u.CoachCrossfit == q.CoachCrossfit || q.CoachCrossfit != 1)
                                   &&
                                   (u.CoachDance == q.CoachDance || q.CoachDance != 1)
                                   &&
                                   (u.CoachMasseuse == q.CoachMasseuse || q.CoachMasseuse != 1)
                                   &&
                                   (u.CoachNutrition == q.CoachNutrition || q.CoachNutrition != 1)
                                   &&
                                   (u.CoachOlympicLifting == q.CoachOlympicLifting || q.CoachOlympicLifting != 1)
                                   &&
                                   (u.CoachOneOnOne == q.CoachOneOnOne || q.CoachOneOnOne != 1)
                                   &&
                                   (u.CoachOnlineAvailable == q.CoachOnlineAvailable || q.CoachOnlineAvailable != 1)
                                   &&
                                   (u.CoachOnlineOnly == q.CoachOnlineOnly || q.CoachOnlineOnly != 1)
                                   &&
                                   (u.CoachOther == q.CoachOther || q.CoachOther != 1)
                                   &&
                                   (u.CoachPhysio == q.CoachPhysio || q.CoachPhysio != 1)
                                   &&
                                   (u.CoachPowerlifting == q.CoachPowerlifting || q.CoachPowerlifting != 1)
                                   &&
                                   (u.CoachProgramOnly == q.CoachProgramOnly || q.CoachProgramOnly != 1)
                                   &&
                                   (u.CoachStrongman == q.CoachStrongman || q.CoachStrongman != 1)
                                   &&
                                   (u.CoachWeightLoss == q.CoachWeightLoss || q.CoachWeightLoss != 1)

                               )
                               select u);

                int total = coaches.Count();

                CityGeo city = await db.CityGeo.FindAsync(q.CityID);

                if (city != null)
                {//sort by distance first if city selected
                    GeoAPI.Geometries.IGeometryFactory geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
                    GeoAPI.Geometries.IPoint           cityLocation    = geometryFactory.CreatePoint(new GeoAPI.Geometries.Coordinate((double)city.Latitude, (double)city.Longitude));

                    coaches = coaches.Where(x => x.Latitude.HasValue)
                              .OrderBy(x => new GeoAPI.Geometries.Coordinate(x.Latitude.Value, x.Longitutde.Value).Distance(cityLocation.Coordinate))
                              .ThenByDescending(x => x.CreationDate);
                }
                else if (!string.IsNullOrEmpty(k))
                {//else sort by keyword relevance only
                    coaches = coaches
                              .OrderByDescending(x => !string.IsNullOrEmpty(x.FirstName) && x.FirstName.ToLower().StartsWith(k))
                              .ThenByDescending(x => x.CreationDate);
                }
                else
                {//else sort by rating
                    coaches = coaches.OrderByDescending(x => x.AverageRating);
                }

                coaches = coaches.Skip(pageNum * takeAmount).Take(takeAmount);

                if (coaches.Count() == 0)
                {
                    return(new HttpResult(true, new { coaches = new List <UserPublic>(), total }, ""));
                }
                else
                {
                    return(new HttpResult(true, new { coaches = coaches.Where(x => x != null).AsEnumerable().Select(s => new UserPublic(s, false)).ToList(), total }, ""));
                }
            }
            catch (Exception e)
            {
                var rawData = db.User.ToList();
                return(new HttpResult(false, null, Functions.ErrorMessage(e)));
            }
        }