Geolocation, map and polygon intersection? - google-maps

I need to retrieve the latitude and longitude coordinates of the intersection of a polygon with the street (look the blue point on the edge of the circle. image here!!!)
I need this data in order to calculate the road length from center of the circle, to its edge). Does anybody know if this task is possible, and if yes which technology allows for doing that ?

This works only if you have the vector data of all streets. This does not work with an image (jpg bmp).
When you have the vector data, you do a simple circle with line intersection, which you have learned in school.
You might transform the vectors first to a cartesian x,y plane such that you dont use latitude, longitude from the street vectors.
vector data, you can get for free from OpenStreetMap, or from TomTom or NavTeq when it is a huge project. Sometimes the state provides this data, too.
A common data format for such vector data is the ESRI shp file format. (.shp)

Related

How to obtain the physical coordinates of the nodes in an ITK :: Mesh obtained from a 3D volume of ct images

I am using ITK library to get a mesh from a 3D image, the 3D image is a volume of slices. I get the mesh using itk::BinaryMask3DMeshSource. But I need to get its physical coordinate for each mesh node and I don't know how to do it.
I know how to obtain with ITK the physical coordinate of a voxel in a image using the TransformIndexToPhysicalPoint function. But when I have a mesh like this or an ITK::Mesh I don't know how to do it. I need to know if there is any relationship between the nodes of the mesh and the voxels in the image to find the physical coordinates.
Mesh points should already be in physical space, judging by both the code and the accompanying comment.

DXF generation using ezdxf: polyline containing spline fit points

I am developing a program, and one of the requirements is to take DXF as input. The input is limited to 2D case only. The program itself is in C++/Qt, but to test it I need some sample DXF input. The spline import is already implemented, the next step is polyline with spline fit points or control points added. I decided to use Python/ezdxf to generate such polyline, as I don't have Autocad.
My first approach was to create a spline from fit points utilizing add_spline_control_frame, then convert it to polyline. The problem is there turned out to be no conversion from spline to polyline (although I think I saw it in the docs, but cannot find it anymore).
The current approach is to make polyline by add_polyline2d(points), making each point to be with DXF flag field equal 8 (spline vertex created by spline-fitting). The problem is points need to be of type DXFVertex (docs state Vertex, but it is absent), and that type is private for ezdxf.
Please share your approaches either to the problems I've faced with ezdxf, or to the initial problem.
P.S. I tried to use LibreCAD to generate such a polyline, but it's hardly possible to make a closed polyline from spline fit points there.
The ability to create B-splines by the POLYLINE entity was used by AutoCAD before in DXF R2000 the SPLINE entity was added. The usage of this feature is not documented by Autodesk and also not promoted by ezdxf in any way.
Use the SPLINE entity if you can, but if you have to use DXF R12 - there is a helper class in ezdxf to create such splines ezdxf.render.R12Spline and an usage example here.
But you will be disappointed BricsCAD and AutoCAD show a very visible polygon structure:
Because not only the control points, but also the approximated curve points have to be stored as polyline points, to get a smoother curve you have to use many approximation points, but then you can also use a regular POLYLINE as approximation. I assume the control points were only stored to keep the spline editable.
All I know about this topic is documented in the r12spline.py file. If you find a better way to create smooth B-splines for DXF R12 with fewer approximation points, please let me know.
Example to approximate a SPLINE entity spline as points, which can be used by the POLYLINE entity:
bspline = spline.construction_tool()
msp.add_polyline3d(bpline.approximate(segments=20))
The SPLINE entity is a 3D entity, if you want to squash the spline into the xy-plane, remove the z-axis:
xy_pts = [p.xy for p in bpline.approximate(segments=20)]
msp.add_polyline2d(xy_pts)
# or as LWPOLYLINE entity:
msp.add_lwpolyline(xy_pts, format='xy')

Distance to the nearest train station

Using Google Map or any other map provider, if I have a GPS tracking device on a train, how do I get a railway distance between the train to the nearest train station?
If you are physically on the train and have a GPS tracked device, most mapping platforms won't be able to snap you to the railway line unless the device/user is sitting at a station. If the device is close enough to road, usually within 150 meters, it will likely snap to that. If the user was at a station, its much easier and just a matter of calculating a transit route.
That said, most transit data uses straight line distances between stations and not true travel distances. I've worked with many large transit agencies around the world and many of them don't even know where their railway lines run, let along the true distance between stations. What they do know is how long it takes to travel between stations and that's all they generally care about for the most part.
To do this correctly, you will need access to the raw railway line vector data. Open street maps has some, but I don't know how accurate or complete it is. Many agencies or governments publish this data, but often it is just straight lines drawn between stations, so you would have to look and see what's available. Once you have complete data, then you can snap to your GPS point to the nearest railway line then calculate the shortest path along all railway lines to the station in question. This is fairly complex, but I've done this before for both railway lines and private road networks. There are several open source libraries that can assist with this, like this one: https://github.com/perliedman/geojson-path-finder

Geotools: Render a GridCoverage2D to a heat map

I'm new to use geotools. Now I need to generate a heat map showing the data density.
I found a Kernel density estimation process from here: https://jira.codehaus.org/browse/GEOT-4175, and so far it gives me a heatmap surface over a set of irregular data points as a GridCoverage2D.
My question is, how can I display it in a heat map fashion? Thanks a lot!!!

Mongodb geospatial index vs GoogleMaps Directions Service

I recently worked on a small project on location-based services and my intention was to locate the nearest cab (GPS fitted) within a given radius of a requesting passenger (GPS enabled Android phone). I wanted to use MongoDB's geospatial indexes, but it turned out that geospatial indexes work on lat-longs and they calculate displacement between two points, not the distance. In my case, search was confined within a city, and I had to go for GoogleMaps Directions Service because it tells the distance as on the road, estimated time taken etc.
Does this mean that geospatial indexes make sense only when displacement is large enough, so that distance and displacement becomes essentially the same?
Geospatial indexes have the goal of having fast data retrieval based on position on a multi-dimensional space. If you have the cab position data in a MongoDB database you could use a geospatial index to fastly select a reduced set of cabs which are more likely to be the closest one, but still you'd have to calculate the distance on the road (and eventually the drive time) using an algorythm on the road network.
For example you know that if the closest (in straight line) cab is at 20km from you (measured through the road), you know that any cab outside the 20km radius will surely be further away (on the road) than the first one you found, so you're not interested in them.
You can then use MongoDB spatial index to get all the cabs in 20km radius and then you can find among them which one has the minimum distance.