Beispiel #1
0
        public static GeoAPI.Geometries.ILinearRing CreateRectangle(GeoAPI.Geometries.IGeometryFactory factory,
                                                                    GeoAPI.Geometries.Coordinate center, System.Drawing.SizeF size)
        {
            var wh = new System.Drawing.SizeF(size.Width * 0.5f, size.Height * 0.5f);
            var lt = new GeoAPI.Geometries.Coordinate(center.X - wh.Width, center.Y + wh.Height);
            var rb = new GeoAPI.Geometries.Coordinate(center.X + wh.Width, center.Y - wh.Height);

            return(CreateRectangle(factory, lt, rb));
        }
Beispiel #2
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));
     }
 }
Beispiel #3
0
        public static GeoAPI.Geometries.ILinearRing CreateRectangle(GeoAPI.Geometries.IGeometryFactory factory,
                                                                    GeoAPI.Geometries.Coordinate leftTop, GeoAPI.Geometries.Coordinate rightBottom)
        {
            var pts = new[]
            {
                leftTop,
                new GeoAPI.Geometries.Coordinate(rightBottom.X, leftTop.Y),
                rightBottom,
                new GeoAPI.Geometries.Coordinate(leftTop.X, rightBottom.Y),
                leftTop
            };

            return(factory.CreateLinearRing(pts));
        }
Beispiel #4
0
 private static Geometry ParseOgrGeometry(OgrGeometry ogrGeometry, GeoAPI.Geometries.IGeometryFactory factory)
 {
     if (ogrGeometry != null)
     {
         //Just in case it isn't 2D
         ogrGeometry.FlattenTo2D();
         byte[] wkbBuffer = new byte[ogrGeometry.WkbSize()];
         ogrGeometry.ExportToWkb(wkbBuffer);
         Geometry geom = GeometryFromWKB.Parse(wkbBuffer, factory);
         if (geom == null)
         {
             Debug.WriteLine(string.Format("Failed to parse '{0}'", ogrGeometry.GetGeometryType()));
         }
         return(geom);
     }
     return(null);
 }
Beispiel #5
0
        public static GeoAPI.Geometries.ILinearRing CreateEllipse(GeoAPI.Geometries.IGeometryFactory factory,
                                                                  GeoAPI.Geometries.Coordinate center, System.Drawing.SizeF size, int segmentsPerQuadrant)
        {
            const double piHalf = System.Math.PI * 0.5d;

            var step = piHalf / segmentsPerQuadrant;

            var pts   = new GeoAPI.Geometries.Coordinate[4 * segmentsPerQuadrant + 1];
            var angle = 0d;

            for (var i = 0; i < 4 * segmentsPerQuadrant; i++)
            {
                pts[i] = new GeoAPI.Geometries.Coordinate(center.X + System.Math.Cos(angle) * size.Width,
                                                          center.Y + System.Math.Sin(angle) * size.Height);
                angle += step;
            }
            pts[pts.Length - 1] = pts[0];
            return(factory.CreateLinearRing(pts));
        }
Beispiel #6
0
        public static GeoAPIGeometry ToGeoAPI(this Data.Shape shape, GeoAPI.Geometries.IGeometryFactory factory = null, bool copyAttributes = false)
        {
            var useFactory = factory ?? GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory();

            if (shape.Range.FeatureType == FeatureType.Polygon)
            {
                return(FromPolygonShape(shape, useFactory, copyAttributes));
            }
            if (shape.Range.FeatureType == FeatureType.Line)
            {
                return(FromLineShape(shape, useFactory, copyAttributes));
            }
            if (shape.Range.FeatureType == FeatureType.MultiPoint)
            {
                return(FromMultiPointShape(shape, useFactory, copyAttributes));
            }
            if (shape.Range.FeatureType == FeatureType.Point)
            {
                return(FromPointShape(shape, useFactory, copyAttributes));
            }
            return(null);
        }
