Comments (6)
Err... wait a moment. The coordinates I had might be "in bounds" in terms of the entire rectangle used but still be out of bounds somehow. I made a small script to draw a 2d map with "working" coordinates:
php8.1 -r 'echo"0 400.000\n",$l="+".str_repeat("-",81)."+\n";for($y=650000;$y>=250000;$y-=10000){echo"|";for($x=0;$x<=400000;$x+=5000){require"vendor/autoload.php";try{$w=PHPCoord\ProjectedPoint::createFromEastingNorthing(PHPCoord\CoordinateReferenceSystem\Projected::fromSRID(PHPCoord\CoordinateReferenceSystem\Projected::EPSG_AMERSFOORT_RD_NEW),new PHPCoord\UnitOfMeasure\Length\Metre($x),new PHPCoord\UnitOfMeasure\Length\Metre($y))->convert(PHPCoord\CoordinateReferenceSystem\Geographic2D::fromSRID(PHPCoord\CoordinateReferenceSystem\Geographic2D::EPSG_WGS_84));}catch(Throwable$e){$w=0;}echo$w?"8":" ";}echo"| ",(int)($y/1000),".000\n";}echo$l;'
0 400.000
+---------------------------------------------------------------------------------+
| | 650.000
| | 640.000
| 88888888888888888888888888888888888888888888888888888 | 630.000
| 88888888888888888888888888888888888888888888888888888 | 620.000
| 88888888888888888888888888888888888888888888888888888 | 610.000
| 888888888888888888888888888888888888888888888888888888 | 600.000
| 888888888888888888888888888888888888888888888888888888 | 590.000
| 888888888888888888888888888888888888888888888888888888 | 580.000
| 888888888888888888888888888888888888888888888888888888 | 570.000
| 888888888888888888888888888888888888888888888888888888 | 560.000
| 888888888888888888888888888888888888888888888888888888 | 550.000
| 888888888888888888888888888888888888888888888888888888 | 540.000
| 888888888888888888888888888888888888888888888888888888 | 530.000
| 888888888888888888888888888888888888888888888888888888 | 520.000
| 888888888888888888888888888888888888888888888888888888 | 510.000
| 888888888888888888888888888888888888888888888888888888 | 500.000
| 888888888888888888888888888888888888888888888888888888 | 490.000
| 888888888888888888888888888888888888888888888888888888 | 480.000
| 888888888888888888888888888888888888888888888888888888 | 470.000
| 888888888888888888888888888888888888888888888888888888 | 460.000
| 8888888888888888888888888888888888888888888888888888888 | 450.000
| 88888888888888888888888888888888888888888888888888888888 | 440.000
| 88888888888888888888888888888888888888888888888888888888 | 430.000
| 88888888888888888888888888888888888888888888888888888888 | 420.000
| 88888888888888888888888888888888888888888888888888888888 | 410.000
| 88888888888888888888888888888888888888888888888888888888 | 400.000
| 88888888888888888888888888888888888888888888888888888888 | 390.000
| 88888888888888888888888888888888888888888888888888888888 | 380.000
| 88888888888888888888888888888888888888888888888888888888 | 370.000
| 88888888888888888888888888888888888888888888888888888888 | 360.000
| 88888888888888888888888888888888888888888888888888888888 | 350.000
| 88888888888888888888888888888888888888888888888888888888 | 340.000
| 88888888888888888888888888888888888888888888888888888888 | 330.000
| 88888888888888888888888888888888888888888888888888888888 | 320.000
| 88888888888888888888888888888888888888888888888888888888 | 310.000
| | 300.000
| | 290.000
| | 280.000
| | 270.000
| | 260.000
| | 250.000
+---------------------------------------------------------------------------------+
So my (completely fictional) 100.000;100.000 clearly falls out of the "working" area.
So I did some more debugging based on this... the original coordinates work. However, if I install datapack-europe
, things change.
0 400.000
+---------------------------------------------------------------------------------+
| | 650.000
| 888 888888 | 640.000
| 88888888888888888888888 | 630.000
| 888888888888888888888888888888 | 620.000
| 888888888888888888888888888888888 | 610.000
| 8888888888888888888888888888888888888 | 600.000
| 888888888888888888888888888888888888888 | 590.000
| 8888888888888888888888888888888888888888 | 580.000
| 8888888888888888888888888888888888888888 | 570.000
| 8888888888888888888888888888888888888888 | 560.000
| 888888888888888888888888888888888888888 | 550.000
| 88888888888888888888888888888888888888 | 540.000
| 8888888888888888888888888888888888 8 | 530.000
| 88888888888888888888888888888888888 | 520.000
| 888888888888888888888888888888888888 | 510.000
| 88888888888888888888888888888888888888888 | 500.000
| 888888888888888888888888888888888888888888 | 490.000
| 888888888888888888888888888888888888888888 | 480.000
| 888888888888888888888888888888888888888888 | 470.000
| 8888888888888888888888888888888888888888888 | 460.000
| 88888888888888888888888888888888888888888888 | 450.000
| 8888888888888888888888888888888888888888888 | 440.000
| 888888888888888888888888888888888888888888888 | 430.000
| 88888888888888888888888888888888888888 888 | 420.000
| 88888888888888888888888888888888888888 | 410.000
|888888888888888888888888888888888888888888 | 400.000
|8888888888888888888888888888888888888888888 | 390.000
| 8888888888888888888888888888888888888888888 | 380.000
| 88888888888888 8 8888888888888888888 | 370.000
| 888888888888 88888888888888888 | 360.000
| 888 88888888 | 350.000
| 8888 | 340.000
| 8 | 330.000
| 8888 | 320.000
| 888888 | 310.000
| 88888 | 300.000
| | 290.000
| | 280.000
| | 270.000
| | 260.000
| | 250.000
+---------------------------------------------------------------------------------+
It now has the shape of the country. I guess that is because the data is based on actual measurements on (mostly?) land and within the country's jurisdiction.
So now back to my original point, it does actually work without the datapack, and is broken when I install the datapack. It just so happens to be right at the narrowest part of the country, in Limburg. Here are the coordinates: 185750 easting, 330750 northing
from phpcoord.
Hi @ameenross
Can you share the particular easting/northing you're using here? It should work, there's an example in the test suite at https://github.com/dvdoug/PHPCoord/blob/v5.1.0/tests/CoordinateOperation/AutoConversionTest.php#L283 that's doing basically what you've got above (the example is from your #39 actually)
from phpcoord.
Yesterday I had something in the south-east, numbers didn't look strange. Today I entered 100000 for both easting and northing, and I got the same error.
So just for the avoidance of doubt, I ran a snippet on CLI that should prevent any interference from other code, error handlers or whatever:
php8.1 -r 'require"vendor/autoload.php";print_r(PHPCoord\ProjectedPoint::createFromEastingNorthing(PHPCoord\CoordinateReferenceSystem\Projected::fromS
RID(PHPCoord\CoordinateReferenceSystem\Projected::EPSG_AMERSFOORT_RD_NEW),new PHPCoord\UnitOfMeasure\Length\Metre(100000),new PHPCoord\UnitOfMeasure\Length\Metre(100000))->convert(PHPCoord\C
oordinateReferenceSystem\Geographic2D::fromSRID(PHPCoord\CoordinateReferenceSystem\Geographic2D::EPSG_WGS_84)));'
PHP Fatal error: Uncaught PHPCoord\Exception\UnknownConversionException: Unable to perform conversion, please file a bug if you think this is incorrect in vendor/
php-coord/php-coord/src/CoordinateOperation/AutoConversion.php:81
Stack trace:
#0 vendor/php-coord/php-coord/src/CoordinateOperation/AutoConversion.php(57): PHPCoord\ProjectedPoint->findOperationPath()
#1 vendor/php-coord/php-coord/src/ProjectedPoint.php(248): PHPCoord\ProjectedPoint->autoConvert()
#2 Command line code(1): PHPCoord\ProjectedPoint->convert()
#3 {main}
thrown in vendor/php-coord/php-coord/src/CoordinateOperation/AutoConversion.php on line 81
from phpcoord.
I even tried it just now in a completely fresh project. Composer require PHPCoord (without the datapack), run above snippet, same result.
from phpcoord.
Hmm, this is a complex one.
The datapack does install more accurate country shape data, see https://phpcoord.net/en/stable/coordinate_conversions_easy.html#boundaries and https://phpcoord.net/en/stable/coordinate_conversions_easy.html#extents
In this specific case, the although quite detailed, the polygon from EPSG (https://epsg.org/extent_1275/Netherlands-onshore.html) does miss out a small sliver of the country close to your point of interest.
That's normal/expected though, and PHPCoord compensates by slightly enlarging the original polygon to include a safety buffer. Here though, your particular point is actually inside the original polygon, so it looks like PHPCoord is accidentally shrinking the validity area instead of expanding it.
This part of the country is south-east of the polygon centre, so it seems the PHPCoord version of the boundary is being shifted further south-east to "expand" it which given the shape of the Netherlands is the wrong direction for this particular point which should instead be shifted north-west. I'll need to research a proper algorithm for polygon expansion, the naive one I've implemented clearly doesn't handle these kinds of shapes.
In the meantime, you can pass the true
as the second parameter of the convert()
method to skip the boundary checking entirely.
from phpcoord.
Very interesting. Thanks for the clarification. Yes, I forgot to mention that, but I already found out about the workaround.
I would think that SVG renderers have such an algorithm. One that even works for bezier curves, not merely polygons. Maybe you can just straight up port some function from Inkscape or whatever to PHP.
from phpcoord.
Related Issues (20)
- toWGS84() function HOT 1
- Accuracy of Lat/Lng to Easting/Northing HOT 2
- Load ten figure UK grid refs HOT 7
- Possibility to map UTM coordinates to a different zone? HOT 13
- ITM to WGS84 error
- Irish Grid to WGS84 problems HOT 6
- Library upgrade assistance HOT 3
- 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
- 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
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.