Giter VIP home page Giter VIP logo

Comments (6)

ameenross avatar ameenross commented on June 11, 2024 1

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.

dvdoug avatar dvdoug commented on June 11, 2024

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.

ameenross avatar ameenross commented on June 11, 2024

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.

ameenross avatar ameenross commented on June 11, 2024

I even tried it just now in a completely fresh project. Composer require PHPCoord (without the datapack), run above snippet, same result.

from phpcoord.

dvdoug avatar dvdoug commented on June 11, 2024

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.

image

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.

image

In the meantime, you can pass the true as the second parameter of the convert() method to skip the boundary checking entirely.

from phpcoord.

ameenross avatar ameenross commented on June 11, 2024

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)

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.