CONVERT GSM COORDINATE TO GD COORDINATE

Hi to all

I'm just trying to convert GSM to GD

For example GMS N 39° 56' 41.673'' O 3° 43' 47.872'' to GET GD 39.94490923478156 and -3.729964618217764

I have this config

csv {
      columns => ["MCC","MNC","LAC","CI","MNEMOTECNICO","LATITUDGSM","LONGITUDGSM","MAPDATUM","AZIMUTH","REDACCESO","ESTADO"]
      separator => ";"
      }
	  
      
	  
 grok { match => ["message","\;%{GRADOS:grados_lat}%{MINUTOS:minutos_lat}%{SEGUNDOS:segundos_lat}\;%{GRADOS:grados_lon}%{MINUTOS:minutos_lon}%{SEGUNDOS:segundos_lon}\;"]}

 mutate {gsub => ["minutos_lat","N","",
  "minutos_lon","W",""]
  add_field =>["LATITUD"]
   add_field =>["LONGITUD"]} 
 
 ruby { code => "event['LATITUD'] = ((((event['segundos_lat']/ 60) + event['minutos_lat'])/60)+event['grados_lat'])"}
 ruby { code => "event['LONGITUD'] = ((((event['segundos_lon']/ 60) + event['minutos_lon'])/60)+event['grados_lon'])"}
 
 
 
  mutate{
     
	  add_field => ["CELL","%{MCC}-%{MNC}-%{LAC}-%{CI}"]
      convert => ["LATITUD","float"]
      convert => ["LONGITUD","float"]
      rename => ["LATITUD","[location][lat]"]
      rename => ["LONGITUD","[location][lon]"]
      remove_field => ["_score"]
      
  }   
  }

but my LATITUD and LONGITUD are not being created, may someone help?

BR

1 Like

What version of logstash are you using ?
Use event.get() and event.set(..., ....)

Looks something related to ETSI-TS-102657 :slight_smile:
I will suppose data reference for CI are provided as CSV as follow

604;01;100;26120;MNEMOTECNICO;N 39° 56' 41.673'';O 3° 43' 47.872'';MAPDATUM;AZIMUTH;REDACCESO;ESTADO

The following cnfiguration may help you to get the geo_point for each CI

input { stdin { } }

filter {

  csv {
      columns => ["MCC","MNC","LAC","CI","MNEMOTECNICO","LATITUDGSM","LONGITUDGSM","MAPDATUM","AZIMUTH","REDACCESO","ESTADO"]
      separator => ";"
      }
	  
	  #604;01;100;26120;MNEMOTECNICO;N 39° 56' 41.673'';O 3° 43' 47.872'';MAPDATUM;AZIMUTH;REDACCESO;ESTADO
	  #° is coded as \xF8
	  mutate {
			gsub => [
						"LATITUDGSM","N\s*","",
						"LATITUDGSM","\\xF8","",
						"LATITUDGSM","'","",
						"LATITUDGSM","''","",
						"LONGITUDGSM","O\s*","",
						"LONGITUDGSM","\\xF8","",
						"LONGITUDGSM","'","",
						"LONGITUDGSM","''",""
					]
	  }
	  
      grok {
			match => { "LATITUDGSM" => "%{NUMBER:grados_lat} %{NUMBER:minutos_lat} %{NUMBER:segundos_lat}" }
			tag_on_failure => ["grok_failure_LATITUDGSM"]
			}
  
	  grok {
			match => { "LONGITUDGSM" => "%{NUMBER:grados_lon} %{NUMBER:minutos_lon} %{NUMBER:segundos_lon}" }
			tag_on_failure => ["grok_failure_LONGITUDGSM"]
			}
	
	  mutate {
			  add_field => ["CELL","%{MCC}-%{MNC}-%{LAC}-%{CI}"]
			  convert => ["grados_lat", "float"]
			  convert => ["minutos_lat", "float"]
			  convert => ["segundos_lat", "float"]
			  convert => ["grados_lon", "float"]
			  convert => ["minutos_lon", "float"]
			  convert => ["segundos_lon", "float"]
			}   
  
	## North/East => deg + (min / 60.0) + (sec / 3600.0)
	## South/West => deg - (min / 60.0) - (sec / 3600.0)
	ruby { code => "
					if event.get('grados_lat') >= 0
						event.set('[location][lat]', (event.get('grados_lat') + (event.get('minutos_lat') / 60.0) + (event.get('segundos_lat') / 3600.0)))
					else
						event.set('[location][lat]', (event.get('grados_lat') - (event.get('minutos_lat') / 60.0) - (event.get('segundos_lat') / 3600.0)))
					end
					
					if event.get('grados_lon') >= 0
						event.set('[location][lon]', (event.get('grados_lon') + (event.get('minutos_lon') / 60.0) + (event.get('segundos_lon') / 3600.0)))
					else
						event.set('[location][lon]', (event.get('grados_lon') - (event.get('minutos_lon') / 60.0) - (event.get('segundos_lon') / 3600.0)))
					end
				   "
	}
  }
  

output {
  #elasticsearch { hosts => ["localhost:9200"] }
  stdout { codec => rubydebug }
}

The ouput should be something like this when running on logstash

[2020-11-25T17:03:41,125][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600}
604;01;100;26120;MNEMOTECNICO;N 39° 56' 41.673'';O 3° 43' 47.872'';MAPDATUM;AZIMUTH;REDACCESO;ESTADO
[2020-11-25T17:03:44,212][WARN ][logstash.codecs.line     ][main][67468ecbdd670bdedf4cf36130eb14b4c81c184d2aaf9a191d8d28f3b4ca3fc0] Received an event
that has a different character encoding than you configured. {:text=>"604;01;100;26120;MNEMOTECNICO;N 39\\xF8 56' 41.673'';O 3\\xF8 43' 47.872'';MAPDA
TUM;AZIMUTH;REDACCESO;ESTADO\\r", :expected_charset=>"UTF-8"}
{
     "minutos_lon" => 43.0,
      "LATITUDGSM" => "39 56 41.673",
     "minutos_lat" => 56.0,
        "location" => {
        "lon" => 3.7299644444444446,
        "lat" => 39.94490916666666
    },
        "MAPDATUM" => "MAPDATUM",
       "REDACCESO" => "REDACCESO",
             "LAC" => "100",
      "grados_lon" => 3.0,
      "@timestamp" => 2020-11-25T16:03:44.240Z,
      "grados_lat" => 39.0,
             "MNC" => "01",
    "MNEMOTECNICO" => "MNEMOTECNICO",
             "MCC" => "604",
            "CELL" => "604-01-100-26120",
    "segundos_lat" => 41.673,
         "AZIMUTH" => "AZIMUTH",
    "segundos_lon" => 47.872,
          "ESTADO" => "ESTADO\\r",
            "host" => "synapticiel",
         "message" => "604;01;100;26120;MNEMOTECNICO;N 39\\xF8 56' 41.673'';O 3\\xF8 43' 47.872'';MAPDATUM;AZIMUTH;REDACCESO;ESTADO\\r",
     "LONGITUDGSM" => "3 43 47.872",
        "@version" => "1",
              "CI" => "26120"
}
2 Likes

GREAT ANSWER MAN! thanks a lot! I will try asap i give you feedback

BR really great post!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.