MapWindow 4 - Plugins : MapWindow Discussion Forum
I have been looking into making a plugin to download and display data from OpenStreetMap [openstreetmap.org] but I have not gotten very far with it yet. Their data is not stored in a form that we can use directly in MapWindow, but a plugin cou
OpenStreetMap Ideas
Posted by: Mark Gray ()
Date: June 10, 2008 10:22AM

I have been looking into making a plugin to download and display data from OpenStreetMap [openstreetmap.org] but I have not gotten very far with it yet. Their data is not stored in a form that we can use directly in MapWindow, but a plugin could make it work. They have both nicely rendered bitmap tiles and vectors available.

Bitmap tiles:
It would be time consuming and might make them less beautiful if we re-project them, but they might work very nicely in a project that uses the same projection. Using a world-wide tiled data set brings up interesting issues for how layers might work differently in MapWindow in the future. Several other layers are available in a similar form.

Vectors:
OSM vectors are not very much like shape files. Each feature has its own list of attributes rather than all features having the same set of attributes. There are also complexities like bridges and tunnels. Rather than trying to use MapWindow shape rendering code, I am thinking we could include their renderer code and render directly from their vectors into the current MapWindow projection.

I am not sure how best to do a custom-rendered layer in MW.

The View.Draw interface: Is it detailed enough to do this? I am guessing that redrawing the layer this way on each view change will not happen quickly enough.

Create a raster layer: Rendering into a GeoTiff or png or other MW raster layer would work. This would not easily provide the worldwide "slippy map" feature, and zooming would either look bad or be slow while waiting for re-rendering, but a one-time download of the project area would be enough for many projects.

Finally, I would want to make it possible for people to use MapWindow to update the street maps and contribute the updates back to the OpenStreetMap project. This will certainly involve dealing with their vectors even if we use their tiles for display.

It is possible that a nice implementation of either a dynamically loaded tile layer or a non-shapefile vector layer will require a move to MapWindow 5/6, but it seems like something useful could be done in 4.5.

I can't work full time on this project right now, but wanted to at least get these ideas into the forum under a new topic. Feel free to follow up if you have any ideas or interest:

Do you want to help create this plugin?
Do you want to use it?
What would you use it for, just as background? for navigation? for updating OSM?
Is a worldwide "slippy map" vital/fun/unimportant to you?

See also Paul Meems enhancement request [bugs.mapwindow.org]

Options: ReplyQuote
Re: OpenStreetMap Ideas
Posted by: milovanderlinden ()
Date: June 12, 2008 09:18AM

I must have some vb.net snippets here and there that might be of use for this. Please contact me so I can mail them.

++ On using OpenStreetMap tiles in an asp.net environment ++
There is a javascript library as an extension to openlayers that loads tiles from the openstreetmap server. I would suggest to use this and not try to implement OpenStreetMap tiles on the server side.


++ On using OpenStreetMap tiles ++

First of all, OpenLayers uses the spherical mercator projection(EPSG:900913). always.
So you would have a way to warp the images if you use another projection.

Next: This is the javascript function that is used to construct the URL to get a tile:

getURL: function (bounds) {
var res = this.map.getResolution();
var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
var z = this.map.getZoom();
var limit = Math.pow(2, z);

if (y < 0 || y >= limit)
{
return OpenLayers.Util.OSM.MISSING_TILE_URL;
}
else
{
x = ((x % limit) + limit) % limit;

var url = this.url;
var path = z + "/" + x + "/" + y + ".png";

if (url instanceof Array)
{
url = this.selectUrl(path, url);
}

return url + path;
}
}

I will see if I can find some time to help out to enhance this.

Options: ReplyQuote
Re: OpenStreetMap Ideas
Posted by: Mark Gray ()
Date: June 12, 2008 11:06AM

(I updated this post June 13, 2008)
On OSM, my URL is [www.openstreetmap.org]
My separate project that uses OSM data is at: [code.google.com]
The first snippets of VB I have are below. I have not gotten the Xapi URL to return anything yet, but pBaseDataURL below works for getting a limited amount of vector data at a time and the Mapnik, Osmarender, and Maplint ones work when I try them in a browser. I haven't actually tried using the TileXY code below yet.

