Пример #1
0
        public static bool isPointInPolygon(Geofence geoFence, Coordinate point)
        {
            List<Coordinate> location = geoFence.getPoints();

            int indexX, indexJ;
            bool status = false;
            for (indexX = 0, indexJ = location.Count - 1; indexX < location.Count; indexJ = indexX++) {
                if ((((location[indexX].latitude <= point.latitude) && (point.latitude < location[indexJ].latitude))
                        || ((location[indexJ].latitude <= point.latitude) && (point.latitude < location[indexX].latitude)))
                        && (point.longitude < (location[indexJ].longitude - location[indexX].longitude) * (point.latitude - location[indexX].latitude)
                            / (location[indexJ].latitude - location[indexX].latitude) + location[indexX].longitude)) {
                    status = !status;
                }
            }
            return status;
        }
Пример #2
0
        public static bool isPointInPolygon(Geofence geoFence, Coordinate point)
        {
            List <Coordinate> location = geoFence.getPoints();

            int  indexX, indexJ;
            bool status = false;

            for (indexX = 0, indexJ = location.Count - 1; indexX < location.Count; indexJ = indexX++)
            {
                if ((((location[indexX].latitude <= point.latitude) && (point.latitude < location[indexJ].latitude)) ||
                     ((location[indexJ].latitude <= point.latitude) && (point.latitude < location[indexX].latitude))) &&
                    (point.longitude < (location[indexJ].longitude - location[indexX].longitude) * (point.latitude - location[indexX].latitude)
                     / (location[indexJ].latitude - location[indexX].latitude) + location[indexX].longitude))
                {
                    status = !status;
                }
            }
            return(status);
        }
Пример #3
0
        public void fillGeofences(Company company)
        {
            List<Geofence> geofences = new List<Geofence>();

            try {
                mysqlConnection = new MySqlConnection(database.getConnectionString());
                mysqlConnection.Open();

                string sql =
                     "SELECT * " +
                     "FROM cmp_" + company.DatabaseName + ".gf";

                MySqlCommand mySqlCommand = new MySqlCommand(sql, mysqlConnection);
                MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader();

                if (!mySqlDataReader.HasRows) {
                    mySqlDataReader.Dispose();
                } else {
                    while (mySqlDataReader.Read()) {
                        Geofence geofence = new Geofence();
                        geofence.Id = mySqlDataReader.GetInt32("gf_id");
                        geofence.Name = mySqlDataReader.GetString("gf_name");
                        geofence.Tracks = mySqlDataReader.GetString("gf_trks");

                        string geofenceData = (string)mySqlDataReader["gf_data"];
                        geofenceData = geofenceData.Replace("),( ", "|");
                        geofenceData = geofenceData.Replace(")", string.Empty);
                        geofenceData = geofenceData.Replace("(", string.Empty);
                        geofenceData = geofenceData.Replace(" ", string.Empty);

                        List<string> points = geofenceData.Split('|').ToList();
                        foreach (string point in points) {
                            string[] coordinates = point.Split(',');
                            double latitude = double.Parse(coordinates[0]);
                            double longitude = double.Parse(coordinates[1]);
                            Coordinate location = new Coordinate(latitude, longitude);
                            geofence.addPoint(location);
                        }
                        geofences.Add(geofence);
                    }
                    company.Geofences = geofences;
                    mySqlDataReader.Dispose();
                }
            } catch (MySqlException mySqlException) {
                throw new QueryException(1, mySqlException.Message);
            } catch (QueryException queryException) {
                throw queryException;
            } catch (Exception exception) {
                throw new QueryException(1, exception.Message);
            } finally {
                mysqlConnection.Close();
            }
        }