Giter VIP home page Giter VIP logo

Comments (3)

dvdoug avatar dvdoug commented on June 5, 2024

Yes, the original versions were very OSGB36 specific and kinda sorta ignored a lot of (sadly needed) complexity that's required once you expand to different coordinate systems.

//Old
$os = new OSRef(199800, 554200);
//New
$from = ProjectedPoint::createFromEastingNorthing(
new Metre(554200),
new Metre(199800),
Projected::fromSRID(Projected::EPSG_OSGB_1936_BRITISH_NATIONAL_GRID)
);

This looks right, except that you've reversed the order of coordinates - both old and new are (easting, northing) so you shouldn't need to do that.

From there, you need to explicitly decide which "world model" (datum/ellipsoid) you want your latitude and longitude to use. The older version you're currently using would have assumed you wanted the Airy Ellipsoid (OSGB36). If you actually wanted WGS84 instead, you'd do a followup conversion. Those were the only 2 coordinate systems it supported so that made it easy to use.

//Old
$ll = $os->toLatLng(); // assumed OSGB36/Airy Ellipsoid
$ll->OSGB36ToWGS84(); // optional conversion depending on needs

New PHPCoord allows you to convert to many, many different systems so you need to choose up front.

//New
$toCRS = Geographic2D::fromSRID(Geographic2D::EPSG_OSGB_1936);
//or
$toCRS = Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84);
$to = $from->convert($toCRS);
echo $to->getLatitude() . " " . $to->getLongitude();

Hope that helps?

from phpcoord.

dvdoug avatar dvdoug commented on June 5, 2024

See also https://www.phpcoord.net/en/stable/creating_points_projected.html#british-national-grid if you need to work with grid letters

from phpcoord.

imbeingfollowed avatar imbeingfollowed commented on June 5, 2024

Cheers for your help Doug - with your kind notes and a fresh head this morning I was able to tackle it.

You were correct - I was converting a grid ref to Easting & Northings prior to that step as I don't think the library supported that at the time. I've removed that step now.

Here's my final code in case it helps anyone.

$point = BritishNationalGridPoint::fromGridReference('TQ 30017 80419');
$toCRS = Geographic2D::fromSRID(Geographic2D::EPSG_OSGB_1936);
$to = $point->convert($toCRS);
$start_lat = floatval((string) $to->getLatitude());
$start_lng = floatval((string) $to->getLongitude());

Thanks again.

from phpcoord.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.