1

I have been prototyping a simple navigation app using QGIS. If I generate tiles from OpenStreetMap using Generate XYZ Tiles, I create a basic app using Leaflet JS. I can then use the Geolocation API to monitor my movements. I am using EPSG:3857. However, I need to use a base map generated by a third party using a CAD tool, in order to have more detailed features than is available in OSM. However, their CAD tool only supports Eastings and Northings (in metres). Once I have imported their layer group, and set the CRS to EPSG:3857 I still have the position information in Eastings and Northings.

I have tried to change this but cannot find any way, but it surely ought to be possible as I can type an individual location into, for example, Grid Reference Finder, and I get back the correct lat and long?

Addendum 10th Feb:

I think I am getting to the root of the problem. I am doing something stupid but not sure how to fix it. Let me explain what I am doing and then I will be able to rephrase my question.

If I start off with an Open Street Map base, and then try to add my DXF layers, nothing appears on top of the OSM layer, although the DXF appears to have loaded without a problem and its three layers appear in the Layers window. So, what I did was to open a new project and simply add the DXF. This is what I get: Screen Shot with DXF loaded Notice the coordinates at the base. These are in metres. However, the origin was presumably set in the original CAD file so that these are correct eastings and northings. This is why I thought that the CAD file had been located correctly. But I don't believe QGIS has done anything of the sort, which is why my DXF would not register on the OSM map when I tried this. If I then add the XY fields (or just right click on the map window and copy coordinate) I get something like this: 4.548068,1.431102. It is way off the true location and I believe this is because the lat long location of the imported DXF is quite arbitrary.

So, it seems my question should be along the following lines. How can I create a custom CRS given that I know the mapping of the metre coordinates onto Lat Long? For example, I have been given that the four corners of the box around my map are: Top Left Corner X = 505900.0 Y = 160200.0 Top Right Corner X = 507400.0 Y = 160200.0 Bottom Left Corner X = 505900.0 Y = 157500.0 Bottom Right Corner X = 507400.0 Y = 157500.0 These are eastings and northings so if I convert them using Grid Reference Finder I do indeed get the correct lat and longs.

2
  • When you say "I still have the position information in Eastings and Northings," do you mean you're selecting "Open Attribute Table" for one of your new layers, and seeing the Eastings and Northings there? Because those numbers will not change. The coordinates QGIS for display are hidden, although it does provide tools to make them visible. Is your end goal here to display those numbers in QGIS, to export them so your Leaflet application can use them, or both? And what geometry type are they - points, lines, polygons or a combination of those?
    – Cowirrie
    Commented Feb 8, 2022 at 21:53
  • If I look at the coordinates on the lower bar of QGIS it shows me the eastings and northings as I move the mouse around on the map I have generated from the CAD file. Basically, the CAD file contains a map of a site in the UK with points, lines and polygons on it. This was generated in AutoCAD. I want to import this into ArcGIS so I can generate the tiles to export into Leaflet so I can use the Geolocation API to show someone their location as they walk around the site.
    – P. Krause
    Commented Feb 9, 2022 at 20:24

3 Answers 3

3

Don't set the projection to EPSG:3857, that does not work.

Keep it as the original CRS and run the Reproject Layer tool from Vector>Data Management Tools> Reproject Layer...

And choose EPSG:3857 as the Target CRS.

5
  • This is a bit strange. I can't seem to make any change this way, other than loose the colouring of the original layers. This is what I am doing at the moment. I create a new project. This will open set to EPSG:4326 as default but I change this to 3857. I then add my .dxf file by dragging and dropping from the browser. This gives three layers. I re-project each although they have already taken up 3857 from the project. So this doesn't seem to change anything. I'm using QGIS 3.22.1
    – P. Krause
    Commented Feb 8, 2022 at 20:49
  • 1
    QGIS re-projects the layers on the fly into the project CRS. That does not impact what the layers CRS is, re-projecting does. But if you bring in the DXF and it does not line up with the other data even though QGIS is re-projecting it, the DXF might not have a projection at all. Commented Feb 8, 2022 at 21:27
  • Yes, I suspect the DXF has no projection. I think I need to talk to the team that produced the DXF. Many thanks for the help with this.
    – P. Krause
    Commented Feb 8, 2022 at 21:52
  • Are you seeing locations from the DXF appear on your map in the right places? If so, the DXF is providing sufficient projection information to QGIS. It's just that, as HeikkiVesanto says, it quietly reprojects behind the scenes without telling you what coordinate values it's now using internally. But you can get those out if you need them.
    – Cowirrie
    Commented Feb 8, 2022 at 23:25
  • Yes, everything is lining up fine. It is just that it is fixed on using eastings and northings. So as I mouse over the map in QGIS it will give me a coordinate such as [506570, 158721]. If I enter these into a tool like Grid Reference Finder, it gives me back the correct lat and long: [51.317626 , -0.47217753] in this case. I'm even a but more confused now as when I Generate XYZ tiles, it gives me this for the centre of the map: setView([1.4241217994743893, 4.549504809454286] and I have no idea what those coordinates represent. It should be approximately the same location.
    – P. Krause
    Commented Feb 9, 2022 at 10:54