Beispiel #7
0
 public static GeoAPI.Geometries.ILinearRing CreateEllipse(GeoAPI.Geometries.IGeometryFactory factory,
                                                           GeoAPI.Geometries.Coordinate center, System.Drawing.SizeF size)
 {
     return(CreateEllipse(factory, center, size, 12));
 }
        /// <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);
        }
        private static GeoAPI.Geometries.ILineString ReadLineString(byte[] geom, ref int idx, bool isLittleEndian, GeoAPI.Geometries.IGeometryFactory factory)
        {
            int iPoint;
            var nPointCount = ReadUInt32(geom, ref idx, isLittleEndian);

            if (nPointCount < 0 || nPointCount > Int32.MaxValue / (2 * 8))
            {
                throw new ApplicationException("Currupt SpatialLite geom");
            }

            List <GeoAPI.Geometries.Coordinate> pts = new List <GeoAPI.Geometries.Coordinate>();

            for (iPoint = 0; iPoint < nPointCount; iPoint++)
            {
                pts.Add(ReadPoint(geom, ref idx, isLittleEndian));
            }

            return(factory.CreateLineString(pts.ToArray()));
        }
        private static GeoAPI.Geometries.IPolygon ReadPolygon(byte[] geom, ref int idx, bool isLittleEndian, GeoAPI.Geometries.IGeometryFactory factory)
        {
            var nRings = ReadUInt32(geom, ref idx, isLittleEndian);

            if (nRings < 1 || nRings > Int32.MaxValue / (2 * 8))
            {
                throw new ApplicationException("Currupt SpatialLite geom");
            }

            List <GeoAPI.Geometries.ILineString> lineStrings = new List <GeoAPI.Geometries.ILineString>();

            for (int i = 0; i < nRings; i++)
            {
                lineStrings.Add(ReadLineString(geom, ref idx, isLittleEndian, factory));
            }

            List <GeoAPI.Geometries.ILinearRing> holes = null;
            var shell = factory.CreateLinearRing(lineStrings[0].Coordinates);

            if (lineStrings.Count > 1)
            {
                holes = new List <GeoAPI.Geometries.ILinearRing>();
                for (int i = 1; i < lineStrings.Count; i++)
                {
                    holes.Add(factory.CreateLinearRing(lineStrings[i].Coordinates));
                }
            }
            return(factory.CreatePolygon(shell, holes == null ? null : holes.ToArray()));
        }
Beispiel #11
0
        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)));
            }
        }
Beispiel #12
0
        private static FeatureDataRow OgrFeatureToFeatureDataRow(FeatureDataTable table, OSGeo.OGR.Feature ogrFeature, GeoAPI.Geometries.IGeometryFactory factory)
        {
            FeatureDataRow fdr      = table.NewRow();
            Int32          fdrIndex = 0;

            for (int iField = 0; iField < ogrFeature.GetFieldCount(); iField++)
            {
                //*** BEGIN FIX: Ensure fdrIndex is incremented if field value is not set and field is of a supported type.
                bool         valueAvailable = ogrFeature.IsFieldSet(iField);
                OgrFieldType fieldType      = ogrFeature.GetFieldType(iField);

                // No need to get field value if there's no value available...
                if (!valueAvailable)
                {
                    // We need to increment the data row column index if this is a supported field type
                    // otherwise the next field will be written to the wrong column...
                    // We support all types except OFTBinary...
                    // Supported field types must be consistent with the code in ReadColumnDefinition and the switch case below...
                    if (fieldType != OgrFieldType.OFTBinary)
                    {
                        fdrIndex++;
                    }

                    continue;
                }
                //*** END FIX
                //if (!ogrFeature.IsFieldSet(iField)) continue;
                try
                {
                    switch (ogrFeature.GetFieldType(iField))
                    {
                    case OgrFieldType.OFTString:
                    case OgrFieldType.OFTWideString:
                    {
                        fdr[fdrIndex++] = ogrFeature.GetFieldAsString(iField);
                        break;
                    }

                    case OgrFieldType.OFTStringList:
                    case OgrFieldType.OFTWideStringList:
                    {
                        fdr[fdrIndex++] = ogrFeature.GetFieldAsStringList(iField);
                        break;
                    }

                    case OgrFieldType.OFTInteger:
                    {
                        fdr[fdrIndex++] = ogrFeature.GetFieldAsInteger(iField);
                        break;
                    }

                    case OgrFieldType.OFTIntegerList:
                    {
                        int count = 0;
                        fdr[fdrIndex++] = ogrFeature.GetFieldAsIntegerList(iField, out count);
                        break;
                    }

                    case OgrFieldType.OFTReal:
                    {
                        fdr[fdrIndex++] = ogrFeature.GetFieldAsDouble(iField);
                        break;
                    }

                    case OgrFieldType.OFTRealList:
                    {
                        int count = 0;
                        fdr[fdrIndex++] = ogrFeature.GetFieldAsDoubleList(iField, out count);
                        break;
                    }

                    case OgrFieldType.OFTDate:
                    case OgrFieldType.OFTDateTime:
                    case OgrFieldType.OFTTime:
                        Int32 y, m, d, h, mi, s, tz;
                        ogrFeature.GetFieldAsDateTime(iField, out y, out m, out d, out h, out mi, out s, out tz);
                        try
                        {
                            if (y == 0 && m == 0 && d == 0)
                            {
                                fdr[fdrIndex++] = DateTime.MinValue.AddMinutes(h * 60 + mi);
                            }
                            else
                            {
                                fdr[fdrIndex++] = new DateTime(y, m, d, h, mi, s);
                            }
                        }
                        catch
                        {
                            throw;
                        }
                        break;

                    default:
                        Debug.WriteLine(string.Format("Cannot handle Ogr DataType '{0}', '{1}'", ogrFeature.GetFieldType(iField), iField));
                        break;
                    }
                }
                catch { }
            }

            using (var gr = ogrFeature.GetGeometryRef())
            {
                fdr.Geometry = ParseOgrGeometry(gr, factory);
                gr.Dispose();
            }
            return(fdr);
        }
