Comments (3)
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.
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.
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)
- ITM to WGS84 error
- Irish Grid to WGS84 problems HOT 6
- Uncaught Error: Class 'PHPCoord\CoordinateReferenceSystem\Projected' not found HOT 4
- Lat/long from eastings & northings v4 HOT 6
- License requirments of the EPSG dataset HOT 4
- I experience a memory leak HOT 2
- Accuracy of EPSG_AMERSFOORT_RD_NEW ⇒ EPSG_WGS_84 conversion HOT 23
- Division by zero HOT 2
- EPSG_AMERSFOORT_RD_NEW ⇒ EPSG_WGS_84 conversion no longer working HOT 6
- Can not convert from epsg:7415 to epsg:4979 HOT 2
- Retrieving Coordinate Systems to Display HOT 1
- deprecation warning php 8: Optional parameter ... declared before required parameter HOT 4
- Determine Point Type from CRS HOT 1
- Convert WGS 84 Coordinates to DHDN / 3-degree Gauss-Kruger zone 4 HOT 2
- Unable to perform conversion HOT 2
- Irish Grid error with valid coordinates HOT 3
- UnknownConversionException with ETRS89_TM35FIN_N_E HOT 5
- Failure to calculate long distances with vicenty HOT 2
- Possible rounding error when converting Geographic2D::EPSG_IRENET95 to Projected::EPSG_TM75_IRISH_GRID HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpcoord.