Visualize results/coordinates of shortest path algorithms - python

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).

Related

Programmatically altering stl CAD files with Python

I have many stl CAD files for 3D printing and I was wondering how I can manipulate an individual CAD file by making a simple change programatically. Like if I want to double the dimensions of everything in the CAD file, how could I accomplish this in python? I could convert it to gcode if that makes things simpler.
I have come across FreeCad but I am not sure if this is the easiest and best way of programmatically altering CAD files. I also wanted an option that allows for freedom of manipulation beyond just size, maybe also seeing how I can programmatically alter the shape of the CAD file.
Well to be precise, STL files are even not meshes, but triangles soups. Which means that triangles are even not connected to each other (well they need to be adjacent to be used by software generatif g-code, but no obligation else)
just for clarification: g-code format is just a sequence of instructions for the machines (3d-printers, etc) so it's very good for printers, but also certainly the worst format to manipulate geometry.
one solution
you can use the python pymadcad module to deal with STL files
So for simple transformation operations (such as scale, translation etc)
from madcad import *
part = read('path/to/your_file.stl')
transformed = part.transform(mat3(2)) # scale by a factor 2 (diagonal matrix of 2)
write(transformed, 'path/to/output_file.stl')
If you need more complex operations (such as booleans, chamfers, etc) you will need to make the triangle connected again before the desired operations.
from madcad import *
part = read('path/to/your_file.stl')
part.mergeclose() # merge points at the same location
# your desired operations (example)
transformed = union(part, icosphere(vec3(1,1,1), 3.)) # add a sphere a diameter 3
write(transformed, 'path/to/output_file.stl')
note
pymadcad is internally using numpy-stl to import stl files, if you need only basic manipulations you can also only install that one
STL files are meshes. Their exterior is defined by triangulated surfaces. Meshes are notoriously difficult to modify after the fact. That's why you always want to save your designs in the native format and also in an open solid format like .STP or .IGES.
That said, simple scaling of a mesh is pretty easy and can be done trivially in FreeCAD.
You can do it in the gui in the mesh design workbench or through python. Here's a post about that:
https://forum.freecadweb.org/viewtopic.php?t=9109#p74047
FreeCAD also has some tools to convert a mesh into a solid. Results are usually less than spectacular but might be good enough depending on your needs. Search on the FreeCAD forum for posts about converting or look here: https://wiki.freecadweb.org/FreeCAD_and_Mesh_Import
Gcode doesn't say anything about the model itself. It specifies where a tool should move so it's just a series of directives that move a tool from place to place at a given speed. Going from Gcode to a model that you can edit is pretty difficult or impossible.

Select vertex from a mesh to parse as an argument to a script

I have made a Python script which takes a mesh and the index of a vertex to apply an operation. Unfortunately, Trimesh -the library I use to process the mesh- does not have an option to select an vertex by clicking on it.
Is it possible to visually select an vertex on the mesh, get the identifier on on that vertex and pass it to another script? Is it worth using a 3rd party program like Meshlab or Blender to select that input or am I missing a more obvious route?
Trimesh does not have a GUI, just some rendering tools. However, it has tons of features to programatically find vertices of interest if you are able to come up with rules or characteristics of it. The docs, source code examples, and issues all have useful implementations to browse through.
This borders on not answering "the question" but you do mention using third party tools as questions within your explanation, so...
I didn't get to implementing this in trimesh / Python. I used Meshlab to select the vertices I wanted, and manually copied the indices over to Python variables. Trimesh will re-order vertices as part of its optimization process. So if you go this route, be sure to use process=False to maintain vertex order. E.g.:
trimesh.load('./my.obj', process=False)

Networkx Programatic Network Graph Visualization

Hopefully this question isn't too opinion based. If it is, can you point me in the right direction for this question.
I am hoping to create something simple to visualize a twitter network that has been defined with networkx. What are the best available visualization tools for this? I would like to have something along the lines of, I run a script and get display a png or some image of the network that isn't too cluttered. I would definitely like to differentiate between usernames and hashtags and possibly color by community or something along those lines.
I haven't started anything yet other than playing with the built in networkx drawing which is limited and networkx doesn't even recommend. The tools I've found in my search include plot.ly, gephi, d3.js, and cytoscape. Plot.ly is proprietary so I'd like to stay away from it. D3.js seems pretty cool. I plan on using it eventually for some interactive graphs, but I hear there are performance issues and limitations to hundreds of nodes vs thousands of nodes. Also I'm not familiar with javascript at all. Gephi and cytoscape aren't really programmatic. They are nice, but require a human element.
Does anything already exist that meets my needs? Is the human element required to get decent looking output? I can get okay results with the built in networkx drawing, but it requires significant tweaking for each case (remove overlapping, setting up a half decent layout, etc...). Also the fact that networkx mentions they may drop support for drawing in the future doesn't help.
No need to use Javascrip. Bokeh is a Python library for D3.
You can also consider NodeBox if on OSX or NetworkX Viewer, but probably what you are looking for is Graph-Tool.

Lookup country for GPS coordinates without Internet access

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?

How to use R-Tree for plotting large number of map markers on google maps

After searching SO and multiple articles I haven't found a solution to my problem.
What I am trying to achieve is to load 20,000 markers on Google Maps.
R-Tree seems like a good approach but it's only helpful when searching for points within the visible part of the map. When the map is zoomed out it will return all of the points and...crash the browser.
There is also the problem with dragging the map and at the end of dragging re-running the query.
I would like to know how I can use R-Tree and be able to achieve the all of the above.
As noted, R-Tree won't help you when you're looking at a zoomed-out view. This problem is often addressed by marker clustering, because showing 20,000 points in a browser window isn't that useful.
Marker Manager is an open source javascript library which addresses this, but there are others.
With a very great number of markers, you may need to look at server-side clustering, (where R-Tree may come in handy!). Here is one discussion of it, and its google cache because link is dead at time of writing.
If you don't want to bother with clustering, then just terminate your marker list at a preset number, maybe a few hundred (which you can determine by usability testing), and display some indication that there are more available as you zoom in

Categories