# X and Y coordinates to latitude and longitude

**URL:** https://discuss.elastic.co/t/x-and-y-coordinates-to-latitude-and-longitude/113920
**Category:** Logstash
**Created:** [January 3, 2018, 12:44pm UTC](https://discuss.elastic.co/t/x-and-y-coordinates-to-latitude-and-longitude/113920 "2018-01-03T12:44:53Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![RoyS](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@RoyS](https://discuss.elastic.co/u/RoyS)
#### Post date: [January 3, 2018, 12:44pm UTC](https://discuss.elastic.co/t/x-and-y-coordinates-to-latitude-and-longitude/113920/1 "2018-01-03T12:44:53Z")

</div>

Hi,  
We have lots of locations with x,y coordinates but Logstash need lat, long values.  
Could you please show how to convert from one to the other in a .config file.  
Thanks  
Roy

---

<div class="post-metadata">

### Author: ![ericohtake](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ericohtake/32/24539_2.png) [@ericohtake](https://discuss.elastic.co/u/ericohtake)
#### Post date: [January 3, 2018, 4:12pm UTC](https://discuss.elastic.co/t/x-and-y-coordinates-to-latitude-and-longitude/113920/2 "2018-01-03T16:12:42Z")

</div>

Can you post some of the data you have and the expected outcome?

---

<div class="post-metadata">

### Author: ![RoyS](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@RoyS](https://discuss.elastic.co/u/RoyS)
#### Post date: [January 3, 2018, 4:39pm UTC](https://discuss.elastic.co/t/x-and-y-coordinates-to-latitude-and-longitude/113920/3 "2018-01-03T16:39:14Z")

</div>

Hi,  
The values in the document are of the form:  
"x": 533209,  
"y": 243518,

I would like to turn it to a geo location to map as a heat map.  
Thanks

---

<div class="post-metadata">

### Author: ![ericohtake](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ericohtake/32/24539_2.png) [@ericohtake](https://discuss.elastic.co/u/ericohtake)
#### Post date: [January 4, 2018, 2:51pm UTC](https://discuss.elastic.co/t/x-and-y-coordinates-to-latitude-and-longitude/113920/4 "2018-01-04T14:51:01Z")

</div>

You need to create a geopoint object field with your lat and long.  
Give a read on this short documentation, it will help you on building your config.  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-point.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-point.html)

```
> {
> "text": "Geo-point as an object",
> "location": { 
> "lat": 41.12,
> "lon": -71.34
> }
> }

```

I'd get the fields, extract the values without the strings, and put them together in a new geopoint field. Something like this:

```
mutate {
  add_field => ["[geoip][location]", "%{longitude}" ]
  add_field => ["[geoip][location]", "%{latitude}" ]
}

```

Your outcome must be a field with the two coordinates together so Kibana can pick it up and build the points on the map for you.

---

<div class="post-metadata">

### Author: ![RoyS](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@RoyS](https://discuss.elastic.co/u/RoyS)
#### Post date: [January 5, 2018, 8:34am UTC](https://discuss.elastic.co/t/x-and-y-coordinates-to-latitude-and-longitude/113920/5 "2018-01-05T08:34:12Z")

</div>

Hi,  
Many thanks for your reply. It helped me.  
What I was looking for is how to convert x,y coordinates to lat, lon. I found this article on the web. [WSG84 to lat, lon](https://carra-lucia-ltd.co.uk/2014/07/28/how-to-convert-easting-and-northing-points-to-latitude-and-longitude-for-coordinates-calculation/)  
I do not know the accuracy yet, but hope it will help somebody else.  
Kindest regards,

---

<div class="post-metadata">

### Author: ![RoyS](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@RoyS](https://discuss.elastic.co/u/RoyS)
#### Post date: [January 5, 2018, 11:00am UTC](https://discuss.elastic.co/t/x-and-y-coordinates-to-latitude-and-longitude/113920/6 "2018-01-05T11:00:30Z")

</div>

Hi,  
Need a bit more help. Logstash 6:

I have lat, lon now, and need to create a [location][lat] & [location][lon] geo\_point.  
The following is in the filter { mutate section  
convert =\> { "LAT" =\> "float" }  
convert =\> { "LON" =\> "float" }  
add\_field =\> { "[location][lat]" =\> "" }  
add\_field =\> { "[location][lon]" =\> "" }  
copy =\> { "LAT" =\> "[location][lat]" }  
copy =\> { "LON" =\> "[location][lon]" }  
convert =\> { "[location][lat]" =\> "float"}  
convert =\> { "[location][lon]" =\> "float"}

but I get  
"location": {  
"lat": "",  
"lon": ""  
},  
Thank you in advance.

---

<div class="post-metadata">

### Author: ![ericohtake](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ericohtake/32/24539_2.png) [@ericohtake](https://discuss.elastic.co/u/ericohtake)
#### Post date: [January 6, 2018, 4:35am UTC](https://discuss.elastic.co/t/x-and-y-coordinates-to-latitude-and-longitude/113920/7 "2018-01-06T04:35:04Z")

</div>

Can you edit the post and put your code in a preformatted text block using the button \</\> in the editor here?

I have a config that looks similar to the code below. After you have the coordinates in the appropriate fields, you need to reference them by using %{field\_name}

```
# A geoip location field will be created with your 2 coordinates.
    mutate {
      add_field => ["[geoip][location]", "%{longitude}" ]
      add_field => ["[geoip][location]", "%{latitude}" ]
    }

# If the geoip location field is not in float type yet, you can finally convert it:
    mutate {
      convert => ["[geoip][location]", "float" ]
    }

```

As an example, you will get this result:

```
{
                 "geoip" => {
                    "location" => [
                      [0] 144.36672,
                      [1] 43.011598
                    ]
                 },
              "latitude" => "43.011598",
             "longitude" => "144.36672",
            "@timestamp" => 2018-01-05T09:47:40.719Z,
              "@version" => "1"
}
```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [February 3, 2018, 4:35am UTC](https://discuss.elastic.co/t/x-and-y-coordinates-to-latitude-and-longitude/113920/8 "2018-02-03T04:35:06Z")

</div>

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