1

Sorry if my way of writing is wrong, I'm a data scientist and I have little to none experience in GIS.

I would like to use an open dataset (from http://opendatastore.brussels/fr/ to be precise). It contains mobility data and some locations are encoded in EPSG:31370 (Belgian Lambert 72). I'd like to transform these locations in GPS coordinates (EPSG:4326 if I'm not mistaken).

I'm not sure to understand how you could derive a formula to automatically transform data from EPSG:31370 to EPSG:4326.

Does it exist Python libraries (or R or any other languages) in order to automate these location transformations? I found an interesting website (https://epsg.io/transform) to do it manually but I have +/- 250.000 transformations to do.

6
  • 2
    What is the intended output? A shapefile? A gpx-track? An excel-list?
    – Erik
    Commented Dec 5, 2019 at 16:01
  • 1
    An excel list. I already have points in GPS coordinates and I'd like to incorporate all of them in a single list. Maybe at the end, I'd like to print all these points on a map of Belgium.
    – Dust009
    Commented Dec 5, 2019 at 16:18
  • 2
    You could download QGIS, open the dataset in QGIS, then reproject layer to 4326, then export to csv or xlsx.
    – jbalk
    Commented Dec 5, 2019 at 18:09
  • 2
    pyproj4.github.io/pyproj/stable/examples.html
    – inc42
    Commented Dec 5, 2019 at 18:20
  • 1
    I have a Python solution in this answer here: gis.stackexchange.com/a/339783/122597 You will have to change this line: Transformer.from_crs(crs_from=31370, crs_to=4326) Commented Dec 5, 2019 at 18:34

3 Answers 3

2

If I understand your excellent question, the solution is quite simple. 1) Starting with a blank QGIS project, add the Belgian Lambert 72 layer to QGIS. 2) In the Table of Contents, output a new 4326 layer by right-clicking the Belgian Lambert 72 layer and selecting Save As... 3) the resulting window will provide the opportunity to choose the output layer's CRS (in your case 4326). Voila!, the output layer is 4326!

1

Please follow the following steps,

  1. Download and install Free and Open Source GIS application from QGIS download page or by searching for QGIS in your prefeed search engine
  2. Then open the QGIS and open the database using QGIS Layer > Data Source Manager > Delimited Text with defining the X and Y values fields while with in the same dialog box with giving the CRS as EPSG:31370 (Belgian Lambert 72)

enter image description here

Select Coordinate System enter image description here

  1. then go to the Layers panel and right click on the newly added layer and go to Export > Save feature as ...
  2. with in the dialog box select CSV as the default file format, give a name and location to save and change the CRS to EPSG:4326

enter image description here

Select Coordinate System enter image description here

1

You can set yourself a Python function to to the job using the PyProj library. This will work Shapely geometries, which are usually the one we are working with in the Python GIS domain.

Sample function:

import pyproj
from pyproj import Transformer
import shapely.ops as sp_ops

def  transform_geom_to_srid(geom, scrs, tcrs)
    """ Transform a geometry to a new target CRS.
        Works with pyproj version >= 2.x.x
        - geom is a Shapely geometry instance
        - scrs is your input CRS EPSG integer (the one of your original data)
        - tcrs is your target CRS EPSG integer (the one you want to reproject
                  your data in, probably 4326 in your case)
    """
    project = Transformer.from_crs(
        'EPSG:'+str(scrs),
        'EPSG:'+str(tcrs),
         always_xy=True
    )
    return sp_ops.transform(project.transform, geom)

Notice: if you use an older version of PyProj, you will have to set your CRS manually including an 'init=' string, e.g. pyproj.Proj('init=EPSG:'+str(scrs)) instead of just writing the 'EPSG:' strings in the [.from_crs()][10] method.

More information

Shapely is a library for manipulating geometry data in Python.

An other very useful library, especially for data science, is GeoPandas, it heavily relies on Pandas, which you must, I hope, already know. The geometry column of a GeoDataFrame usually contains Shapely geometries for each row if your dataframe.

See also here for PROJ documentation: https://proj.org/

And here for PyProj: https://pyproj4.github.io/pyproj/stable/

EPSG codes are defined in the EPSG registry, which is actually the IOGP today; https://epsg.org/home.html

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.