Zum Inhalt springen

Wikivoyage:Coordinates

Aus Wikivoyage

Dieser Artikel enthält technische Hintergrundinformationen zum Modul Coordinates. Er dient zur Konvertierung von Koordinaten und ersetzt Parserfunktionen aus der Erweiterung MapSources.

Benötigte Module

[Bearbeiten]

Verwendbarkeit

[Bearbeiten]
Unterstützte Skins
alle
Eignung für andere Wikis
geeignet, Übersetzung nötig.
Eignung für mobile Geräte
ja.

Aufruf

[Bearbeiten]

Der Aufruf erfolgt zumeist in den Vorlagen {{Marker}}, {{vCard}}, {{Coord}} und {{GeoData}}.

Für die direkte Nutzung stehen die Vorlagen {{Coord DD to DMS}} und {{Coord DMS to DD}} zur Verfügung.

Funktionen für Lua/Scribunto-Module

[Bearbeiten]
function cd.toDec( coord, aDir, prec )

toDec converts decimal and hexagesimal DMS formatted coordinates to decimal coordinates.

  • Input
    • coord: coordinate, as a string
    • prec: number of digits after the decimal point, as a number
    • aDir: lat/long directions, as a string

It returns a result array with the following indexes:

  • Output
    • dec: decimal value, as a number
    • error: error number, as a number
    • parts: number of DMS parts, usually 1 (already decimal) ... 4, as a number
function cd.getDMSString( coord, prec, aDir, aPlus, aMinus, aFormat )

getDMSString formats a degree-minute-second string for output in accordance to a given format specification

  • Input
    • coord: decimal or hexagesimal DMS coordinate, as a string
    • prec: precision of the coordinate string: D, DM, DMS, or a number like, 0, 2, 4
    • aDir: lat/long direction to add correct direction letters, as a string
    • plus: alternative direction string for positive directions, as a string
    • minus: alternative direction string for negative directions, as a string
    • aFormat: format array with delimiter and leadZeros values or a predefined dmsFormats key. Default format key is f1. For a list of format keys see below.

It outputs three results for three different variables:

  • 1: formatted string or error message for display, as a string
  • 2: decimal coordinate, as a number
  • 3: absolute decimal coordinate including the direction letter like 51.2323_N, as a string
function cd.getGeoLink( pattern, lat, long, plusLat, plusLong, minusLat, minusLong, prec, aFormat )

getGeoLink returns a complete dms geographic coordinate with latitude and longitude without reapplying the toDec and toDMS functions. Pattern can contain placeholders $1 ... $6.

  • Input
    • Pattern, as a string
      • $1: latitude in Wikipedia syntax including the direction letter like 51.2323_N
      • $2: longitude in Wikipedia syntax including the direction letter like 51.2323_E
      • $3: latitude in degree, minute and second format considering the strings for the cardinal directions and the precision
      • $4: longitude in degree, minute and second format considering the strings for the cardinal directions and the precision
      • $5: latitude
      • $6: longitude
    • lat: latitude, as a string or number
    • long: longitutde, as a string or number
    • plusLat: string which is added to the latitude if it has a positive value
    • plusLong: string which is added to the longitude if it has a positive value
    • minusLat: string which is added to the latitude if it has a negative value
    • minusLong: string which is added to the longitude if it has a negative value
    • aFormat: format array with delimiter and leadZeros values or a predefined dmsFormats key. Default format key is f1. For a list of format keys see below.

It outputs three results for three different variables:

  • 1: formatted string or error message for display
  • 2: decimal latitude
  • 3: decimal longitude

This function can be extended to add #coordinates because cd.getGeoLink returns lat and long, too.

function cd.getDecGeoLink( pattern, lat, long, prec )

getDecGeoLink returns complete decimal geographic coordinate with latitude and longitude without reapplying the toDec function. Pattern can contain placeholders $1 ... $4 (see above). prec specifies the number of digits after the decimal point.

Funktionen für #invoke-Aufrufe

[Bearbeiten]
function cd.dec2dms( frame )

dec2dms converts degrees to degree-minute-second format. It uses the required coordinate and the optional plus, minus and precision values. Identical to MapSources #dd2dms tag. It is usually called by the {{Coord DD to DMS}} template.

  • Application: {{Coord DD to DMS | 14.58 |plus=String for the positive cardinal direction|minus=String for the negative cardinal direction|precision=decimal places}}
  • Example: {{Coord DD to DMS | coord = 14.58 | precision = 4 }} gives 14° 34′ 48″
  • Example: {{Coord DD to DMS | 14.58 | precision = 2 }} gives 14° 35′

Degree values can be both sexagesimal and decimal.

Strings for the cardial directions will be added to the dms value. They can be empty, single letters or strings and will be added at the end of the conversion result. If the original value is graeter or equal zero, the plus string is added, otherwise the minus string is used.

  • Parent frame input
    • |1= or coord: decimal or hexagesimal coordinate
    • |precision=: precision of the coordinate string: D, DM, DMS, or 0, 2, 4. 4 is default.
    • |plus=: alternative direction string for positive directions
    • |minus=: alternative direction string for negative directions
    • |format=: Predefined dmsFormats key. Default format key is f1.
  • Predefined deg-min-sec output formats
    • f1 = { delimiter = ' ', leadZeros = false }, -- default
    • f2 = { delimiter = ' ', leadZeros = true },
    • f3 = { delimiter = '', leadZeros = false },
    • f4 = { delimiter = '', leadZeros = true }
function cd.dms2dec( frame )

dms2dec converts degrees to decimal-degree format. Identical to MapSources #deg2dd tag. It is usually called by the {{Coord DMS to DD}} template.

  • Application: {{Coord DMS to DD | 14° 23' 45'' | precision=decimal places }}
  • Example: {{Coord DMS to DD | 14° 23' 45'' S | precision = 3 }} gives -14.396
function cd.geoLink( frame )

The pattern string can obtain up to six different place holders $1 ... $6.

  • $1 means the latitude in Wikipedia syntax including the direction letter like 51.2323_N.
  • $2 means the longitude in Wikipedia syntax including the direction letter like 51.2323_E.
  • $3 means the latitude in degree, minute and second format considering the strings for the cardinal directions and the precision, see also dd2dms.
  • $4 means the longitude in degree, minute and second format considering the strings for the cardinal directions and the precision, see also dd2dms.
  • $5 means the latitude in decimal format.
  • $6 means the longitude in decimal format.