Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about rastering the osm #17

Open
SiYLin opened this issue Aug 7, 2023 · 3 comments
Open

Question about rastering the osm #17

SiYLin opened this issue Aug 7, 2023 · 3 comments

Comments

@SiYLin
Copy link

SiYLin commented Aug 7, 2023

Thx for producing such great work!
I have met some questions about render raster mask function for osm data. During the render_raster_mask function, I find out multipoints(more than 10) in xy space are ploted as two or zero points after the cv2.polylines function.

@sarlinpe
Copy link
Collaborator

sarlinpe commented Aug 7, 2023

Thank you for reporting an issue, can you please provide a minimal code example that reproduces this?

@SiYLin
Copy link
Author

SiYLin commented Aug 7, 2023

Thanks for your helping! I have found out the real problem is that when we query elements from the bounding box. It gerneates lines/points outisde of the boundingbox. Here is the minimal code to reproduce the error. (All hard code numbers and parameters are from avigon.osm and related json)

from ..utils.geo import BoundaryBox, Projection
from .data import MapData
from .download import get_osm
from .parser import Groups
from .raster import Canvas, render_raster_map, render_raster_masks
from .reader import OSMData, OSMNode, OSMWay

osm = OSMData.from_file('./avigon.osm')
osm.add_xy_to_nodes(projection)
map_data = MapData.from_osm(osm)
map_index = MapIndex(map_data)
bbox_tile = ([-1507.6801249806967,-1083.4590254879367],[-1379.6801249806967,-955.4590254879367])
canvas = Canvas(bbox_tile, ppm)
nodes, lines, areas = map_index.query(bbox_tile)
print(lines)

It will get something like [-1395.64272195, -1090.34845149],
[-1483.56526137, -1128.99600827],
[-1576.82026528, -1169.08557396],
[-1610.25588428, -1184.96641715],
[-1656.72452035, -1209.31050901],
[-1683.04645824, -1223.09275943],
[-1718.85196607, -1242.26133847],
[-1741.42436825, -1254.84432836],
[-1764.96035421, -1267.54920678],
[-1801.02338149, -1287.15060517],
[-1824.35964077, -1302.64421344],
[-1837.21680909, -1312.9739888 ],
[-1850.76548401, -1326.80354365],
[-1865.88090246, -1344.32151594],
[-1877.82520615, -1362.75146288],
[-1888.57344251, -1381.84839481],
[-1897.28212891, -1400.12367128],
[-1904.56191997, -1419.19934585],
[-1911.04745617, -1440.29746137],
[-1913.45076729, -1449.35231573],
[-1919.67292496, -1475.71715968],
[-1923.53499303, -1503.58268054],
[-1924.87191517, -1517.63783432]])

@sarlinpe
Copy link
Collaborator

sarlinpe commented Aug 23, 2023

This is working as intended. The map index uses an R-tree to efficiently retrieve elements based on their bounding box:

self.index_nodes = rtree.index.Index()

It returns any lines and polygons whose bounding box intersect with the query. OpenCV drawing functions support elements that are partially outside the canvas:
def draw_multipolygon(self, xys: List[np.ndarray]):
uvs = [self.to_uv(xy).round().astype(np.int32) for xy in xys]
cv2.fillPoly(self.raster, uvs, 255)
def draw_line(self, xy: np.ndarray, width: float = 1):
uv = self.to_uv(xy)
cv2.polylines(
self.raster, uv[None].round().astype(np.int32), False, 255, thickness=width
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants