File: geocode-parameters.awk

package info (click to toggle)
geeqie 1%3A2.5-8
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 16,780 kB
  • sloc: cpp: 110,189; xml: 11,497; sh: 3,681; awk: 124; perl: 88; python: 80; makefile: 23
file content (127 lines) | stat: -rw-r--r-- 3,279 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/awk -f
#
## @file
## @brief Used by the Search option "search on geo-position".
##
## It is used to decode the results of internet or other searches
## to extract a geo-position from a text string.
##
## To include other searches, follow the examples below and
## store the file in:  
## ~/.config/geeqie/applications/geocode-parameters.awk  
## Ensure the returned value is either in the format:  
## 89.123 179.123  
## or  
## Error: $0  
##

BEGIN {
LINT = "fatal"
}

function check_parameters(latitude, longitude)
    {
    # Ensure the parameters are numbers
    if ((latitude == (latitude+0)) && (longitude == (longitude+0)))
        {
        if (latitude >= -90 && latitude <= 90 &&
                        longitude >= -180 && longitude <= 180)
            {
            return latitude " " longitude
            }
        else
            {
            return "Error: " latitude " " longitude
            }
        }
    else
        {
        return "Error: " latitude " " longitude
        }
    }

# This awk file is accessed by the decode_geo_parameters() function
# in search.cc. The call is of the format:
# echo "string_to_be_searched" | awk -f geocode-parameters.awk
#
# Search the input string for known formats.
{
if (index($0, "https://www.geonames.org/maps/google_"))
    {
    # This is a drag-and-drop or copy-paste from a geonames.org search
    # in the format e.g.
    # https://www.geonames.org/maps/google_51.513_-0.092.html

    gsub(/https:\/\/www.geonames.org\/maps\/google_/, "")
    gsub(/.html/, "")
    gsub(/_/, " ")
    print check_parameters($1, $2)
    }

else if (index($0, "https://www.openstreetmap.org/search?query="))
    {
    # This is a copy-paste from an openstreetmap.org search
    # in the format e.g.
    # https://www.openstreetmap.org/search?query=51.4878%2C-0.1353#map=11/51.4880/-0.1356

    gsub(/https:\/\/www.openstreetmap.org\/search\?query=/, "")
    gsub(/#map=.*/, "")
    gsub(/%2C/, " ")
    print check_parameters($1, $2)
    }

else if (index($0, "https://www.openstreetmap.org/#map="))
    {
    # This is a copy-paste from an openstreetmap.org search
    # in the format e.g.
    # https://www.openstreetmap.org/#map=5/18.271/16.084

    gsub(/https:\/\/www.openstreetmap.org\/#map=[^\/]*/,"")
    gsub(/\//," ")
    print check_parameters($1, $2)
    }

else if (index($0, "https://www.google.com/maps/"))
    {
    # This is a copy-paste from a google.com maps search
    # in the format e.g.
    # https://www.google.com/maps/place/London,+UK/@51.5283064,-0.3824815,10z/data=....

    gsub(/https:\/\/www.google.com\/maps.*@/,"")
    sub(/,/," ")
    gsub(/,.*/,"")
    print check_parameters($1, $2)
    }

else if (index($0,".html"))
    {
    # This is an unknown html address

    print "Error: " $0
    }

else if (index($0,"http"))
    {
    # This is an unknown html address

    print "Error: " $0
    }

else if (index($0, ","))
    {
    # This is assumed to be a simple lat/long of the format:
    # 89.123,179.123

    split($0, latlong, ",")
    print check_parameters(latlong[1], latlong[2])
    }

else
    {
    # This is assumed to be a simple lat/long of the format:
    # 89.123 179.123

    split($0, latlong, " ")
    print check_parameters(latlong[1], latlong[2])
    }
}