سؤال

I have an application (WinForms C#) that allows users to draw a line (free draw) to highlight roads of interest on a bitmap taken from Google Maps.

I am using the Mouse Down/Move/Up events to add points to a GraphicsPath object. This works well for straight stretches o road that can be represented by just two points. But when the mouse draws turns with the button down for long periods, a lot of point data is generated.

This is not only inefficient but also a clunky way to draw over curves (specially when the zoom level is too low).

Question:

  • Once the path is complete, how can I programatically reduce the number of points without losing accuracy.
  • Is there a better way to capture point information using some form of geometric construct?
هل كانت مفيدة؟

المحلول

A commonly used way to reduce the number of points in a polygonal curve is the Ramer–Douglas–Peucker algorithm. It is perfectly suited for reducing the number of points in a map drawing, e.g. a route.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top