diff --git a/_posts/2014-02-16-joining-a-list-of-binaries-in-erlang.md b/_posts/2014-02-16-joining-a-list-of-binaries-in-erlang.md index d277fb5..ebf1af0 100644 --- a/_posts/2014-02-16-joining-a-list-of-binaries-in-erlang.md +++ b/_posts/2014-02-16-joining-a-list-of-binaries-in-erlang.md @@ -2,6 +2,7 @@ layout: post title: Joining a List of Binaries in Erlang description: "Description and implementation of a function that joins a list of binaries." +category: posts tags: [erlang, programming, english] image: feature: abstract-3.jpg diff --git a/_posts/2014-02-17-exchange-reverse-proxy-using-nginx.md b/_posts/2014-02-17-exchange-reverse-proxy-using-nginx.md index 735d3f5..b912867 100644 --- a/_posts/2014-02-17-exchange-reverse-proxy-using-nginx.md +++ b/_posts/2014-02-17-exchange-reverse-proxy-using-nginx.md @@ -2,6 +2,7 @@ layout: post title: Exchange Reverse Proxy Using nginx description: "Simple nginx configuration that allows you to proxy most of Microsoft Exchange." +category: posts tags: [nginx, exchange, ops, english] image: feature: abstract-10.jpg diff --git a/_posts/2014-02-24-telegram-and-security.md b/_posts/2014-02-24-telegram-and-security.md index 81b6d84..a9a5247 100644 --- a/_posts/2014-02-24-telegram-and-security.md +++ b/_posts/2014-02-24-telegram-and-security.md @@ -1,7 +1,8 @@ --- layout: post title: Telegram and Security -description: "Simple nginx configuration that allows you to proxy most of Microsoft Exchange." +description: "Some links regarding Telegram and its security model." +category: posts tags: [telegram, whatsapp, app, english] image: feature: abstract-2.jpg diff --git a/_posts/2014-03-23-buffered-polyline.md b/_posts/2014-03-23-buffered-polyline.md new file mode 100644 index 0000000..00eb59b --- /dev/null +++ b/_posts/2014-03-23-buffered-polyline.md @@ -0,0 +1,49 @@ +--- +layout: post +title: Buffered Polyline +description: "Blow up a polyline to search inside the generated polygon." +category: posts +tags: [javascript, programming, english] +image: + feature: abstract-7.jpg + credit: dargadgetz + creditlink: http://www.dargadgetz.com/ios-7-abstract-wallpaper-pack-for-iphone-5-and-ipod-touch-retina/ +comments: true +share: true +--- + +At work, we needed a simple way to buffer a polyline in order to search for stuff along the route from A to B. I'll explain how we used Google's Map API and [JSTS](https://github.com/bjornharrtell/jsts) in order to achieve this easily. + +The first thing we had to do, was to "transform" each element in the overview_path (which the `DirectionsService` returns) to GeoJSON, because that's what JSTS understands. + +{% highlight javascript linenos %} +var overviewPath = response.routes[0].overview_path, + overviewPathGeo = []; +for(var i = 0; i < overviewPath.length; i++) { + overviewPathGeo.push( + [overviewPath[i].lng(), overviewPath[i].lat()] + ); +} +{% endhighlight %} + +The next step was getting `overviewPathGeo` into JSTS and letting it do the work of buffering the line. + +{% highlight javascript linenos %} +var distance = 10/111.12, // Roughly 10km + geoInput = { + type: "LineString", + coordinates: overviewPathGeo + }; +var geoReader = new jsts.io.GeoJSONReader(), + geoWriter = new jsts.io.GeoJSONWriter(); +var geometry = geoReader.read(geoInput).buffer(distance); +var polygon = geoWriter.write(geometry); +{% endhighlight %} + +The `polygon` variable now contains a polygon that neatly fits around the `overviewPath`, with a *distance* (buffer size) of roughly 10km. + +Since it is nested, you need to call `polygon.coordinates[0]` in order to get back the coordinates of the polygon (as GeoJSON). + +You could then use the the coordinates to draw the generated polygon on the map (along with the route), in order to produce something like this: + +![Image of the resulting polygon]({{ site.url }}/assets/img/buffered-polyline-1.png) diff --git a/assets/img/buffered-polyline-1.png b/assets/img/buffered-polyline-1.png new file mode 100644 index 0000000..b134e01 Binary files /dev/null and b/assets/img/buffered-polyline-1.png differ