Public OSMDataTypeName As String() = {"Xapi", "Mapnik", "Osmarender", "Maplint"}

' api 0.5 returns XML vector data
Private pBaseDataURL As String = "[www.openstreetmap.org]; 'map?bbox=-0.703125,51.604302,-0.681152,51.617947
'Xapi should also return XML vectors, see [wiki.openstreetmap.org]
Private pBaseXapiURL As String = "[www.informationfreeway.org]; 'way|node|relation|*[bbox=botleftlon,botleftlat,toprightlon,toprightlat]
Private pBaseMapnikURL As String = "[tile.openstreetmap.org]; 'zoom/x/y.png e.g. 8/127/85.png
Private pBaseOsmarenderURL As String = "[tah.openstreetmap.org];
Private pBaseMaplintURL As String = "[tah.openstreetmap.org]; '14/8159/5441.png

'Tile Zoom Levels
'0 1 tile covers whole world
'1 2 × 2 tiles
'2 4 × 4 tiles
'n 2n × 2n tiles
'17 Maximum zoom for Osmarender layer
'18 Maximum zoom for Mapnik layer
' Project the world as Mercator.
' Divide the equator into n equal units -- those are the x values
' Locate ±85.0511° on your projection -- those are the limits of the map in the Y axis
' Divide the map's Y axis into n equal units -- those are the y values starting from 0 at the top
'x = (lon+180)/360
'y = log(tan(lat) + sec(lat))
'Tiles are 256 × 256 pixel PNG files
'file name = zoom/x/y.png
Private Sub TileXY(ByVal aLat As Double, ByVal aLon As Double, ByVal aZoom As Long, ByRef X As Integer, ByRef Y As Integer)
X = Math.Floor((aLon + 180) / 360 * 2 ^ aZoom)
Y = Math.Floor((1 - Math.Log(Math.Tan(aLat * Math.PI / 180) + 1 / Math.Cos(aLat * Math.PI / 180)) / Math.PI) / 2 * 2 ^ aZoom)
End Sub



Edited 2 time(s). Last edit at 12/16/2009 08:37AM by Mark Gray.

Options: ReplyQuote
OSM_VBnet
Posted by: Mark Gray ()
Date: July 11, 2008 03:43PM

I have just added a project to the repository at [svn.mapwindow.org] which is a small stand-alone application that downloads and displays OpenStreetMap tiles. This was an easy way to get started experimenting with OSM. I plan to turn it into a MapWindow plugin at some point, but it may be useful on its own also.

The initial version still has bugs and missing features, but hopefully it is interesting enough to take a look at already. It caches all the tiles it displays so future panning or zooming is much faster than the first look at a new area. I find it surprising how much more fun it is to look at maps that load quickly out of cache.

The UI does not yet offer an option for where to cache the tiles. It defaults to caching in IO.Path.GetTempPath. If you want to cache somewhere else I recommend placing a stop just after the first line of GetSettings in frmMap and changing pTileCacheFolder to the folder you want to save tiles in. After exiting normally the first time, it should read your defaults from the registry, including your cache folder and the last location and zoom you were looking at.

Saving the current view to a stitched-together georeferenced .png is almost working but the world file (.pgw) does not get the correct north coordinate. This means that if you load the .png into MapWindow the image is displaced an annoying distance north or south of where it should be relative to correctly projected layers. If you can figure out how to fix this, please feel free. It is possible that I do not write quite the right .prj file or that some math somewhere is off.

Getting the projection and world file right are important for getting this data into MapWindow. Other features that would be nice include changing which tile server to use and navigating to places by place name, address, bookmark, or lat/long. Overlaying other data on the map is also desirable, but that is probably best done after the data is in MapWindow where we already know how to handle multiple layers well.

Looking at the stitched-together tiles in MapWindow is fine when you are near the native projection and resolution. When you get far from the native zoom, we probably want to get a different zoom layer from OSM.

