Skip to content

Commit

Permalink
Splitting the SecGuardID gps pathway
Browse files Browse the repository at this point in the history
  • Loading branch information
JerelHJ committed Feb 1, 2024
1 parent 495beb8 commit 95cd8d5
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 79 deletions.
Binary file added Images/Individual_Plots/plot_SecGuardID_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Individual_Plots/plot_SecGuardID_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Images/plot.png
Binary file not shown.
Binary file added Images/plot_SecGuardID_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/plot_SecGuardID_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 5 additions & 25 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

include_once("GeoDBConnection.php");

$query = "SELECT SecGuardID, Name FROM secguard";
$query = "SELECT * FROM secguard";
$result = $conn->query($query);

?>
Expand All @@ -46,34 +46,14 @@
<!--<img src="" height="250" width="600" class="center">
<img src="" class="center">-->
<p>
- Select Security Guard's name to track pathway -
- Security Guard's pathway -
</p><br>

<label for="guard">Select Security Guard:</label>
<form action="" method="post">
<select required name="guard" id="guard">
<?php
// Check if there are any rows in the result set
if ($result->num_rows > 0) {
// Loop through each row and generate an option element
while ($row = $result->fetch_assoc()) {
$id = $row['SecGuardID'];
$name = $row['Name'];
echo "<option value='$id'>$name</option>";
}
}
else {
echo "<option value='' disabled>No options available</option>";
}


// Close the database connection
$conn->close();
?>
</select>
<input type="submit" value="Submit">
</form>
<p>
<!-- <img src="Images/plot.png" alt="Image" width="100%" height="80%"> -->
<img src="Images\plot_SecGuardID_1.png" alt="Image" width="100%" height="80%">
<img src="Images\plot_SecGuardID_2.png" alt="Image" width="100%" height="80%">
</p>
<button onclick="runSeer()"> Run Seer </button>
<br><br>
Expand Down
121 changes: 67 additions & 54 deletions python/seer2.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import csv
import numpy as np
import cartopy.crs as ccrs
#%matplotlib
import matplotlib.pyplot as plt
import cartopy.io.img_tiles as cimgt
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import io,time
import io
from urllib.request import urlopen, Request
from PIL import Image
plt.ion()
import pandas as pd
from sqlalchemy import create_engine
import sys

import sys
import os

# Replace the placeholder values with your actual database credentials
servername = 'localhost'
Expand All @@ -23,82 +22,96 @@
connection_string = f'mysql+mysqlconnector://root:@localhost:3306/geotrackdb'
engine = create_engine(connection_string)
qry = 'SELECT * FROM records;'
df = pd.read_sql_query(qry,engine)
df = pd.read_sql_query(qry, engine)

# You can use the DataFrame columns to access specific data
recordid = df['RecordID'].tolist()
secguard = df['SecGuardID'].tolist()
secguards = df['SecGuardID'].unique() # Get unique SecGuardIDs
date = df['RecordTime'].tolist()
alts = df['Altitude'].tolist()
lats = df['Latitude'].tolist()
lons = df['Longitude'].tolist()
floors = df['Floor'].tolist()


def image_spoof(self, tile):
api_url = self._image_url(tile) # get the url of the street map API
req = Request(api_url) # start request
req.add_header('User-agent','Anaconda 3') # add user agent to request
response = urlopen(req) #Open the URL and get the response
im_data = io.BytesIO(response.read()) # Get image data
response.close() # Close the url
img = Image.open(im_data) # open image using PIL
api_url = self._image_url(tile) # get the url of the street map API
req = Request(api_url) # start request
req.add_header('User-agent', 'Anaconda 3') # add user agent to request
response = urlopen(req) # Open the URL and get the response
im_data = io.BytesIO(response.read()) # Get image data
response.close() # Close the url
img = Image.open(im_data) # open image using PIL
img = img.convert(self.desired_tile_form) # Convert the image format
return img, self.tileextent(tile), 'lower' # Return the image, tile extent, and vertical alignment


return img, self.tileextent(tile), 'lower' # Return the image, tile extent, and vertical alignment

cimgt.GoogleTiles.get_image = image_spoof # Spoof the web request for street map
osm_img = cimgt.GoogleTiles() # Download the spoofed street map using the GoogleTiles class
cimgt.GoogleTiles.get_image = image_spoof # Spoof the web request for street map
osm_img = cimgt.GoogleTiles() # Download the spoofed street map using the GoogleTiles class
lat_zoom = 0.0005 # Decreased zoom for latitude
lon_zoom = 0.0025 # Decreased zoom for longitude

if lons and lats:
extent = [np.min(lons) - lon_zoom, np.max(lons) + lon_zoom, np.min(lats) - lat_zoom, np.max(lats) + lat_zoom]
# Create a directory for individual plots
individual_plots_directory = 'Images/Individual_Plots'
os.makedirs(individual_plots_directory, exist_ok=True)

