Skip to main content

A coordinate converter built on pyproj to convert WWII-era map grid coordinates to latitude & longitude

Project description

milmapcon

milmapcon (Military Map Converter) is a Python library (built using pyproj) which converts 4 or 6 digit grid coordinates from WWII-era maps into latitude and longitude coordinates in the WGS 84 coordinate system. milmapcon can be installed using pip:

pip install milmapcon

Usage

milmapcon supports the following grid systems which were used in the European Theatre of Operations during WWII:

  • British Cassini Grid
  • Irish Cassini Grid
  • French Lambert Zones 1-3
  • Northern European Zone 3
  • Nord de Guerre Zone
  • Iberian Peninsula Zone
  • North Italy Zone
  • South Italy Zone

More information on these grids can be found on Thierry Arsicaud's website which heavily influenced this project. This library is not meant to provide extremely high-precision conversions, but should nevertheless be useful in producing reasonably accurate maps especially if the results are cross-checked against other resources such as original maps or primary-source descriptions of terrain, etc.

Basic usage of the library is as follows:

import milmapcon as mmc

zone_name = "nord_de_guerre"
grid_ref = "vS014448"   # approximate position of the Arc de Triomphe

converter = mmc.Converter(zone_name, print_warnings=True)

lat, lon = converter.convert(grid_ref)
# returns (48.87381346581111, 2.295301091901731)

The library has a very basic utilty to display the coordinates in a GoogleMaps page using Python's builtin webbrowser library:

mmc.show_map(lat, lon)
# opens your browser to a Google map page with a pin on these coordinates

screenshot

The library also has a function which lists all zones currently supported. More importantly, it lists the exact strings which should be used in specifying the zone (as shown above):

mmc.show_zones()

Prints the following list:

1). "british_cassini"
2). "french_lambert_1
3). "french_lambert_2"
4). "french_lambert_3"
5). "iberian"
6). "irish_cassini"
7). "italy_north"
8). "italy_south"
9). "nord_de_guerre"
10). "north_euro_3

Note the print_warnings option upon initializing the Converter class. Leaving this set to the default of True will provide some indication as to why the specified grid reference could not be converted successfully. However, the conversion function will also return None for lat/lon in the event a conversion fails. For example, if you wanted to convert a large number of coordinates, you may wish to suppress the warnings and simply rely on the None values to flag coordinates which couldn't be converted.

A practical use of this might be in converting a pandas dataframe which contains a series of coordinates (example usage below):

import pandas as pd
import milmapcon as mmc

coord_df    # assume we've populated a dataframe of our grid references
            # and that the grid reference is in the "grid_ref" column

# Option 1 - converting a series of references in the same zone. This
# shows no warnings, but will return "None" if a conversion fails.

zone_name = 'nord_de_guerre'
converter = mmc.Converter(zone_name, print_warnings=False)

def convert_1(grid_ref):
    '''
    Custom function to use with pandas apply
    '''
    lat, lon = converter.convert(grid_ref)
    return f'{lat},{lon}'

coord_df['lat/lon'] = coord_df['grid_ref'].apply(lambda x: convert_1(x))

# Option 2 - converting grids in multiple zones where the zone is a
# separate column of the dataframe

def convert_2(zone, grid_ref):
    converter = mmc.Converter(zone_name, print_warnings=False)
    lat, lon = converter.convert(grid_ref)
    return f'{lat},{lon}'

coord_df['lat/lon'] = coord_df.apply(
                lambda row: convert_2(row['zone'], row['grid_ref']), axis=1)

Here I chose to return the coordinates to the dataframe as comma-delimited strings which could be parsed out into separate columns, converted back to float, etc. It's also worth noting that this approach may not be highly performant if the dataframe is large, but should handle hundreds (or even thousands) of rows without too much difficulty. The main advantage here is getting the data in a format that can be used in something like geopandas, for creating custom maps.

Other technical considerations

Successful use of this library requires you to know the map zone in which a given grid square reference exists. Fortunately there are a few excellent resources which can help:

  1. echodelta.net - This site by Thierry Arsicaud provides a lot of information about these old coordinate systems and also includes an online coordinates translator which can be used as well. As noted above, this site was used as a primary source of research for defining the coordinate transformations.
  2. McMaster University Library - has made high-quality scans of period maps available to download. These were indispensible for obtaining technical map data such as the natural origins, projections, grid square origins, and false coordinates of the origin.
  3. UT Austin Libraries - has similarly made a large number of maps available from the U.S. Army Map Service. These scans are also of very high quality.

Adding more maps

In since the calculations are done using the pyproj library, it is possible to add additional zones to this library. Please contact me if you are interested. For each zone additional zone, the following data would be required:

  • Understanding of all two-letter (100 km) grids in the zone, and their relation to one another, for the purposes of programming the origins for each grid.
  • Data pertinent for defining the coordinate system in pyproj. Namely:
    • Type of projection (i.e. Cassini Solder, Lambert Conformal, etc.)
    • Coordinates of the natural origin
    • False coordinates (Easting, Northing) of the natural origin
    • The reference ellipsoid (i.e. Bessel, Airy, etc.) or the underlying parameters which define them such as the radius of major/minor axis ($a, b$), inverse flattening ($1/f$), scaling factor ($k_0$)

The data for the supported projections are packaged with the library as a sqlite3 database, but will also be made available on the GitHub repository for this project in .csv format.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

milmapcon-1.0.2.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

milmapcon-1.0.2-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file milmapcon-1.0.2.tar.gz.

File metadata

  • Download URL: milmapcon-1.0.2.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.7

File hashes

Hashes for milmapcon-1.0.2.tar.gz
Algorithm Hash digest
SHA256 e425b346c7bfb09d5fd166765d690b70176e12bf971920953f68ea42215fd762
MD5 2f252589ea7733721a5c1e2e87badfad
BLAKE2b-256 18808cfe03f8d5d5f8f529a0aa170ffa199b7fac822e66c65ab85625a024ca15

See more details on using hashes here.

File details

Details for the file milmapcon-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: milmapcon-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.7

File hashes

Hashes for milmapcon-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 873926ffb240a4423690ff9ab9a2fe2b7f7c63eb0c1217c5e9daa3adb991e6ce
MD5 91c96d5c70d51fd1d445c452abb2bfef
BLAKE2b-256 852b4ec0c4ee6f16f43efcefc1c2f2812e171483233b58862f354255ef67627c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page