Please let me know if you are working on this code.

Options: ReplyQuote
Rendering from OSM vectors
Posted by: Mark Gray ()
Date: July 11, 2008 03:45PM

While OSM_VBnet deals only with downloaded tiles so far, another option is to render these maps on the fly. I have not yet started looking at it, but there is an interesting sounding program called Kosmos that renders from OSM vectors using .net:
[wiki.openstreetmap.org]

It has just had a new version released, source may be out this weekend:
[igorbrejc.net]

I imagine that rendering any significant area will be much slower than showing cached bitmaps, but I figure this approach is worth a look.

Options: ReplyQuote
Re: OSM_VBnet
Posted by: pmeems ()
Date: July 13, 2008 01:49PM

Mark,

I've just downloaded your VB.NET project and it works great.
Although I had to change the frmMap_Paint to
Private Sub frmMap_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
  If Not pBitmap Is Nothing Then
    e.Graphics.DrawImage(pBitmap, 0, 0)
  End If
End Sub

Further I've added
Case Keys.OemMinus
  If pZoom > g_ZoomMin Then
    pZoom -= 1
    Redraw()
  End If
Case Keys.Oemplus
  If pZoom < g_ZoomMax Then
    pZoom += 1
    Redraw()
  End If
to frmMap_KeyDown() because I don't have a wheel mouse.

I also added a new directory called images with some more OSM images you can use for icons.

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn



Edited 1 time(s). Last edit at 07/13/2008 02:29PM by pmeems.

Options: ReplyQuote
Re: Rendering from OSM vectors
Posted by: geofran80 ()
Date: July 13, 2008 02:59PM

Is very great the application for OSM, and the addings from pmeens.

It's works fine. i think that would be related with WMS Servers and WFS servers using XML.

Is very powerfull.

Cheers.

Francisco J.

Options: ReplyQuote
OSM_VBnet update
Posted by: Mark Gray ()
Date: July 14, 2008 08:32AM

I just checked in the Paint change suggested by pmeems and started using the icon he submitted on the main form.

I just noticed that I didn't include pmeems other suggested change. Everyone should feel free to commit changes to this program yourselves if you have a MapWindow SVN account. SVN is good at merging changes if they don't conflict and I can always roll back to an earlier version if a change causes trouble. Just be sure to update to the latest code often in case someone else changes it too.

New features I am thinking about include:

Allow the user to select which tile server to use

Download tiles in a separate thread so the user can keep zooming and panning even if not all tiles are downloaded yet

Display a scaled version of tile(s) we already have from the same area at a different zoom while we download a tile at the requested zoom, rather than just showing a white square

Options: ReplyQuote
Re: OSM_VBnet
Posted by: pmeems ()
Date: July 16, 2008 01:36PM

Mark,

Although I'll be watching this project very closely I won't be able to contribute through code. Because it's written in VB.NET and I'm still in the process of learning C# (I'm trying to get certified). It's too confusing.
I might port your code to C# when it's fully working ;)

Going to multi threading would be a good step forward. You might also consider downloading some more tiles when the visible tiles are done. Like a ring around the current view. When an user moves/pans it looks/response faster.

I'll try to test it as much possible and contribute that way.

Keep up the good work!

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Options: ReplyQuote
OSM_VBnet: GPX, threaded download, Zoom and Tile Server menus
Posted by: Mark Gray ()
Date: July 24, 2008 10:18AM

OSM_VBnet now has the ability to overlay GPX files containing waypoints and/or tracks. Simply drag one or more *.gpx files onto the map or open them from the File menu. There are associated menu items under View to choose whether the map automatically pans and/or zooms to the extent of the loaded file.

Downloading tiles is now done in a background thread so the user is able to navigate around the map and change the zoom while tiles are downloading.

A Zoom menu has been added to select the OSM zoom without using a scroll wheel or the OEM + and - keys.

There is also a new menu for the user to choose which tile server to use. This currently allows selection of the default Mapnik renderer, Osmarender, or the debugging layer Maplint.

