<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Virtual Earth 3D team blog : Cache</title><link>http://blogs.msdn.com/virtualearth3d/archive/tags/Cache/default.aspx</link><description>Tags: Cache</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>WMS Data</title><link>http://blogs.msdn.com/virtualearth3d/archive/2009/06/09/wms-data.aspx</link><pubDate>Tue, 09 Jun 2009 20:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9716735</guid><dc:creator>NikolaiF</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/virtualearth3d/comments/9716735.aspx</comments><wfw:commentRss>http://blogs.msdn.com/virtualearth3d/commentrss.aspx?PostID=9716735</wfw:commentRss><description>&lt;P&gt;I was having a discussion with&amp;nbsp;Kurt Guenther from &lt;A title="Infusion Surface Blog" href="http://www.infusion.com/surfaceblog/" target=_blank mce_href="http://www.infusion.com/surfaceblog/"&gt;Infusion&lt;/A&gt; yesterday on the topic of WMS servers and VE3D.&amp;nbsp; There is a large amount of very interesting spatial data out there served by &lt;A title="WMS on Wikipedia" href="http://en.wikipedia.org/wiki/Web_Map_Service" target=_blank mce_href="http://en.wikipedia.org/wiki/Web_Map_Service"&gt;Web Map Services&lt;/A&gt;, or WMS servers.&amp;nbsp; VE3D is able to process this data using ConnectionParameter-based DataSources.&amp;nbsp; Setting it up is pretty easy:&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #2b91af; FONT-SIZE: 10pt"&gt;ConnectionParameters&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt; cp = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ConnectionParameters&lt;/SPAN&gt;(&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;A href="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Portland/Portland_ESRI_Neighborhoods_AGO/MapServer/export?bbox=%7b16%7d,%7b17%7d,%7b18%7d,%7b19%7d&amp;amp;bboxSR=4326&amp;amp;layers=&amp;amp;layersDefs=&amp;amp;size=256,256&amp;amp;imageSR=102113&amp;amp;format=png&amp;amp;transparent=true&amp;amp;dpi=&amp;amp;f=image"&gt;&lt;FONT color=#0000ff&gt;http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Portland/Portland_ESRI_Neighborhoods_AGO/MapServer/export?bbox={16},{17},{18},{19}&amp;amp;bboxSR=4326&amp;amp;layers=&amp;amp;layersDefs=&amp;amp;size=256,256&amp;amp;imageSR=102113&amp;amp;format=png&amp;amp;transparent=true&amp;amp;dpi=&amp;amp;f=image&lt;/FONT&gt;&lt;/A&gt;&lt;/SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; connectionParameters = cp.ToString();&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;DataSourceLayerData&lt;/SPAN&gt; layerData = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;DataSourceLayerData&lt;/SPAN&gt;(LayerName, Name, connectionParameters, &lt;SPAN style="COLOR: #2b91af"&gt;DataSourceUsage&lt;/SPAN&gt;.TextureMap);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Host.DataSources.Add(layerData);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Drop this in to your Activate (plug-in) or Initialized handler (winforms etc) app and fly to Portland, OR to see the data (thanks to ArcGIS for the sample data and Kurt for the pointer).&lt;/P&gt;
&lt;P mce_keep="true"&gt;I won't go into all the details of the WMS spec here, but I will call out a few important parts.&amp;nbsp; First, in order for this to work you must specify the bbox to be in Geographic coordinates (4326).&amp;nbsp; This is usually the default.&amp;nbsp; Second, you must pay attention to the returned projection.&amp;nbsp; In the above case, we have instructed the server to return 102113, which is Web Mercator, VE3D's native image projection.&amp;nbsp; This data can be consumed directly with very little overhead.&amp;nbsp; However, different servers support only certain formats and projections, and you must be careful for any particular server (it is possible to query this using WMS's GetCapabilities).&amp;nbsp; Nearly all support returning images in Geographic coordinates, 4326.&amp;nbsp; It is possible to instruct VE3D to reproject this to Web Mercator (this is the only reprojection VE3D will do for you, fortunately it will work for the majority of data).&lt;/P&gt;
&lt;P mce_keep="true"&gt;Now, to look at ConnectionParameters and what it can do for you.&amp;nbsp; First, there's the big url.&amp;nbsp; Notice that the bbox has string.Format replacement variables in it:&amp;nbsp; {16}, {17}, etc.&amp;nbsp; Requests to the server are made on a per-tile basis (the &lt;A title="Debug keys" href="http://blogs.msdn.com/virtualearth3d/archive/2008/10/29/debug-key-shortcuts.aspx" target=_blank mce_href="http://blogs.msdn.com/virtualearth3d/archive/2008/10/29/debug-key-shortcuts.aspx"&gt;T key&lt;/A&gt; is useful here).&amp;nbsp; For each request, these variables are replaced with data specific to the tile in question.&amp;nbsp; Here is a list of available parameters:&lt;/P&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;
&lt;P&gt;0 Reserved&lt;/P&gt;
&lt;P&gt;1 Map Style&lt;/P&gt;
&lt;P&gt;2 Round-robin integer&lt;/P&gt;
&lt;P&gt;3 Reserved&lt;/P&gt;
&lt;P&gt;4 Quadkey&lt;/P&gt;
&lt;P&gt;5 Extension&lt;/P&gt;
&lt;P&gt;6 Generation&lt;/P&gt;
&lt;P&gt;7 Stripe (0-3)&lt;/P&gt;
&lt;P&gt;8 Tile Host&lt;/P&gt;
&lt;P&gt;9 App Host&lt;/P&gt;
&lt;P&gt;10 Language code&lt;/P&gt;
&lt;P&gt;11 Region code&lt;/P&gt;
&lt;P&gt;12 Tile LOD&lt;/P&gt;
&lt;P&gt;13 Tile X&lt;/P&gt;
&lt;P&gt;14 Tile Y&lt;/P&gt;
&lt;P&gt;15 Low order stripe (0-1)&lt;/P&gt;
&lt;P&gt;16 MinLong&lt;/P&gt;
&lt;P&gt;17 MinLat&lt;/P&gt;
&lt;P&gt;18 MaxLong&lt;/P&gt;
&lt;P&gt;19 MaxLat&lt;/P&gt;
&lt;P&gt;20 RequestToken&lt;/P&gt;
&lt;P&gt;21 Culture name&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P mce_keep="true"&gt;The most interesting ones are 4 (the main quad-key, very useful for already-tiled data), 12, 13, 14, and and 16-19.&amp;nbsp; To see some of this in action, check out the &lt;A title="Terrain Images live sample" href="http://www.veteam.members.winisp.net/Spaceland/Samplesv4/TerrainImages/TestPage.htm" target=_blank mce_href="http://www.veteam.members.winisp.net/Spaceland/Samplesv4/TerrainImages/TestPage.htm"&gt;TerrainImages sample&lt;/A&gt;&amp;nbsp;(also available in the &lt;A title=Samples href="http://blogs.msdn.com/virtualearth3d/archive/2008/09/25/current-samples.aspx" target=_blank mce_href="http://blogs.msdn.com/virtualearth3d/archive/2008/09/25/current-samples.aspx"&gt;sample code&lt;/A&gt; of course).&amp;nbsp; Programatically, you can&amp;nbsp;investigate these values using the TileId class, using GetRequestCode, GetPosition, and GetLatLonBoundingBox.&lt;/P&gt;
&lt;P mce_keep="true"&gt;As for other values on ConnectionParameters, you can control reprojection (if your data is in Geographic, specify CoordinateReferenceSystem = WGS84CoordinateReferenceSystem.Instance, as noted before this is the only reprojection natively supported, so otherwise leave this field uninitialized), the bounds of where the data is valid is terms of Lat/Long and LOD (useful to reducing unnecessary network requests), and caching behavior.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Caching behavior deserves special discussion, because WMS servers are often quite slow.&amp;nbsp; By default, data loaded using ConnectionParameters is not cached locally.&amp;nbsp; Once it moves out of memory, it must be re-queried.&amp;nbsp; If you set CacheRetention however, the data will be kept locally for the period of time specified (unless it is evicted due to space restrictions in the interim).&amp;nbsp; If you set CacheRetention = new TimeSpan(24, 0, 0), for example, for 24 hours from the time of query a given tile will not be re-queried.&amp;nbsp; Note that some servers are dynamic, such as weather data, so it's important to use an appropriate value here.&lt;/P&gt;
&lt;P mce_keep="true"&gt;And just to give Kurt a poke in the ribs, please remember to only add DataSources after/during the Initialized event!&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;STRONG&gt;Update:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;John Fletcher from &lt;A href="http://www.latitudegeo.com/" target=_blank mce_href="http://www.latitudegeo.com/"&gt;Latitude Geographics&lt;/A&gt; pointed out that the example I give above isn't actually WMS compliant in its query parameters.&amp;nbsp; He suggests an alternate sample, of the British Columbia, CA&amp;nbsp;area:&lt;/P&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;
&lt;P&gt;ConnectionParameters&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; p = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;ConnectionParameters&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"http://openmaps.gov.bc.ca/mapserver/libcwms2?SERVICE=WMS&amp;amp;VERSION=1.1.1&amp;amp;REQUEST=GetMap&amp;amp;LAYERS=DBM_7H_MIL_BATHYMETRIC_POLY,BC_LABEL,DBM_7H_MIL_DRAINAGE_LINE,DBM_7H_MIL_DRAINAGE_POLY,DBM_7H_MIL_ROADS_LINE,DBM_7H_MIL_POLITICAL_POLY_PS,DBM_7H_MIL_POPULATION_POINT&amp;amp;STYLES=,,,,,,&amp;amp;SRS=EPSG:4326&amp;amp;BBOX={16},{17},{18},{19}&amp;amp;WIDTH=256&amp;amp;HEIGHT=256&amp;amp;FORMAT=image/png&amp;amp;TRANSPARENT=TRUE&amp;amp;EXCEPTIONS=application/vnd.ogc.se_inimage&amp;amp;"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;);&lt;/P&gt;
&lt;P&gt;p.CoordinateReferenceSystem = Microsoft.MapPoint.CoordinateSystems.&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Wgs84CoordinateReferenceSystem&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.Instance;&lt;/P&gt;
&lt;P&gt;Host.DataSources.Add(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;DataSourceLayerData&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"foo"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"bar"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;, p.ToString(), &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;DataSourceUsage&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.TextureMap));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;John&amp;nbsp;also provided a link to the WMS spec repository&amp;nbsp;(&lt;A href="http://www.opengeospatial.org/standards/wms"&gt;http://www.opengeospatial.org/standards/wms&lt;/A&gt;).&amp;nbsp; Note that the sample above is for WMS 1.1.1.&amp;nbsp; The most current version is 1.3.0, but many servers use the older, or support both.&amp;nbsp; No matter which you use (or even for something a little off spec like my original example) the interface with VE3D is the same.&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9716735" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/virtualearth3d/archive/tags/Code/default.aspx">Code</category><category domain="http://blogs.msdn.com/virtualearth3d/archive/tags/VE3D/default.aspx">VE3D</category><category domain="http://blogs.msdn.com/virtualearth3d/archive/tags/DataSource/default.aspx">DataSource</category><category domain="http://blogs.msdn.com/virtualearth3d/archive/tags/Cache/default.aspx">Cache</category><category domain="http://blogs.msdn.com/virtualearth3d/archive/tags/WMS/default.aspx">WMS</category></item><item><title>Modifying cache location</title><link>http://blogs.msdn.com/virtualearth3d/archive/2009/06/09/modifying-cache-location.aspx</link><pubDate>Tue, 09 Jun 2009 20:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9716616</guid><dc:creator>NikolaiF</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/virtualearth3d/comments/9716616.aspx</comments><wfw:commentRss>http://blogs.msdn.com/virtualearth3d/commentrss.aspx?PostID=9716616</wfw:commentRss><description>&lt;P&gt;My, it has been a long time since I posted.&amp;nbsp; I promise I will try to be better.&lt;/P&gt;
&lt;P&gt;Recently I was asked if it is possible to change the location of the cache file.&amp;nbsp; It is, with certain minor restrictions.&amp;nbsp; &lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000 size=2 face=Arial&gt;You can change the location by adding this to user.config:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000 size=2 face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;setting name="PersistentCacheDirectory" serializeAs="String"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;value&amp;gt;path here&amp;lt;/value&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/setting&amp;gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000 size=2 face=Arial&gt;Or, when creating the GlobeControl directly, pass in a GlobeControlInitializationOptions object with PersistentCachePath set.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000 size=2 face=Arial&gt;In either case, you can either specify a full path to anywhere, or a relative path from the current location (\AppData\LocalLow\Microsoft\Virtual Earth 3D\).&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000 size=2 face=Arial&gt;Putting the file outside LocalLow will cause problems when running in IE7/8 protected mode (Vista/Win7 with UAC on).&amp;nbsp; For a WinForms or WPF-based solution, it’s fine.&amp;nbsp; In such a case, the GlobeControlInitializationOptions setting is generally preferred as it will prevent problems when running Bing Maps on the same machine.&amp;nbsp; On the other hand, this will also cause two caches to be written, one in the default location and containing data from runs in Bing Maps, and one in the specified location.&amp;nbsp; The best approach depends on your exact usage.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9716616" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/virtualearth3d/archive/tags/VE3D/default.aspx">VE3D</category><category domain="http://blogs.msdn.com/virtualearth3d/archive/tags/Cache/default.aspx">Cache</category></item></channel></rss>