locked
Can I use the Reduce() spatial method to simply a polygon, based on a map's zoom level? RRS feed

  • Question

  • Hi folks,

    you guys know how VE/GM have different zoom levels? I'm assuming each zoom level is actually representing a distance per 'grid' size. For example, when i goto GM, it defaults to 1000kms/500mi. Not sure what the exact zoom level number is. I think there's around 20 zoom levels? anyways, each zoom level must represent some defined size. as u go closer, the scale changes.

    so .. is it possible to relate the Reduce() method to a zoom level. For example. if we have a zoom level scale of 1000km/500mi, it make no sense showing a polygon with 10,000 points on it (actually, in reality, that's a crazy high number even when you've zoomed right in.. but that's not the point right now :)  ) ... but reducing it to show a few / few dozen. Then, when i'm zoomed closer, more poly's should get shown.

    So, is there a trick to using the Reduce() method tied into a zoom level?

    When i check Reduce() on MSDN , the Reduce() method says :


    tolerance

    Is a value of type float . tolerance is the tolerance to input to the Douglas-Peucker algorithm. tolerance must be a positive number.

     

    That doesn't make much sense to me, with regards to map zoom levels :)

    cheers!


    -Pure Krome-
    Thursday, May 21, 2009 6:40 AM

Answers

  • I would very strongly recommend that you do use Reduce() to different levels depending on the zoom level of your map... doing so is a very easy way of dramaticaly improving the performance of VE/Google Maps while ensuring that you retain the fidelity of shapes when you zoom closer.
    GM and VE both use exactly the same projection system (Mercator, based on a perfectly spherical ellipsoid model, using the WGS84 datum). One advantage of this projection is that they have exactly the same scale in the y and x dimensions.
    Furthermore, both VE and GM define exactly the same zoom levels, which is handy. At the lowest resolution (1), the whole world is displayed on 4 256px x 256px tiles (i.e. a 2x2 grid). As you zoom in to each successive level, the resolution of the map doubles in both dimensions.
    So the resolution at each zoom level is as follows:

    Meters/Pixel Zoom Level
    78271.52    1
    39135.76    2
    19567.88    3
    9783.94      4
    4891.97      5
    2445.98      6
    1222.99      7
    611.50        8
    305.75        9
    152.87       10
    76.44         11
    38.22         12
    19.11         13
    9.55           14
    4.78           15
    2.39           16
    1.19           17
    0.60           18
    0.30           19

    Back to SQL Server:- The tolerance of the Douglas-Peucker algorithm represents the greatest deviation that is allowed between any point in the simplified result returned from the Reduce() method compared to the original instance supplied. Clearly, there's no point trying to display shapes on your map that are at a greater resolution than the map itself - doing so would require processing of additional points that won't actually add any extra information. So, you can tolerate a greater deviation at lower zoom levels.

    There is no direct correlation between the value returned by map.GetZoomLevel() and the tolerance value that you supply to Reduce(), but using the table above as a guide you should be able to play around with different values that work for you.

    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
    • Marked as answer by Pure Krome Monday, May 25, 2009 12:25 AM
    Thursday, May 21, 2009 7:29 AM
    Answerer

All replies

  • I would very strongly recommend that you do use Reduce() to different levels depending on the zoom level of your map... doing so is a very easy way of dramaticaly improving the performance of VE/Google Maps while ensuring that you retain the fidelity of shapes when you zoom closer.
    GM and VE both use exactly the same projection system (Mercator, based on a perfectly spherical ellipsoid model, using the WGS84 datum). One advantage of this projection is that they have exactly the same scale in the y and x dimensions.
    Furthermore, both VE and GM define exactly the same zoom levels, which is handy. At the lowest resolution (1), the whole world is displayed on 4 256px x 256px tiles (i.e. a 2x2 grid). As you zoom in to each successive level, the resolution of the map doubles in both dimensions.
    So the resolution at each zoom level is as follows:

    Meters/Pixel Zoom Level
    78271.52    1
    39135.76    2
    19567.88    3
    9783.94      4
    4891.97      5
    2445.98      6
    1222.99      7
    611.50        8
    305.75        9
    152.87       10
    76.44         11
    38.22         12
    19.11         13
    9.55           14
    4.78           15
    2.39           16
    1.19           17
    0.60           18
    0.30           19

    Back to SQL Server:- The tolerance of the Douglas-Peucker algorithm represents the greatest deviation that is allowed between any point in the simplified result returned from the Reduce() method compared to the original instance supplied. Clearly, there's no point trying to display shapes on your map that are at a greater resolution than the map itself - doing so would require processing of additional points that won't actually add any extra information. So, you can tolerate a greater deviation at lower zoom levels.

    There is no direct correlation between the value returned by map.GetZoomLevel() and the tolerance value that you supply to Reduce(), but using the table above as a guide you should be able to play around with different values that work for you.

    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
    • Marked as answer by Pure Krome Monday, May 25, 2009 12:25 AM
    Thursday, May 21, 2009 7:29 AM
    Answerer
  • Hi Tanoshimi :)

    i'm not sure how the guide above will help me. :( Like, I understand 100% what you described about how VE/GE have zoom levels and what each tile scales to represent, etc.

    The key sentence I read in that is the following: So, you can tolerate a greater deviation at lower zoom levels .

    As such, are you suggesting that as i go lower, (eg. 1 is top, 19 is bottom), I provide a larger number to the Reduce() method. Besides that, it's all trial and error? There's no magic numbers i should use / start with / end with / stay within a range, etc... ???

    (also, if any of this is in your book, please plug the page(s) ... so i can reference it quickly).

    -Pure Krome-
    Thursday, May 21, 2009 7:56 AM
  • Try pps 332 - 334 for an explanation of Douglas-Peucker. Also, be sure to check the diagram on p333 that shows how a polygon representing Australia appears when Reduced() at four different tolerance levels.

    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
    Thursday, May 21, 2009 8:40 AM
    Answerer
  • If it helps, think of Reduce() as a kind of 'rounding', but for spatial data.

    So, ROUND(14.6543345,2) gives 14.65 - which is 14.6543345 rounded to 2 decimal places.

    Geometry.Reduce(250) is a bit like rounding the coordinates of Geometry to the nearest 250 metres (assuming that the coordinates are measured in metres). The greater the value provided to Reduce(), the more it is rounded, so the more simplified the shape.

    Does that help?

    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
    Thursday, May 21, 2009 8:46 AM
    Answerer
  • yep - sure does :) cheers again :)
    -Pure Krome-
    Monday, May 25, 2009 12:25 AM