source: extensions/piwigo-openstreetmap/include/functions_metadata.php @ 29761

Last change on this file since 29761 was 24677, checked in by ddtddt, 11 years ago

[extensions] - piwigo-openstreetmap - add file for translate

File size: 2.0 KB
Line 
1<?php
2/***********************************************
3* File      :   functions_metadata.php
4* Project   :   piwigo-openstreetmap
5* Descr     :   Read Geotag Metdata
6* Base on   :   RV Maps & Earth plugin
7*
8* Created   :   30.05.2013
9*
10* Copyright 2013 <xbgmsharp@gmail.com>
11*
12* This program is free software: you can redistribute it and/or modify
13* it under the terms of the GNU General Public License as published by
14* the Free Software Foundation, either version 3 of the License, or
15* (at your option) any later version.
16*
17* This program is distributed in the hope that it will be useful,
18* but WITHOUT ANY WARRANTY; without even the implied warranty of
19* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20* GNU General Public License for more details.
21*
22* You should have received a copy of the GNU General Public License
23* along with this program.  If not, see <http://www.gnu.org/licenses/>.
24*
25************************************************/
26
27function osm_parse_fract( $f )
28{
29        $nd = explode( '/', $f );
30        return $nd[0] ? ($nd[0]/$nd[1]) : 0;
31}
32
33function osm_parse_lat_lon( $arr )
34{
35        $v=0;
36        $v += osm_parse_fract( $arr[0] );
37        $v += osm_parse_fract( $arr[1] )/60;
38        $v += osm_parse_fract( $arr[2] )/3600;
39        return $v;
40}
41
42function osm_exif_to_lat_lon( $exif )
43{
44        $exif = array_intersect_key( $exif, array_flip( array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude') ) );
45        if ( count($exif)!=4 )
46                return '';
47        if ( !in_array($exif['GPSLatitudeRef'], array('S', 'N') ) )
48                return 'GPSLatitudeRef not S or N';
49        if ( !in_array($exif['GPSLongitudeRef'], array('W', 'E') ) )
50                return 'GPSLongitudeRef not W or E';
51        if (!is_array($exif['GPSLatitude']) or !is_array($exif['GPSLongitude']) )
52                return 'GPSLatitude and GPSLongitude are not arrays';
53
54        $lat = osm_parse_lat_lon( $exif['GPSLatitude'] );
55        if ( $exif['GPSLatitudeRef']=='S' )
56                $lat = -$lat;
57        $lon = osm_parse_lat_lon( $exif['GPSLongitude'] );
58        if ( $exif['GPSLongitudeRef']=='W' )
59                $lon = -$lon;
60        return array ($lat,$lon);
61}
62
63?>
Note: See TracBrowser for help on using the repository browser.