WGS 84 geojson to lat lng coordinate system

219 Views Asked by At

I have a geojson file with polygon data around the British Isles. Using php, I am trying to import this file into a mysql database so I can perform spacial queries.

The geojson file uses the WGS 84 (EPSG:4326) coordinate system. I want to convert these coordinates into lat/lng. I have found found some code here to do the conversion of each point, https://stackoverflow.com/a/18336137/1485815

However, it is requiring a UTM number. This is fine, but the British Isles are split into 3 different UTM codes 29,30 and 31 so I do not know which one to use or do I need to work out which one to use on a per coordinate basis

1

There are 1 best solutions below

0
TheCodeProspector On

I am doing a project using such translations myself. Try this. proj4php\Proj4php I have found it able to convert any datum I have come across so far without an issue. As a tip for looping functions, only include some of the code shown in the github example to re-run every loop or else it will greatly slow the process down. The following is how I implement it.

function spnc_wgs($x, $y) {
    global $proj4, $proj_given, $proj_WGS84;
    // Create a point.
    $pointSrc = new Point($x, $y, $proj_given); //x, y
    // Transform the point between datums.
    $pointDest = $proj4->transform($proj_WGS84, $pointSrc);
    //output lat/lon as array
    $output = explode(" ", $pointDest->toShortString());
    return array('lon' => $output[0], 'lat' => $output[1]);
}

I use this at the start of the php file:

include($_SERVER['DOCUMENT_ROOT']."/vendor/autoload.php");
use proj4php\Proj4php;
use proj4php\Proj;
use proj4php\Point;
$proj4 = new Proj4php();
$proj_WGS84 = new Proj('EPSG:4326', $proj4);

and right before calling the function I set the source projection:

$proj_given = new Proj($projection_used, $proj4);

For a full list of all EPSGs available: Spatial Reference List

Enjoy and good luck!!