# Logstash - Calculate a midpoint from a Geo polygon

**URL:** <https://discuss.elastic.co/t/logstash-calculate-a-midpoint-from-a-geo-polygon/154030>\
**Category:** Logstash\
**Created:** [October 25, 2018, 3:01pm UTC](https://discuss.elastic.co/t/logstash-calculate-a-midpoint-from-a-geo-polygon/154030 "2018-10-25T15:01:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adde](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@adde](https://discuss.elastic.co/u/adde)\
**Post date:** [October 25, 2018, 3:01pm UTC](https://discuss.elastic.co/t/logstash-calculate-a-midpoint-from-a-geo-polygon/154030/1 "2018-10-25T15:01:15Z")

</div>

Hello,

I want to calculate a midpoint from a geo-polygon. I know I should use the ruby filter but I don't know how.

My formula looks like this:

pmidlat = plat2 - ((plat2 - plat3) / 2)  
pmidlong = plong4 - ((plong4 - plong3) / 2)

My geo polygon is an array with nested fields and looks like this:

"StageLocation": [

{"GPSHeight": 0, "GPSLatitude": 44.13380000000005, "GPSLongitude": 39.126500000000064},  
{"GPSHeight": 0, "GPSLatitude": 44.13380000000005, "GPSLongitude": 39.06050000000006},  
{"GPSHeight": 0, "GPSLatitude": 44.06780000000005, "GPSLongitude": 39.06050000000006},  
{"GPSHeight": 0, "GPSLatitude": 44.06780000000005, "GPSLongitude": 39.126500000000064}

],

Could anybody help me or give me some advice? Thank you so much!

---

<div class="post-metadata">

**Author:** ![adde](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@adde](https://discuss.elastic.co/u/adde)\
**Post date:** [October 25, 2018, 3:08pm UTC](https://discuss.elastic.co/t/logstash-calculate-a-midpoint-from-a-geo-polygon/154030/2 "2018-10-25T15:08:17Z")

</div>

This is my \*.conf file:

input {  
kafka {  
bootstrap\_servers =\> "localhost:9092"  
topics =\> ["flink\_to\_apama"]  
client\_id =\> "logstash\_hub"  
}  
}  
filter {  
json {  
source =\> "message"  
}  
split {  
field =\> "Impacts"  
}  
mutate {  
rename =\> { "[Impacts][Location]" =\> "[Ort]"}  
}  
split {  
field =\> "[Ort][StageLocation]"  
}  
ruby{

}  
}  
output {  
elasticsearch {  
hosts =\> ["elasticsearch:9200"]  
index =\> "itesa\_risks"  
document\_type =\> "doc"  
template =\> "/tmp/logstash\_vol/itesa\_mapping.json"  
template\_overwrite =\> true  
}  
}

---

<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:** [November 22, 2018, 3:13pm UTC](https://discuss.elastic.co/t/logstash-calculate-a-midpoint-from-a-geo-polygon/154030/3 "2018-11-22T15:13:38Z")

</div>

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