.net - How can I interpolate a point along a line string using DbGeography? -
i have linestring dbgeography object , want find point along linestring given fractional value of total distance. example, if give 0.5, should midpoint of line dbgeography object point wkt (well known text).
i've tried digging through dbgeography documentation, no apparent "easy" method seems exist.
i think method similar google maps js api spherical geometry interpolate method. suggestions?
i've done before using following approach:
iterate through linestring's points until find pair of adjacent points between target point must lie (the target distance either given or can computed distance fraction mention); then
use
dbgeography.buffer
on each of 2 points, providing"remaining distance target" + "small distance padding"
* first ,"distance between 2 points" - "remaining distance target" + "small distance padding"
second; thenuse
dbgeography.intersection
on 2 points, obtaining small polygon, not point; thenconvert polygon
dbgeometry
object , takecentroid
; thenconvert result point
dbgeography
object if desired.
note won't technically precise, because geometric centroid not identical geographic center. however, it's enough in case because polygon centroid taken can darn small (e.g. using 1 meter buffer distance padding).
*: distance padding provided try avoid "near misses" due rounding errors floating-point. if had infinite precision, you'd take buffers no padding , intersection give exact point you're looking for.
Comments
Post a Comment