Hi everyone,

currently i'm working on my own .net implementation of a tiles server. I've made some progress but currently im facing a problem with gaps in the rendered lines (example motorways) Look at the image, there are gaps in the blue motorway. I'm rendering data based on the nodes and ways relations imported to my custom database. Any ideas what am I missing? I've already tried to include all types of 'roads' to my query.

Thank you for any suggestions :)

alt text

Here is the db structure, and a query answering scai's question So yes, all nodes seems to be imported correctly. and yes i am debuging the problem already for 2 days :) :alt text

How data is rendered on the tile: i'm using this http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#C.23 to get lat and lng for each tile number (left top corner). Getting the +1 tile geoposition gives me right bottom corner. Let's call those two beginingGeoPosition and endGeoPosition. that gives me a set of nodes and their lat and lng.

Knowing my tiles are 256x256 i can get a pixel possition for each node on the tile:

var x = 256 * (node.Longitude - beginingGeoPosition.Longitude ) / (endGeoPosition.Longitude - beginingGeoPosition.Longitude )
var y = 256 * (node.Latitude - beginingGeoPosition.Latitude )/(endGeoPosition.Latitude -beginingGeoPosition.Latitude );

(currently it will work only for lat and lng > 0, but thats not the point)

so that gives us groups of points (for each way) on image tile positioned by their x and y. connectiong those points gives us a part of a motorway. Precisly in .net

gfx.DrawLines(new Pen(Color.Blue, 3), linePoints); it creates line through all the points in the linePoints array - each point has its x and y

and the full query looks like this.

select n.nodeid, n.latitude, n.longitude, wn.wayid, wt.tagname, wt.tagvalue, wn.orderid
                        from nodes n
                        join waynodes wn on n.nodeid = wn.nodeid
                        join waytags wt on wn.wayid = wt.wayid
                        where wt.tagname IN ('route', 'area:highway', 'highway') and wt.tagvalue IN ('motorway','trunk','primary','secondary','tertiary','unclassified', 'road', 'motorway_link','trunk_link','primary_link','secondary_link','tertiary_link','unclassified_link','road_link')
                        and n.latitude BETWEEN 52.30848 and 52.32191
                        and n.longitude BETWEEN 15.49072 and 15.5127
                        order by wn.orderid asc

asked 24 Aug '17, 09:36

michal_poz's gravatar image

accept rate: 0%

edited 24 Aug '17, 16:32


Please tell us at least the location or ideally the way IDs that won't get rendered.

(24 Aug '17, 09:38) scai ♦

For example i'm issuing the problem for 52.319371, 15.494535 I think the problem is about connecting the ways. I'm drawing roads for nodes (lat and lng) grouped by wayid, so one line on my img is build of connected points (nodes lat lng) in one group.

(24 Aug '17, 11:11) michal_poz

This seems to be around http://www.openstreetmap.org/way/223282681 and there doesn't seem to be an obvious correspondance between ways in OSM and what is missing.

You'll need to describe in more detail what you have actually done to stand a chance of anyone being able to reply with useful information.

(24 Aug '17, 11:20) SomeoneElse ♦

Maybe it helps to (re-)read about the basic OSM data model, i.e. https://wiki.openstreetmap.org/wiki/OSM_XML and https://wiki.openstreetmap.org/wiki/Elements.

(24 Aug '17, 11:34) scai ♦

For example, it's exactly this line http://www.openstreetmap.org/way/497464371#map=14/52.3202/15.4986 that is not rendered correctly.

And to be more precise about what i alerady did: I've created db with tables that describes relations betwen nodes, ways, way tags (waytags values). Each node has its lat and lng.

I've also created a api that provides an endpoint for z/x/y parameters. So based on z x and y (zoom and tile number) i can get the lat and lng coordinates.

After that i can query my db getting all nodes betwen begining lat/lng and end lat/lng. It's a join query on ways and waytags so i get nodes for specific waytag value. In our discusion its highway = motorway It gives me all nodes between left top corner and bottom right corner of specific tile.

Then i know that my tile is 256x256 px, so based on node lat and lng i can specifie its position on the tile - that gives me an array of points (nodes) so i can create a polyline which is drawn on my img.

Hope it's clear enought what i just wrote. I could also post a quere here if that would help. Thanks again

(24 Aug '17, 12:28) michal_poz

I've created db with tables that describes relations betwen nodes, ways, way tags (waytags values).

That's not really enough detail - you know the schema, so you'll need to debug it. Also you've not said how the data once retrieved from the database is turned into a tile.

(24 Aug '17, 12:32) SomeoneElse ♦

Then start debugging your software. Does way 497464371 and all corresponding nodes exist in your database? Does it get selected for rendering? What does the renderer finally do with it?

(24 Aug '17, 12:34) scai ♦

I've added some more precised description to the topic on how i am drawing roads. Besides that...shouldn't i use relations that are grouping ways? i mean the relations in the osm xml file

(24 Aug '17, 16:34) michal_poz

@michal_poz, have you had the time to test the hypothesis in my answer below? I posted it within minutes of your edit, so maybe you've missed it. Let us know if you're still seeing this problem!

(26 Aug '17, 12:33) Tordanik
showing 5 of 9 show 4 more comments

The gaps in the highway seem to be suspiciously correlated with boundaries between tiles. This might be useful for debugging your problem.

In particular, you write:

After that i can query my db getting all nodes betwen begining lat/lng and end lat/lng.

To render the section of a way that is within a given tile, you need at the very least one additional node beyond the border of the tile. Otherwise, the parts of the way that cross over into the adjacent tile will be missing.

So if you indeed only query for nodes within the tile boundaries, this might explain the broken highways.

permanent link

answered 24 Aug '17, 16:34

Tordanik's gravatar image

accept rate: 33%


I've tested it and that is what is cousing the problem When a single node is not returned in the query for a specific way and lat/ lng range im getting a gap on the edge of a tile. I've tested it by creating a query that returned data for 9 tiles (one tile that i am interested in and 8 other around that first one). That gave me a image with size 768x768 px (3 x256 = 768) and all roads were drawn correctly. So now i have to figure out how to add a additional point on the edge of a tile, that would make roads align with eachother.

(27 Aug '17, 12:58) michal_poz

I've just got it working correctly. By querying db for data for all 9 tiles and drawing just the middle tile using all nodes. Its possible becouse .net graphic DrawLine method allows to pass also points with x/y possition less than 0. The line is just drawn and ends at the edge of an image. Rendering lasts a big longer but i've added a caching mechanism

Than you all for your comments and help

He is the result.alt text

(27 Aug '17, 15:36) michal_poz
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 24 Aug '17, 09:36

question was seen: 1,250 times

last updated: 29 Aug '17, 08:01

powered by OSQA