Converting GPS coordinates into 3D model - c#

As the question says, I am looking to use GPS coordinates (say from Google maps) to build a 3D model (a road).
So it should work as follows:
You go to Google maps and select a route (this can be between 2 points or a circuit). You then get the lat long coordinates for this route.
Using this data, you then feed it into a program that generates a height map of the coordinates as obtained from Google maps.
I am trying to make a demo in C# (XNA) that you can quickly generate a course of your neighbourhood for a driving sim (as long as I get the main road sections right its ok, wont be able to add detailed characteristics of the road e.g. a ditch next to the road or small bumps in the actual road surface).
Does anyone have any ideas on where I would even start with a problem like this (tried Google already but the best I could find was here)

GPS coordinates (latitude, longitude, altitude) uses a speherical 3D modell. What you want is a transformation to a cartesian 3D Model.
For this case you can convert them into ECEF coordinates, this then are a x,y,z coordinates
For ECEF overview see ECEF

A starting point could be to look at the Dotspatial libraries for .NET: http://dotspatial.codeplex.com/
I have used these libraries, but mainly to gather GPS coordinates from an external device. I haven't used these coordinates on a map for instance. The documentation is limited, but if you pry around you might be able to find some info.

Related

Graph visualization in C#

I'm currently learning swarm intelligence algorithms and I want write a C# app for testing those in the context of a vehicle routing problem.
I want to write an app that will show a graph that will be a representation of of cities (vertices) and roads (edges) and implement new algorithms as I learn more of them.
The problem is I don't know how I can draw such graph. I was thinking about using adjacency matrix to know if the vertices are connected and another to represent the distance between them if they are connected.
If You know any way to visualize such graph in a efficient way it will be much appreciated. I saw someone was able to do so using picture box which is mind blowing.
The simplest option is probably to create a winforms application and attach an event handler for your paint-event. This will give you a graphics object that can be used to draw squared, lines etc. Note that you probably need to translate your coordinates from your internal coordinate system to screen/image coordinates.

How to map a user location to a not true to realism map?