3

Your Source Data Coordinates

Your DXF file must have a valid Coordinate Reference System, or it wouldn't appear in the right place on the map. It may well be different from your Project Coordinate Reference System, but if they're different, QGIS will automatically reproject when needed. QGIS will run a little more efficiently if you reproject the geometry layers, but that's the only different reprojection will make.

The above paragraph was optimistic, wrong, and written before the addendum to the question. See other answers for more discussion on this.

Numbers Showing in the QGIS Status Bar

The units of the EPSG:3857 Coordinate Reference System are meters, and by default, this is what QGIS will show in the status bar. Specifically, they are meters from the zero latitude, zero longitude. In the screenshot below I have changed this to show "Extents" rather than the mouse cursor; note that the magnitudes of the numbers are nearly equal, because the map is (nearly) centered on 0,0.

QGIS screenshot showing status bar with Extents from -1097997,-722896 to 1085698,728785 and Coordinate Reference System of EPSG:3857

You say that these numbers appear to be valid eastings and northings. This part I can't explain. Can you post a screenshot of your QGIS window and the values you see there, with both the position numbers and the CRS value in the lower right?

Changing the Coordinate Display in the QGIS Status Bar

If you want different numbers in the status bar, you can change the format in the Project Settings > General > Coordinate and Bearing Display. This will not affect the way your data are stored and exported. See also the question Set the QGIS display to show decimal degrees?... which also has some people reporting this not working.

Screenshot of window with heading 'Project Properties' and with 'General' selected in the upper left and a red box around 'Coordinate and Bearing Display'

Leaflet setView

According to the Leaflet Documentation, the first argument to Map.setView is a Latitude, Longitude pair. Numbers I've seen generated by QGIS for different locations are centered as expected, so I'm not sure why yours are so far from the region you are looking at.

Seeing Coordinates of Your Point Geometry

You mention running the mouse over the map to coordinates. Would you like to see where QGIS thinks your geometry is? If you have a point layer, you can run the Add X/Y fields to layer Tool, and have their coordinates appear in the Attribute Table. If using this tool, set the Coordinate system to EPSG:4326 - WGS 84 for output in degrees. Setting it to EPSG:3857 - WGS 84 / Pseudo-Mercator will generate the same coordinates in meters that you are already seeing.

Like most QGIS tools, this will generate a new layer with randomly assigned symbology in a single color.

1
  • Very many thanks for this Dondragmer. I have added more material to my question following on from your answer. I will do a bit more searching of the documentation as I know better what to look for now, but if you have any experience of setting custom CRS that might help me, I would greatly appreciate it!
    – P. Krause
    Commented Feb 10, 2022 at 10:45
0

Thank you for your addendum, now we're pinning this down. I shouldn't have confidently said QGIS was putting your geometry in the right place. It must be showing it in the South Atlantic somewhere.

UTM and MGRS

I was also confusing UTM (Universal Transverse Mercator) with MGRS (Military Grid Reference System). They share the 60 bands of longitude, but with MGRS you also have those latitude bands which define the grid zone.

Other people with this issue haven't received much help. There used to be an MGRS Tools plugin for QGIS 2, but the only reason I know this is people reporting it doesn't work, and now you can't even download it.

Assign Projection

If you can get the right Coordinate Reference System, you can use the Assign Projection Tool to put it in the right location. This is distinct from the Reproject Layer Tool, which assumes that your geometry is already in a known place.

Creating a Custom CRS

You could try to manually calculate the fix, as this hard-working person had to. But you may be able to work out a custom CRS and still have QGIS do the rest of the work for you. If you can work out the CRS you want, the question Creating custom CRS in QGIS shows where in the user interface to do it. And yes, you really do follow the steps to create a new User Profile and suddenly you get the menu options to create custom projections!

You can get approximately right by finding a UTM projection of the correct longitude band, copying the text from that, and editing the false northing and possibly the false easting to match the grid zone you're in. But your geometry looks precise enough that you need to be sure about the datum as well. Have they come from an existing map, from examining aerial photographs, from walking around with a GPS, or some combination of the above?

2
  • Many thanks. I will have a go at creating a custom CRS. I should have enough information. The northings and eastings I have come from the UK Ordnance Survey so we actually have very precise location information. My colleague in the CAD group of the charity I am trying to help on this did send me a DXF with a marker giving the lat long coordinates but QGIS did not seem to use this. I do have some precise datums.I know Coordinate [505900 , 160200] on my GIS corresponds to [51.331045 , -0.48134893] lat long, for example. So it must be possible to get QGIS to do the necessary?
    – P. Krause
    Commented Feb 10, 2022 at 21:56
  • At a minimum, QGIS provides a validation interface when you're defining a custom CRS so you can enter your known points and make sure those line up. Good luck.
    – Cowirrie
    Commented Feb 10, 2022 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.