for secguard in secguards:
secguard_df = df[df['SecGuardID'] == secguard]

if lons and lats:
extent = [
np.min(secguard_df['Longitude']) - lon_zoom,
np.max(secguard_df['Longitude']) + lon_zoom,
np.min(secguard_df['Latitude']) - lat_zoom,
np.max(secguard_df['Latitude']) + lat_zoom
]

fig, ax1 = plt.subplots(figsize=(14, 12), facecolor='#FCFCFC', subplot_kw={'projection': osm_img.crs})
ax1.set_title(f'GPS Tracker Map - SecGuardID {secguard}', fontsize=16)

# Set the extents of the map
ax1.set_extent(extent)

fig = plt.figure(figsize=(14, 12), facecolor='#FCFCFC')
ax1 = plt.axes(projection=osm_img.crs)
ax1.set_title('GPS Tracker Map', fontsize=16)
# Set longitude and latitude indicators
ax1.set_xticks(np.linspace(extent[0], extent[1], 7), crs=ccrs.PlateCarree())
ax1.set_yticks(np.linspace(extent[2], extent[3], 7)[1:], crs=ccrs.PlateCarree())

# Set the extents of the map
ax1.set_extent(extent)
# Format the longitude and latitude tick labels
lon_format = LongitudeFormatter(number_format='0.1f', degree_symbol='', dateline_direction_label=True)
lat_format = LatitudeFormatter(number_format='0.1f', degree_symbol='')

# Set longitude and latitude indicators
ax1.set_xticks(np.linspace(extent[0], extent[1], 7), crs=ccrs.PlateCarree())
ax1.set_yticks(np.linspace(extent[2], extent[3], 7)[1:], crs=ccrs.PlateCarree())
# Set the major formatters for longitude and latitude
ax1.xaxis.set_major_formatter(lon_format)
ax1.yaxis.set_major_formatter(lat_format)

# Format the longitude and latitude tick labels
lon_format = LongitudeFormatter(number_format='0.1f', degree_symbol='', dateline_direction_label=True)
lat_format = LatitudeFormatter(number_format='0.1f', degree_symbol='')
# Set tick label font sizes
ax1.xaxis.set_tick_params(labelsize=14)
ax1.yaxis.set_tick_params(labelsize=14)

# Set the major formatters for longitude and latitude
ax1.xaxis.set_major_formatter(lon_format)
ax1.yaxis.set_major_formatter(lat_format)
# Empirical calculation of scale based on zoom
scale = np.ceil(-np.sqrt(2) * np.log(np.divide((extent[1] - extent[0]) / 2.0, 350.0)))

# Set tick label font sizes
ax1.xaxis.set_tick_params(labelsize=14)
ax1.yaxis.set_tick_params(labelsize=14)
# Ensure scale does not exceed 19
scale = (scale < 20) and scale or 19

# Empirical calculation of scale based on zoom
scale = np.ceil(-np.sqrt(2) * np.log(np.divide((extent[1] - extent[0]) / 2.0, 350.0)))
# Add the spoofed OSM image to the map with the specified zoom level
ax1.add_image(osm_img, int(scale + 1))

# Ensure scale does not exceed 19
scale = (scale < 20) and scale or 19
for index in range(0, len(secguard_df['Longitude']), 5):
ax1.plot(secguard_df['Longitude'].iloc[index], secguard_df['Latitude'].iloc[index], markersize=10,
marker='o', linestyle='', color='Black', transform=ccrs.PlateCarree(), label='GPS Point') # plot points

# Add the spoofed OSM image to the map with the specified zoom level
ax1.add_image(osm_img, int(scale + 1))
annotation_text = f'Alt: {secguard_df["Altitude"].iloc[index]:.2f} meters\nFloor: {secguard_df["Floor"].iloc[index]}'
ax1.text(secguard_df['Longitude'].iloc[index], secguard_df['Latitude'].iloc[index], annotation_text,
fontsize=10, color='red', transform=ccrs.PlateCarree(), ha='right', va='bottom')

plt.pause(0.1)
else:
print(f"Error: No data for SecGuardID {secguard}")

for index in range(0, len(lons), 5):
ax1.plot(lons[index], lats[index], markersize=10, marker='o', linestyle='',
color='Black', transform=ccrs.PlateCarree(), label='GPS Point') # plot points
# Save individual plots
plt.savefig(f'{individual_plots_directory}/plot_SecGuardID_{secguard}.png')
plt.show()

annotation_text = f'Alt: {alts[index]:.2f} meters\nFloor: {floors[index]}'
ax1.text(lons[index], lats[index], annotation_text,
fontsize=10, color='red', transform=ccrs.PlateCarree(), ha='right', va='bottom')
else:
print("Error: lons or lats list is empty.")

plt.pause(0.01)
else:
print("Error: lons or lats list is empty.")

plt.savefig('Images/plot.png')

0 comments on commit 95cd8d5

Please sign in to comment.