I'm sorry if this question is broad but I have not been able to find any real solutions to the problem I must solve. I need to solve the problem of mapping a user's location to an image that represents a map (like an amusement park map).
One possible solution would be to define GPS coordinates to different parts of the image and then snap the user's location to the closest defined location.
Something else I saw was Geospatial PDF's but I couldn't find much on implementing a way to read Geospatial information from the PDF.
How can I take an image that represents lets say a theme park and map a user's location to it?
Short answer:
You can't, by which I mean you can't just take a regular image and snap co-ordinates to it's pixels.
Long answer:
You can, but it takes a lot of work and preparation, here's the basics of what you need to do.
STEP 1 - Georefrence the image
To do this you need some GIS software, and an existing map of the area that's registered in the correct co-ordinate space.
If you have the budget, then you should consider using professional software such as Autodesk map 3D or the ESRI suite of tools. If you don't have a budget, you can do this using free tools such as QGIS.
I'll assume QGis for this description.
Load the existing map that you have for the area (The one that's already referenced) into your GIS Package. (How and where you get this map from is entirely up to you, if your lucky you might have one someone else did, or the builders of your park might have site plans you can use, without this source map however, you can forget any chance of matching the image to it unless you have a list of all the points you want to reference) [SIDE NOTE: It's perfectly feasible to go out with a GPS device and record your points manually, esp if the site your mapping is not to big and you have full access to it, since your only referencing an image of your own, and not building anything then super, duper 1000% accuracy is not needed]
Assuming the use of QGis, go up to the "Raster" menu, and select the "GeoReferencer" tool
Once the tool loads, you'll be presented with a child window that allows you to load your "Un-referenced" map image into it. (The load button is marked with a red arrow)
Once you have your raster image loaded, you then need to use the already referenced map you loaded into QGis (Sorry no space to document this part, there are a multitude of ways, depending on what data you have) and pick points from it that match the raster, in your georeferencer tool.
Make sure the georeferencer tool is in add point mode.
Then click on the image that you loaded into your geo-referencing tool, at the location where you want your first point.
The enter map co-ordinates box will pop open.
If you already know the location of these points (For example because you went out with a GPS, or you have some survey data) then you can simply just type them in. If not, then click the button marked "from map canvas", and the geo-reference tool will switch to the already referenced map you have loaded, and ask you to click on the same location on the referenced map.
Once you click on the referenced map, QGis will then switch back to the Geo-reference tool with the co-ordinates filled in
At this point, you can click "OK" and the point will be registered on your un-referenced raster image as a referenced point (Small red dot)
Repeat this process, until you have as many locations as you want referenced. You don't have to do everything, but key locations, such as park entrances, corners around the main site outline, centers of prominent buildings and road junctions should be done.
The more points you reference, the more accurate the final referenced raster image will be.
Once you've finished adding the points to your image to reference it, you then need to click the yellow cog wheel, and fill in the options for the output raster, target SRS and other things that will turn this into a map.
Now, at this stage I've not mentioned a VERY, VERY, VERY important concept, and that's the "SRS" otherwise known as the "Spatial Reference System"
You may have noticed in my screen shots above, when the co-ordinates were entered in the dialog by clicking on the map, that they did not look like the usual latitude/longitude pair that a phone or GPS unit might produce.
That's because ALL of my maps are in an SRS known as "OSGB36" (or EPSG:27700), which is the local spatial reference system for the united kingdom.
I could have if I'd wanted to, used the standard GPS system (Known as WGS84 or 'EPSG:4326') but because I'm working only within the UK, doing that would actually have cause errors in my calculations.
If your working with something a small as an Amusement park, then for best results you NEED to find what your local geographic co-ordinate system is, using standard GPS co-ordinates will cause too many errors, and might even lead to incorrect location plotting when you finally plot your point on your image.
There's simply far too much info for me to put into an SO post, so I would strongly suggest that you grab a free copy of the EBook I've written on the subject from here:
https://www.syncfusion.com/resources/techportal/details/ebooks/gis
That will fill in a large amount of the background knowledge you need, in order to do this.
Once you've set your settings, and added all your reference points, your then ready to create your referenced raster image, by simply clicking on the green triangle
Once you get to this point, and your referenced image is saved, you will now have a map/image that should be referenced in your local co-ordinates, and can understand a point given to it in the same co-ordinate system, and know where to plot it on a map.
That however, is only the start of your journey.
STEP 2 - Build a map server
Once you have the image, you then need to host in something called a WMS server.
Again, describing how to do this from the ground up in an SO post is simply just not practical, what you need is something like "geoserver" (A Java based easy to use map server system) or something like a bare bones linux system, with apache webserver installed and the mapserver CGI binary application to run under it.
Once you have a map server set up, and serving maps using the WMS protocol, you can then move onto the final stage
STEP3 - Creating your application to display the map
The final part of the equation is to build an application to display the map from your WMS server, and then take the location of the person or item you want to plot, optionally convert the co-ordinates to the local SRS that matches your image, then plots the dot over the image in the correct location.
If your doing this in a web/mobile application, then you'll most likely want to investigate the use of openlayers.js or leaflet.js, if your doing this in a C# application, then GreatMaps or SharpMap are the toolkits you want to be looking at.
Wrap up
Many folks think that plotting locations onto a map image is a quite straight forward and simple task, I can tell you now it's not.
Iv'e built many GIS systems over the years, and even the simplest of them has taken me over 3 months.
Even a simple idea such as the one your asking about, takes tremendous amounts of planning and analysis, there is no quick way of doing this unless you simply just want to host a google maps image on your web page, and match your device co-ordinates up to that.
The second you start to produce custom maps, you automatically set yourself up for a lot of work, that's going to take you time and patience to get it right.
Pixels in images simply don't match up to real world co-ordinates, and the truth of the matter is simple. There's a reason why mapping and GIS companies charge as much as they do to create systems like this.
References and further reading
http://www.qgistutorials.com/en/docs/georeferencing_basics.html
http://www.digital-geography.com/qgis-tutorial-i-how-to-georeference-a-map/
http://glaikit.org/2011/03/27/image-georeferencing-with-qgis/
http://geoserver.org/
http://mapserver.org/uk/index.html
http://openlayers.org/
All the best with your project, and please know this, your in for a lot of work, but your also going to have a lot of fun, and learn heaps of new stuff, the world of GIS is by it's very nature complicated, but it's also a very fascinating subject, especially when you start drawing your own maps from scratch :-)
Shawty
If your map image represents a not so large area, then I would think of this as a rectangle.
It would be just a matter of transforming your Lat/Lng coordinates to (x,y) coordinates inside your image.
Lat2 |----------------------------|
| |
Lat1 |----------------------------|
Long1 Long2
Assign the real world Lat/Long coordinates to each corner of your map:
Bottom Left Corner = Lat1, Long1
Bottom Right Corner = Lat1, Long2
Upper Left Corner = Lat2, Long1
Upper Right Corner = Lat2, Long2
Given the user longitude and latitude and knowing the width and height of your image, you can calculate the transformed (x,y) coordinates over the image:
x = User Longitude * Image Width / |Long2 - Long1|
y = User Latitude * Image Height / |Lat2 - Lat1|
You should now be able to put a pin over that (x,y) position.

How to retrieve the coordinates of the building (length, width, height) on google maps or bing maps?

I wonder if it is possible with google maps or bing maps to retrieve the coordinates of the buildings? their positions (latitude and longitude) and height of buildings if possible?
If we can recover the angle of view and the perspective used we should be able to calculate the height Approximate not?
I already searched on the web, but apparently it is not possible to get all this information?
A thousand thank you
Preferably in c # ^ ^
There are a couple of ways to do this but they are not perfectly accurate and may have legal issues. Using the Birdseye imagery in Bing Maps gives you an angled view of buildings which technically there is a lot of math that could be done to get the height of the building. However, using Birdseye imagery to do this is against the terms of use of Bing Maps and is a restriction put in place by the data provider for birds eye imagery.
Another method is to use the old Bing Maps 23D control and mouse events to get the altitude of the clicked location. I wrote a blog post on this a long time ago here: http://rbrundritt.wordpress.com/2009/10/03/bing-map-3d-altitude-extraction-via-mouse-click/
Bing Maps has a new 3D map control which is currently in preview as a Windows 8 app. There is no public API at this time but if this is for a proof of concept or demo you could always try playing around with the dll's. Here is a blog post on how to do that: http://sharpgis.net/post/2014/01/28/The-layout-of-an-ExtensionSDK