Beispiel #13
0
        private static FeatureDataRow LoadOgrFeatureToFeatureDataRow(FeatureDataTable table, OSGeo.OGR.Feature ogrFeature, GeoAPI.Geometries.IGeometryFactory factory)
        {
            var values = new object[ogrFeature.GetFieldCount()];

            for (var iField = 0; iField < ogrFeature.GetFieldCount(); iField++)
            {
                // No need to get field value if there's no value available...
                if (!ogrFeature.IsFieldSet(iField))
                {
                    continue;
                }

                int count;
                switch (ogrFeature.GetFieldType(iField))
                {
                case OgrFieldType.OFTString:
                case OgrFieldType.OFTWideString:
                    values[iField] = ogrFeature.GetFieldAsString(iField);
                    break;

                case OgrFieldType.OFTStringList:
                case OgrFieldType.OFTWideStringList:
                    values[iField] = ogrFeature.GetFieldAsStringList(iField);
                    break;

                case OgrFieldType.OFTInteger:
                    values[iField] = ogrFeature.GetFieldAsInteger(iField);
                    break;

                case OgrFieldType.OFTIntegerList:
                    values[iField] = ogrFeature.GetFieldAsIntegerList(iField, out count);
                    break;

                case OgrFieldType.OFTReal:
                    values[iField] = ogrFeature.GetFieldAsDouble(iField);
                    break;

                case OgrFieldType.OFTRealList:
                    values[iField] = ogrFeature.GetFieldAsDoubleList(iField, out count);
                    break;

                case OgrFieldType.OFTDate:
                case OgrFieldType.OFTDateTime:
                case OgrFieldType.OFTTime:
                    Int32 y, m, d, h, mi, s, tz;
                    ogrFeature.GetFieldAsDateTime(iField, out y, out m, out d, out h, out mi, out s, out tz);
                    try
                    {
                        if (y == 0 && m == 0 && d == 0)
                        {
                            values[iField] = DateTime.MinValue.AddMinutes(h * 60 + mi);
                        }
                        else
                        {
                            values[iField] = new DateTime(y, m, d, h, mi, s);
                        }
                    }
// ReSharper disable once EmptyGeneralCatchClause
                    catch { }
                    break;

                default:
                    Debug.WriteLine("Cannot handle Ogr DataType '{0}'", ogrFeature.GetFieldType(iField));
                    break;
                }
            }

            var fdr = (FeatureDataRow)table.LoadDataRow(values, true);

            using (var gr = ogrFeature.GetGeometryRef())
            {
                fdr.Geometry = ParseOgrGeometry(gr, factory);
                gr.Dispose();
            }
            return(fdr);
        }
Beispiel #14
0
        private static FeatureDataRow OgrFeatureToFeatureDataRow(FeatureDataTable table, OSGeo.OGR.Feature ogrFeature, GeoAPI.Geometries.IGeometryFactory factory)
        {
            FeatureDataRow fdr      = table.NewRow();
            Int32          fdrIndex = 0;

            for (int iField = 0; iField < ogrFeature.GetFieldCount(); iField++)
            {
                if (!ogrFeature.IsFieldSet(iField))
                {
                    continue;
                }

                switch (ogrFeature.GetFieldType(iField))
                {
                case OgrFieldType.OFTString:
                case OgrFieldType.OFTWideString:
                    fdr[fdrIndex++] = ogrFeature.GetFieldAsString(iField);
                    break;

                case OgrFieldType.OFTStringList:
                case OgrFieldType.OFTWideStringList:
                    break;

                case OgrFieldType.OFTInteger:
                    fdr[fdrIndex++] = ogrFeature.GetFieldAsInteger(iField);
                    break;

                case OgrFieldType.OFTIntegerList:
                    break;

                case OgrFieldType.OFTReal:
                    fdr[fdrIndex++] = ogrFeature.GetFieldAsDouble(iField);
                    break;

                case OgrFieldType.OFTRealList:
                    break;

                case OgrFieldType.OFTDate:
                case OgrFieldType.OFTDateTime:
                case OgrFieldType.OFTTime:
                    Int32 y, m, d, h, mi, s, tz;
                    ogrFeature.GetFieldAsDateTime(iField, out y, out m, out d, out h, out mi, out s, out tz);
                    try
                    {
                        if (y == 0 && m == 0 && d == 0)
                        {
                            fdr[fdrIndex++] = DateTime.MinValue.AddMinutes(h * 60 + mi);
                        }
                        else
                        {
                            fdr[fdrIndex++] = new DateTime(y, m, d, h, mi, s);
                        }
                    }
                    catch { }
                    break;

                default:
                    Debug.WriteLine(string.Format("Cannot handle Ogr DataType '{0}'", ogrFeature.GetFieldType(iField)));
                    break;
                }
            }

            using (var gr = ogrFeature.GetGeometryRef())
            {
                fdr.Geometry = ParseOgrGeometry(gr, factory);
                gr.Dispose();
            }
            return(fdr);
        }
        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)));
            }
        }