Display number of images with GPS

A forum for discussing possible new features or changes to netPhotoGraphics. But NOTE, only a formal request via the GitHub repository ticket system is tracked or responded to.
Post Reply
Mates-K1
Posts: 34
Joined: Tue Aug 28, 2018 9:43 pm
Location: Ústí nad Orlicí, Czech Republic

Display number of images with GPS

Post by Mates-K1 »

Hi Stephen,
Could you please suggest me a code to display the number of images with GPS coordinates from the total number of images in the gallery?

Either so I can put it somewhere in the theme, or maybe this information could appear on the Gallery Stats page.

And maybe if I go a little further with the idea, maybe this information would be interesting for each album in the administration (e.g. in the right column).

I have already abandoned the idea of displaying a map with all images with GPS, because I think it would be very heavy on the server.
stephenbillard
Site Admin
Posts: 94
Joined: Tue Aug 14, 2018 6:33 pm
Location: Huntington Beach, CA, USA

Re: Display number of images with GPS

Post by stephenbillard »

The following loop will find images in the album that have gps data:

Code: Select all

		$count = 0;
		$images = $album->getImages(0, 0, null, null, false);
		$total_images = count($images);
		foreach ($images as $an_image) {
			$image = newImage($album, $an_image);
			$lat = (string) $image->getGPSLatitude();
			$long = (string) $image->getGPSLongitude();
			if (!(empty($lat) || empty($long))) {
		
				/* this image has geo data, so count it or whatever */
				$count ++;
		
			}
		}
So far as performance is concerned I do not think this will add much to the processing. netPhotoGraphics caches the list of images and any image object that is instantiated. Since if you are showing a map of the album with image points the image list and all the images will have already been cached so it is just the above loop that will be added to the processing overhead.
-Stephen
stephenbillard
Site Admin
Posts: 94
Joined: Tue Aug 14, 2018 6:33 pm
Location: Huntington Beach, CA, USA

Re: Display number of images with GPS

Post by stephenbillard »

You could also use an SQL query to get the count:

Code: Select all

$sql = 'SELECT count(*) FROM ' . prefix('images') . ' WHERE `albumid`=' . $album->id . ' and `gpslatitude` is not null and `gpslongitude` is not null';
$row = query_single_row($sql);
$count = reset($row);
-Stephen
Post Reply