Search code examples
algorithmgisgeowkt

Giving a linestring width to create a polygon


I have a WKT linestring and I want to use it to search for intersections in postgis but the linestring has some level of error and won't perfectly intersect the things stored in postgis so I want to convert it to a polygon and give it n meters thickness so that it will intersect with things next to it.

An example of what I want to do. Green being the polygon created from the line enter image description here

The language of the solution doesn't matter too much. I can adapt the solution to work so I am just looking for some general algorithm which can create the polygon. The linestring contains geographical coords so I think working out how far away n meters is could be difficult.

I think the best way to go about this is drawing normals off the linestring and marking the point that's far enough away

enter image description here


Solution

  • Looks like this can be done with postgis. http://www.postgis.org/docs/ST_Buffer.html

    enter image description here

    SELECT ST_Buffer(
     ST_GeomFromText(
      'LINESTRING(50 50,150 150,150 50)'
     ), 10, 'endcap=round join=round');