Search code examples
c#androidiosgeolocationgis

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?


Solution

  • 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

    enter image description here

    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)

    enter image description here

    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.

    enter image description here

    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.

    enter image description here

    enter image description here

    Once you click on the referenced map, QGis will then switch back to the Geo-reference tool with the co-ordinates filled in

    enter image description here

    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.

    enter image description here

    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

    enter image description here

    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