I really like the functions of OSMnx, thank you! Nevertheless sometimes OSM-data is limited, especially for human powered modes like walking and cycling. I am working on a project for Zuerich, Switzerland and I am lucky that the city has a full walking network, including sidewalks, steps, paths, etc. At the moment this file is downloable as ESRI shapefile, gpkg or GEOjson. It just contains the lines but it would be easy to add nodes to them because edges are drawn until the next intersection point with another edge. For the 3D-layer it is accounted for, in such a way that lines on a different height aren't intersecting. I was wondering if it is possible to import a shape-file and work with it in OSMnx?
Did anyone did this before?
What would be a first step?
Does it make sense to try to convert the shapefile to "osm xml" in order to import it like this?
I have tried to first import it in networkx (https://gis.stackexchange.com/questions/227909/from-shapefile-to-python-networkx) but the syntax for nodes and edges is so different.
Thank you, I appreciate every hint.
The data can be found here: https://data.stadt-zuerich.ch/dataset/geo_fuss__und_velowegnetz/resource/80af45c0-835c-4e29-b99d-f8cd6dfefa11?inner_span=True (includes also bike-infrastructure which has to be removed)
Related
I would like to try to proceed some experiment, where I give two inputs for reinforcement learning agents. As first input, I would like to provide him grid-like environment that would represent room-maze with some walls and reward in one of the maze rooms. And the second one would be a graph representation of this maze.
I'm still stuck at planning the experiment, because I'm not sure about creating sufficient way to create a proper graph structure of 2D-grid environment. For example, I was thinking about looking for some algorithms that is able to find modularities (e.g. modules could correspond to rooms).
Do you have any idea what would be worth recommending when it comes to building a graph? And maybe what RL algorithm would work fine on both?
A maze grid is often represented in a text file as "ASCII ART"
The * mark the cells that are in the path from the start to the end.
It is fairly straightforward to write code to read this text file and create a graph with links between adjacent cells. If there is a wall the link has "infinite" cost, if there is a door then the link cost can be small or zero. From this graph a standard path finding code will find the path through the maze.
Here is the result as visualized by graphviz
"cnrm" is the node representing the call at row m, column n and the path is highlighted in red.
You can look at C++ code for doing this at https://github.com/JamesBremner/PathFinder
specifically the code to read the ascii art and generate the graph is in https://github.com/JamesBremner/PathFinder/blob/main/src/cMaze.cpp
I'm testing an algorithm that finds a shortest path between two certain vertexes in graph and gives a list of vertexes after each turn (actually it gives three paths - one of them is a shortest path in this graph and two others are some kind of extra paths that are also important for us and are used for further shortest path calculations). On each turn the weights of graph edges change somehow so every turn we get a new triple of lists (paths). I would like to visualize the evolving of these paths by drawing a graph (this graph is actually a grid that represents a city, e.g. New York) and each kind of path would be represented with certain colour (so on each turn there would be a grid with three coloured paths). One more time - on every turn the paths will be different so the picture will change. What is the best way to represent it? And one more question - sometimes there would be edges that belong to two or maybe even three of these pathes and I'd like to show it, so it would be nice if there is an opportunity to colour this edge with two/three colours at once. It would be perfect if it was possible to make it look like two/three thinner edges put along together, but I could only find a situation where we draw several lines of different colour that are being put together consecutively (like that: enter image description here). Is there a way to make it the first way?
I'm sorry for being discursive but I've never dealt with graphics in Python and I desperately need help. Thanks!
If you want to show the image in a GUI, it depends on the GUI toolkit that you want to use. In the Tkinter toolkit that comes with most Python distributions you could use the Canvas widget. There are several tutorials online [1], [2]. Most GUI toolkits have a similar functionality, but they can have different names.
If you want to save an image to a file, there are many graphics libraries you could use, depending on what kind of format you want to save it to.
For example the Python bindings to the Cairo library can save a picture as PDF or SVG vector formats.
The Pillow library on the other hand supports many bitmap formats.
There are many others; matplotlib, agg, gd are just some examples.
I am working on a navigation system and want to visually check results of my calculations. (Dijkstra, A*, etc.)
What are my options without getting into Google Maps API, Javascript, etc.?
For the most part every query gives me a list of coordinates:
[[53.4704344, 9.9145282], [53.4704483, 9.9152652], [53.4704704, 9.9164389], [53.4704818, 9.9169074]]
Right now I build GeoJSON linestring I paste into GeoJSONLint.com which starts getting annoying.
Without knowing the requirements, two things that immediately come to mind are:
matplotlib maps: http://matplotlib.org/basemap/users/examples.html
GeoJSON on http://gist.github.com: https://github.com/blog/1576-gist-meets-geojson
I would probably use gist first, as it's all git-able, zoomable, shows streets, etc.
Which is better probably depends on your data (especially the spatial scale).
I'm interested in using python to make diagrams representing the size of values based on the size of squares (and optionally their colour). Basically I'm looking for a way to make overviews of a bunch of values like the good old program windirstat does with hard-drive usage (it basically makes a big square representing your harddrive and then smaller squares making up the area inside of it representing different programs, the bigger the square the larger the file, colour indicates the type of file). I'm fairly familiar with matplotlib, and I don't think it's possible to do something like this with it. Is there any other python package that would help? Any suggestions for something more low level if it's not? I guess I could do it manually if I could find a way to draw the boxes programatically (I don't really care about the format, but the option to export SVG as well as PNG would be nice).
Ultimately, it would be nice to have it be interactive like windirstat is, where if you were to hover over a particular square you get more information on it, and if you clicked on it maybe you'd go in and see the makeup of that particular square. I'm only familiar with wxpython for GUI stuff, not sure if it could be used for something like this. For now I'd be happy with just outputting them though.
Thanks a lot!
Alex
Edit:
Thanks guys, both your answers helped a lot.
You're looking for Treemapping algorithms. Once implemented, you can transform the output (which should be rectangles) into plotting commands to anything that can draw layered rectangles.
Edit:
More links and information:
If you don't mind reading papers, the browser-based d3 library provides for 'squarified' treemaps (js implementation). They reference this paper by Bruls, Huizing, and van Wijk. (This is also citation 3 on the wikipedia article)
I'd search on the algorithms listed on the linked Wikipedia article. For instance, they also link to this article, which describes an algorithm for "mixed treemaps". The paper also includes some interesting portions at the end describing transformations into other-than-rectangular shapes.
Squarified certainly appears to be the most common variety around. The above links should give you enough to work towards a solution or, even, directly port the d3 implementation. However, the cost of grokking d3's model (which is something like a declarative form of jQuery) may be somewhat high. At first glance, though, the implementation appears relatively straightforward.
Squaremap does this. I haven't used it (I only know it from RunSnakeRun) and its documentation is severely lacking, but it seems to work.
I need to find out in what country given GPS coordinates are, on a device that has no Internet access (e.g. this, but without the easy on-line solution). Having no experience with GIS, I guess I'd need some kind of module that would statically store shapes of countries and match current location against them.
I'd therefore like to ask what kind of tools would be best for this, and what is the best way to obtain the country data. I'm using Python on an embedded Linux box.
There's a shape file here with all of the country borders. You can then use OGR or something like this to access the data.
You might have a look at the GeoDjango documentation even if you aren't making a web application. The tutorial covers importing the world boundaries shapefile.
Have you seen https://github.com/krisrak/ios-offline-reverse-geocode-country/?
all offline ... no need for any APIs super fast .
accuracy not guaranteed !!
You would need a map with the boundaries of each country. Then, given a coordinate, you would need to calculate in which boundary the point fell. Of course, the two challenges there are collecting the data and representing it, and doing the math to find where a point falls.
Does anyone know how Yahoo does it? Could you possibly port their approach locally?