I want help and idea about how to draw The path of GPS in C#

as you can see i want to do senior project about soccer player tracking with gps to show the path that player was using or tracking in real time
i already study about basic gps function in c# but I Really Have problems on how to draw paths on the map or picture that i want to use after we got the data from gps.
the hardware part are already finish but i get stuck in and idea for how to get the data from gps to draw path of player
I appreciate with any help on me ( sorry for bad english) Thank you very much
Link of my designed project picture :
http://image.ohozaa.com/view2/weK9gVKBzGZqRxKC
Just think about what you're doing.
GPS data (from each player) is received as a sequence of points (Latitude/Longitude?).
Convert those points to X/Y coordinates for your football field image
Use a graphics API (such as GDI / System.Drawing ) to draw lines between subsequent points
If you're using C# you might save time and trouble by using WinForms and subclassing Control and painting directly to the control's surface. You'll need to store a list of all the recent points for each player (because you'll need to constantly repaint the control).
Note that the geolocation features in .NET won't help you here unless all of your football players are going to be carrying laptops strapped to their backs. You'd want small GPS trackers attached to each player along with a small radiotransmitter that sends the data. An easy way to do this is with a commodity Bluetooth GPS unit, but I don't know if Bluetooth can support that many transceivers in such a small space, or even if the signal will reach from one end of the field to another. The most expensive way is to write a phone app and have each player carry a smartphone that sends geolocation data via a 3G or Wifi connection.
Note that GPS units tend to have a usable accuracy of about 5m (maybe 2.5m on a good day), and are useless indoors. Then consider the 5 minutes it takes for them to secure a good lock in the first place (mobile phones have quick geolocation because they use assistance from mobile phone masts). Football fields aren't very big, and even with 2.5m accuracy the data isn't going to be very useful.
In real sports they don't use GPS for this reason. Instead they use higher-precision radio units and specialist transmitter/receiver units placed around the pitch. An alternative is visual tracking, but that's an immature science (Turing help you if two players or more wearing the same team colour collapse into each other).
Looking at the picture you provided I'd say something like this is feasible with a WPF application using the Canvas control and the Line class. You'd have to convert your GPS data to (x,y)-coordinates where the origin is located at the upper left corner of the soccer field. Then you could connect subsequent points using line segments.

C# Create "wireframe"/3D "map"

image http://prod.triplesign.com/map.jpg
How can I produce a similar output in C# window forms in the easiest way?
Is there a good library for this purpose?
I just needs to be pointed in the direction of which graphic library is best for this.
You should just roll your own in a 3d graphics library. You could use directx. If using WPF it is built-in, you can lookup viewport3d. http://msdn.microsoft.com/en-us/magazine/cc163449.aspx
In graphics programming what you are building is a very simple version of a heightmap. I think building your own would give your greater flexibility in the long run.
So a best library doesn't exist. There are plenty of them and some are just for different purposes. Here a small list of possibilities:
Tao: Make anything yourself with OpenGL
OpenTK: The successor of the Tao framework
Dundas: One of the best but quite expensive (lacks in real time performance)
Nevron: Quite good, but much cheaper (also has problems with real time data)
National Instruments: Expensive, not the best looking ones, but damn good in real time data.
... Probably someone else made some other experiences.
Checkout Microsoft Chart Controls library.
Here's how I'd implement this using OpenGL.
First up, you will need a wrapper to import the OpenGL API into C#. A bit of Googling led me to this:
CsGL - OpenGL .NET
There a few example programs available to demonstrate how the OpenGL interface works. Play around with them to get an idea of how the system works.
To implement the 3D map:
Create an array of vectors (that's not the std::vector/List type but x,y,z triplets) where x and y are along the horizontal plane and z is the up amount.
Set the Z compare to less-than-or-equal (so the overlaid line segments are visible).
Create a list of quads where the vertices of the quads are taken from the array in (1)
Calculate the colour of the quad. Use a dot-product of the quad's normal and a light source direction to get a value to shade value, i.e. normal.light of 1 is black and -1 is white.
Create a list of line segments, again from the array in (1).
Calculate the screen position of the various projected axes points.
Set up your camera and world->view transform (use the example programs to get an idea of how to do this).
Render the quads and lines, OpenGL will do the transformation from world co-ordinates (the list in (1)) to screen space. Draw the labels, you might not want to do this using OpenGL as the labels shouldn't scale with distance from camera, otherwise they could get too small to read.
Since the above is quite a lot of stuff, there isn't really the space (and time on my part) to post working code (but someone else might add something if you're lucky). You could break the task down and ask questions on the parts you don't quite understand.
Have you tried this... gigasoft data visualization tools (Its not free)
And you can checkout the online wireframe demo here

Categories