Update documentation - increase Doxygen usage
[geeqie.git] / plugins / geocode-parameters / geocode-parameters.awk
1 #!/usr/bin/awk -f
2 #
3 ## @file
4 ## @brief This file is used by the Search option "search on geo-position".
5 ##
6 ## It is used to decode the results of internet or other searches
7 ## to extract a geo-position from a text string.
8 ##
9 ## To include other searches, follow the examples below and
10 ## store the file in:  
11 ## ~/.config/geeqie/applications/geocode-parameters.awk  
12 ## Ensure the returned value is either in the format:  
13 ## 89.123 179.123  
14 ## or  
15 ## Error: $0  
16 ##
17
18 function check_parameters(latitude, longitude)
19     {
20     # Ensure the parameters are numbers
21     if ((latitude == (latitude+0)) && (longitude == (longitude+0)))
22         {
23         if (latitude >= -90 && latitude <= 90 &&
24                         longitude >= -180 && longitude <= 180)
25             {
26             return latitude " " longitude
27             }
28         else
29             {
30             return "Error: " latitude " " longitude
31             }
32         }
33     else
34         {
35         return "Error: " latitude " " longitude
36         }
37     }
38
39 # This awk file is accessed by the decode_geo_parameters() function
40 # in search.c. The call is of the format:
41 # echo "string_to_be_searched" | awk -f geocode-parameters.awk
42 #
43 # Search the input string for known formats.
44 {
45 if (index($0, "http://www.geonames.org/maps/google_"))
46     {
47     # This is a drag-and-drop or copy-paste from a geonames.org search
48     # in the format e.g.
49     # http://www.geonames.org/maps/google_51.513_-0.092.html
50
51     gsub(/http:\/\/www.geonames.org\/maps\/google_/, "")
52     gsub(/.html/, "")
53     gsub(/_/, " ")
54     print check_parameters($1, $2)
55     }
56
57 else if (index($0, "https://www.openstreetmap.org/search?query="))
58     {
59     # This is a copy-paste from an openstreetmap.org search
60     # in the format e.g.
61     # https://www.openstreetmap.org/search?query=51.4878%2C-0.1353#map=11/51.4880/-0.1356
62
63     gsub(/https:\/\/www.openstreetmap.org\/search\?query=/, "")
64     gsub(/#map=.*/, "")
65     gsub(/%2C/, " ")
66     print check_parameters($1, $2)
67     }
68
69 else if (index($0, "https://www.openstreetmap.org/#map="))
70     {
71     # This is a copy-paste from an openstreetmap.org search
72     # in the format e.g.
73     # https://www.openstreetmap.org/#map=5/18.271/16.084
74
75     gsub(/https:\/\/www.openstreetmap.org\/#map=[^\/]*/,"")
76     gsub(/\//," ")
77     print check_parameters($1, $2)
78     }
79
80 else if (index($0, "https://www.google.com/maps/"))
81     {
82     # This is a copy-paste from a google.com maps search
83     # in the format e.g.
84     # https://www.google.com/maps/place/London,+UK/@51.5283064,-0.3824815,10z/data=....
85
86     gsub(/https:\/\/www.google.com\/maps.*@/,"")
87     sub(/,/," ")
88     gsub(/,.*/,"")
89     print check_parameters($1, $2)
90     }
91
92 else if (index($0,".html"))
93     {
94     # This is an unknown html address
95
96     print "Error: " $0
97     }
98
99 else if (index($0,"http"))
100     {
101     # This is an unknown html address
102
103     print "Error: " $0
104     }
105
106 else if (index($0, ","))
107     {
108     # This is assumed to be a simple lat/long of the format:
109     # 89.123,179.123
110
111     split($0, latlong, ",")
112     print check_parameters(latlong[1], latlong[2])
113     }
114
115 else
116     {
117     # This is assumed to be a simple lat/long of the format:
118     # 89.123 179.123
119
120     split($0, latlong, " ")
121     print check_parameters(latlong[1], latlong[2])
122     }
123 }