On the TODO list:

Allow loading the transparent Maplint tiles on top of other tiles.

Port to Windows Mobile to use it on my phone.

Experiment with rendering from vectors.

Speculative caching: Speed up panning (and/or zooming) by adding a separate background queue of tiles that are nearby to download. When all visible tiles have been retrieved, start getting other ones. Interrupt speculative caching whenever a new visible tile is needed.

Cache management: The user can right-click a tile and ask to refresh it manually, but there is no code to automatically decide a cached tile is old enough to go get a fresh copy. It would be nice to figure out how to inquire whether a tile has changed since the copy we have. I am not sure OSM supports that kind of query yet. Perhaps we could use HTTP to inquire the date (or size?) of a tile file. It looks like tiles are re-rendered without regard to whether they have changes, so it may be difficult to avoid getting unchanged newly rendered tiles.

It is still the plan for this code to be incorporated into a new MapWindow plugin, but I have been enjoying using the stand-alone version for now and I have not yet started that effort. Feel free to start building a MW plugin or add any features if you are eager to.

Options: ReplyQuote
Re: OSM_VBnet: GPX, threaded download, Zoom and Tile Server menus
Posted by: pmeems ()
Date: July 24, 2008 01:58PM

Mark,

This project is getting more impressive every time.
Thanks to the treading it's much more user-friendly.
I couldn't get the other two tile servers to work.
I'm looking forward to seeing your 'Speculative caching'

I haven't tested the GPX option because I don't have any. The zoom i nicely working.

On the issue of when to get new tiles, perhaps for now a workable option would be using a user setting (set it to a week) and using the file date of the cached tile. Of course the cached tile should be shown first and the new tile can be downloaded and then replace the cached tile.

As always keep up the good work!

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Options: ReplyQuote
OSM_VBnet: GPX, Tile Server, C#
Posted by: Mark Gray ()
Date: July 24, 2008 03:00PM

The two newly added tile servers seem to be less reliable than the main one. I believe they both come from the same machine and it is sometimes either not responding or slow.

GPX files are used to contain points or tracks for a GPS unit. I download them from my GPS after each trip I take so I can see where I have been and see how well the OSM map lines up. It is usually perfect, but I occasionally find a new street or one that needs fixing in OSM.

On the C# vs. VB.net issue, I understand wanting to concentrate on the one you are about to get certified in, so you are off the hook for developing this application for now. I do want to say to anyone listening that they are really quite similar and if you know one it is not that hard to use the other. SharpDevelop (an open source development environment [www.icsharpcode.net] ) even has an automatic converter to switch your code's syntax from one to the other. My office usually uses VB, and there are a couple of things I prefer about it, but I develop in both. The two differences I can think of that I like are that VB is not case sensitive (and fixes case when you type it wrong) and the Visual Studio error checker in C# seems to only find errors or figure out you have fixed them when you compile, but in VB it updates every time you finish editing a line.

I may end up switching to C# when I port this to Windows Mobile because that is the language that my track-making software is in that makes my GPX files. I am not sure yet whether to add maps to my track-making software or create a separate application for the maps.

Options: ReplyQuote
Re: OpenStreetMap Ideas
Posted by: danames ()
Date: July 28, 2008 05:48PM

Mark, I finally had a chance to look at your OSM project. Very nicely done... So... the next question is, how do we get this data into MapWindow? What are your thoughts? - Dan

Options: ReplyQuote
Re: OpenStreetMap Ideas
Posted by: pmeems ()
Date: August 08, 2008 02:08PM

Mark,

I've just got the latest sources of your project but I can't compile:
Becaue 'pPanToGPX' is not declared in line 30 of \OSM_VBnet\frmMap.vb
It seems so forgot to add a new file or something.

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Options: ReplyQuote


Sorry, only registered users may post in this forum.





Banner Exchange




GISCP.com




Send us your banner logo (160x120) for the space above, and add this MapWindow banner ad to your site:

Just paste this text in your page: