Giter VIP home page Giter VIP logo

phpcoord's Introduction

Taps mic🎤, is thing on?

Hello!

In my day job I help to make awesome applications that help to empower people and bring the world a little closer together. With my open source hat on, I create and/or maintain some libraries that I've needed that otherwise wouldn't exist 🦾 Check them out!

Tell me more

Sometimes in my career, I've looked for a library to complete what I imagined to be a fairly common task and to my surprise have found that one either doesn't exist or has been abandoned by its original author. This makes me sad, sometimes sad enough that I've decided to do something about it 😇.

Those libraries have now recorded over 2,500,000 downloads so I'm fairly confident that there are people out there using them to do all sorts of wonderful things.

An original creation because nothing else that I could find was suitable. When you try and get a pricing quote from a courier, you're asked for the width/length/depth of the box and it's weight. When you're working in e-commerce, weight is easy: you simply add up the individual weights of the all the stuff the customer ordered.

But the dimensions of the box(es)? That's....more complex.

If you have a latitude/longitude from GPS and just want to plot it on Google Maps or OpenStreetMap you probably don't need this. But if you have grid co-ordinates from a national mapping system e.g. the UK's Ordnance Survey and need to convert them, or have recently had your mind blown by discovering that the GPS latitude/longitude of a spot does not always agree with what national mapping authorities think it is then you need a conversion library. This project already existed when I first needed to do co-ordinate conversion, but was written for an old version of PHP. I polished it up, fixed some bugs and added some features.

Since then, the project has been completely rewritten and now supports over 6000 different coordinate systems, up from just 10 in previous versions.

My most recent pick-up, this is actually a fork of an abandoned fork of a long-abandoned project making me something of a 3rd-generation maintainer. This Behat extension allows you to generate code coverage reports when running a Behat test suite, just like those you can get when running PHPUnit.

In 2020 I did substantial work enhancing the code coverage statistics reported by PHPUnit's code coverage component, to (optionally) produce branch and path coverage alongside the traditional line-based metrics. As part of that work, I also contributed performance enhancements that make coverage generation quicker even when not using the new metrics.

An in-depth writeup of the changes is available to read here.

phpcoord's People

Contributors

caffme avatar dependabot[bot] avatar dvdoug avatar exussum12 avatar stevegoddard avatar teeedwards avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpcoord's Issues

Determine Point Type from CRS

Hi, first of all thanks so much for help on the other issue I opened!

I was wondering if there was a way to create a point using a CRS without having to define the Geometry type? For example, instead of
GeographicPoint::create we could do Point::create and instead pass in the CRS that the point is in. So if it was a Projected CRS it would automatically define it using Metres?

ITM to WGS84 error

Hi,

I am running into the following issue converting ITM into WGS84:

RuntimeException
Transform parameters not known for this ellipsoid

Here is the example:
$coord = new ITMRef(722304, 726059);
$newCoords = $coord->toLatLng()->toWGS84();

Any ideas for how to resolve this error?

Many thanks!

The use of round() at the end of toSixFigureString() in OSRef.php is incorrect

Hi,

I've just forked JStott's PHPCoord also. I'm not proposing any merge as I need to maintain compatibility with <5.3 PHP. This is just a heads up really.

I discovered that I was getting different values out of toSixFigureString(), when compared to the javascript version of the same library - and the javascript version gives the correct results.

I found the source of the error in the use of the 2 round() functions on the last few lines of the function - these were only introduced in version 2.3, having previously been floor(). Both of these should be floor(). I've been trying to contact the original developer to discuss why he made this change, but to no avail.

Here's a worked example:

$Easting = 439145
$Northing = 274187

This is a point in warwickshire, where the A45 meets the A445 (near Ryton-on-Dunsmore. Converting these by hand is simple. Chop off the 1st digit (they're taken care of by the letters in the reference - and they get converted properly by the function to SP) and the remaining digits give you the rest of the reference:

SP 39145 74187

To convert this to a six figure reference, chop off (don't round - that might put you in the wrong square) the last 2 digits of the easting and northing to give you:

SP 391 741

It's easy to see that rounding 74187 to 3 digits would give you 742 - which is not correct. But let's work through the function manually:

$100kmE = floor(439145/100000) = 4
$100kmN = floor(274187/100000) = 2

We'll assume the calculation of the 2 letters gives us SP. The digits after the SP are calculated thusly:

$e = $Easting - (100000 * $100kmE) = 439145 - 400000 = 39145 
$n = $Northing - (100000 * $100kmN) = 274187 - 200000 = 74187

So, the full 10 digit OS grid coordinate would be SP 39145 74187. And we're right so far.

To get the 6 digit grid, we just chop the last 2 digits off each of the easting and northing to give us SP 391 741. The correct function to use for this is floor(), not round():

floor(39145/100) = 391
floor(74187/100) = 741

Using round(), as in the broken version, gives us

round(39145/100) = 391 // (still OK)
round(74187/100) = 742 // (oops)

And therefore, the incorrect OS grid SP 391 742, which is what we'd been seeing from v2.3 of JStott's code.

This suggests to me that 50% of values calculated by this function will be wrong. If the 4th digit is >5, you'll get the wrong result. Otherwise, it'll be correct. Interesting to note that the examples in the original distribution are OK, perhaps by chance.

Sorry for the long windedness, but this has been driving me mad! And so many emails to the dev with no response, I feel like I've been banging my against the wall!

Let me know if you need any more clarification! And I hope this helps.

how do I use the Irish Grid Ref?

I am seeing error when I try to load IrishGridRef.php
PHP Fatal error: Class 'PHPCoord\TransverseMercator' not found in /home/site/public_html/PHPCoord-master/IrishGridRef.php on line 16

Consider immutable objects for a new version?

This library is very useful but I think the interface could be improved a little.

Say you have an instance of LatLng, if you call any method ->toXyz() the common expectation is to return an object/value in whatever the new format is. You wouldn't necessarily expect the original object to change. The problems are that now we have an object that can be in different states and it is hard to track what state that object is in, and so much easier to make errors. Compare toWGS84() with toOSRef() which does return a new object.

There is also potential confusion if you don't know how this is implemented. What happens if you call $latLng->toWGS84(); $latLng->toWGS84()? You have to look in the code to work out that this is safe.

Also, calling any of the methods toOSRef(), toUTMRef() and toITMRef() (while returning a new object) has the side-effect of converting the current object to another ellipsoid, and this is another potential source of bugs. There is nothing in the API to warn about this.

The PHP DateTime class went through a similar pain, PHP rather late in the day came out with DateTimeImmutable, after realising that working with mutable value objects can be clumsy. I think easier for me to link to something that explains better [or Google cache because main site seems to be down].

deprecation warning php 8: Optional parameter ... declared before required parameter

PHP Deprecated: Optional parameter $height declared before required parameter $crs is implicitly treated as a required parameter in <myfolder>/vendor/php-coord/php-coord/src/GeographicPoint.php on line 132

The source points to this function:

 public static function create(Angle $latitude, Angle $longitude, ?Length $height = null, Geographic $crs, ?DateTimeInterface $epoch = null): self
    {
        return new static($latitude, $longitude, $height, $crs, $epoch);
    }
        }

For completeness this is the function call I use, but I think this is caused by how the functions in the library are structured:

  $crs = Projected::fromSRID(Projected::EPSG_AMERSFOORT_RD_NEW);
  $from = ProjectedPoint::createFromEastingNorthing(
      new Metre($easting),
      new Metre($northing),
      $crs
  );
  
  $coords = (string) $from->convert(Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84), true);

Info about this warning:
https://php.watch/versions/8.0/deprecate-required-param-after-optional

Division by zero

$cos2SigmaM = cos($sigma) - 2 * sin($U1) * sin($U2) / $cosSqAlpha;

This doesn't have any protections against $cosSqAlpha being zero.

Here's an examples of what causes this to occur.

            $newPoint = GeographicPoint::create(
                Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84),
                new Degree($newLocation->latitude),
                new Degree($newLocation->longitude),
                null
            );

            $location->utm = $newPoint->asUTMPoint();

            $oldPoint = GeographicPoint::create(
                Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84),
                new Degree($oldLocation->latitude),
                new Degree($oldLocation->longitude),
                null
            );

            $distance = $oldPoint->calculateDistance($newPoint);

$newLocation is:

PHPCoord\GeographicPoint {#1841 ▼
  #latitude: PHPCoord\UnitOfMeasure\Angle\Degree {#1844 ▼
    -angle: 37.774929
  }
  #longitude: PHPCoord\UnitOfMeasure\Angle\Degree {#1842 ▼
    -angle: -122.419416
  }
  #height: null
  #crs: PHPCoord\CoordinateReferenceSystem\Geographic2D {#836 ▶}
  #epoch: null
  -maxChainDepth: 6
}

$oldLocation is:

PHPCoord\GeographicPoint {#1825 ▼
  #latitude: PHPCoord\UnitOfMeasure\Angle\Degree {#1830 ▼
    -angle: 37.774929
  }
  #longitude: PHPCoord\UnitOfMeasure\Angle\Degree {#1819 ▼
    -angle: -122.419416
  }
  #height: null
  #crs: PHPCoord\CoordinateReferenceSystem\Geographic2D {#836 ▶}
  #epoch: null
  -maxChainDepth: 6
}

Accuracy of Easting Northing to Lat Lng

With version 1, I could take an E/N, convert to Lat/Lng and plot on a Bing OS map with almost perfect accuarcy.

I have just moved to version 2 and points plotted appear to be 10-20m out. I'm plotting 1km grid squares which should line up perfectly with the blue OS grid lines (and did in version 1).

I.e.

Version 1.1.2

$var_grid_ref_osref = new OSRef($var_easting, $var_northing); 
$var_grid_ref_lat_lng = $var_grid_ref_osref->toLatLng();
$var_grid_ref_lat_lng->OSGB36ToWGS84();

"easting": ​322000, "northing": ​241000, "lat": ​52.06187, "lng": ​-3.13916
version1

Version 2.0.1

$var_grid_ref_osref = new OSRef($var_easting, $var_northing);
$var_grid_ref_lat_lng = $var_grid_ref_osref->toLatLng();
$var_grid_ref_lat_lng->toWGS84();

"easting": ​322000, "northing": ​241000, "lat": ​52.06193, "lng": ​-3.13935
version2

If I plot the points in ArcMap (without the toWGS84 conversion) they are perfect. So the issue seems to be with the toWGS84 function. To confirm this, I've checked and both version 1 and 2 return the same lat/lng values for this example if you take off the WGS84 conversion (52.06146,-3.13788). But after the OSGB36ToWGS84() in 1.2.1 or toWGS84() in 2.0.1 conversions I get different answers.

Is this an issue or am i doing something wrong?

Thanks
Steve

Namespace

Please consider using namespaces. Thank you

License requirments of the EPSG dataset

In the documentation here you make reference to using a EPSG dataset but not where its from, the license requirements of it & under what conditions the library interacts with it.

Investigating the website https://epsg.org/download-dataset.html seems to make matters worse because you need a login to access the data set?

Its a concern because data sets like the ordnance survey come with very little onwards requirements but datasets licensed under other licenses (often ones from openstreetmaps / maptiller) can require you to release your database / data as public.

Can you shed some light into this please? 😄

Can not convert from epsg:7415 to epsg:4979

This code does not work:

$inputCrs = Compound::fromSRID('urn:ogc:def:crs:EPSG::7415'); // RD new + NAP
$outputCrs = Geographic3D::fromSRID('urn:ogc:def:crs:EPSG::4979'); // WGS 3D

$input = [
    108360.8790,
    415757.2745,
    258.0057,
];

$horizontalPoint = ProjectedPoint::createFromEastingNorthing(
    $inputCrs->getHorizontal(),
    new Metre($input[0]),
    new Metre($input[1]),
);
$verticalPoint = VerticalPoint::create($inputCrs->getVertical(), new Metre($input[2]));
$inputPoint = CompoundPoint::create($inputCrs, $horizontalPoint, $verticalPoint);

return $inputPoint->convert($outputCrs);

It produces the error: Unable to perform conversion, please file a bug if you think this is incorrect.

With a workaround it is possible:

$inputCrs = Compound::fromSRID('urn:ogc:def:crs:EPSG::7415'); // RD new + NAP
$outputCrs = Geographic3D::fromSRID('urn:ogc:def:crs:EPSG::4979'); // WGS 3D

$input = [
    108360.8790,
    415757.2745,
    258.0057,
];

$horizontalPoint = ProjectedPoint::createFromEastingNorthing(
    $inputCrs->getHorizontal(),
    new Metre($input[0]),
    new Metre($input[1]),
);
$verticalPoint = VerticalPoint::create($inputCrs->getVertical(), new Metre($input[2]));
$inputPoint = CompoundPoint::create($inputCrs, $horizontalPoint, $verticalPoint);

// convert the horizontal part to ETRS89 -> geograpic 2d so we have lat/lon
$etrs89 = $inputPoint->getHorizontalPoint()->convert(
    Geographic2D::fromSRID('urn:ogc:def:crs:EPSG::4258') // ETRS89
);

$elipsoidHeight = $inputPoint->getVerticalPoint()->getHeight()->add(
    (new GTXETRS89NAPProvider)->provideGrid()->getHeightAdjustment($etrs89)
);

$wgs84 = $etrs89->convert($outputCrs);

$outputPoint = GeographicPoint::create(
    $outputCrs,
    $wgs84->getLatitude(),
    $wgs84->getLongitude(),
    $elipsoidHeight,
);

return $outputPoint;

Is there any way to do this easier?

We are dealing with a lot of 3d coordinates (either geographic or projected, either ellipsoid or gravity), for which we know the 3 components and the accompanying CRS.

Ideally, I can call a method where I provide both inputs, and the rest is magic.

For reference, using proj:

$ echo 108360.8790 415757.2745 258.0057 | cs2cs -d 9 epsg:7415 epsg:4979
51.728601274	4.712120126 301.798133706

Retrieving Coordinate Systems to Display

Hi! Are there any built-in methods to query the stored Coordinate System, for example if a user populates a search box in the front-end it can then retrieve all Coordinate Systems matching the input. Or even to populate a drop down list so a user can select a Coordinate System to project from.

UnknownConversionException with ETRS89_TM35FIN_N_E

Hi,

I am writing an API that generates random WGS84 coordinates in unit tests. These are then converted to ETRS89_TM35FIN_N_E. The limits for the coordinates are 60-70 and 20-30. These should be well within the bounds of ETRS89_TM35FIN_N_E. However with the random coordinate generation, I am sometimes getting an the exception below even though everything should be fine.

PHPCoord\Exception\UnknownConversionException Unable to perform conversion, please file a bug if you think this is incorrect.

WGS84 bounds for ETRS89_TM35FIN_N_E:
-16.1 32.88
40.18 84.73

$from = GeographicPoint::create(
    Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84),
    new Degree(68.754962),
    new Degree(23.258243),
    null
);

$toCRS = Projected::fromSRID(Projected::EPSG_ETRS89_TM35FIN_N_E);
$point = $from->convert($toCRS);

Convert WGS 84 Coordinates to DHDN / 3-degree Gauss-Kruger zone 4

Sadly, I'm not deep enough in the topic but tried to convert GPS Coordinates urn:ogc:def:crs:EPSG::4326 to easting & northing in urn:ogc:def:crs:EPSG::31468.

The following Table should be the correct result:

  • UTM: 32U 534800, 5534668
  • GAUSS_KRUGER_ZONE_4: 4319680, 5539360
  • WGS 84 (lat/lon): 49.96335, 9.48521

I run into a UnknownConversionException when running this code:

$geographic = GeographicPoint::create(
	Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84),
	new Degree(49.96335),
	new Degree(9.48521),
	NULL
);

$projected = $geographic->convert(Projected::fromSRID(Projected::EPSG_DHDN_3_DEGREE_GAUSS_KRUGER_ZONE_4));

what am i doing wrong?

Load ten figure UK grid refs

Hi,

I'm looking to convert 10 figure grid references to latitude/longitude pairs. I've used Jonathan's getOSRefFromSixFigureReference() and then $os6x->toLatLng() for many years, but I'm now looking for more accuracy.

I noticed that you have a fromSixFigureReference(), would you consider adding one for Ten?

Best wishes,

James

I experience a memory leak

I experiment some kind of memory leak when converting coordinates for multiple times.

Do you see any issues with this code?

PHP 8.0.6
PHPCoord 4.3
Datapack Europe 1.0

require_once __DIR__ . '/vendor/autoload.php';

use PHPCoord\CoordinateReferenceSystem\Projected;
use PHPCoord\CoordinateReferenceSystem\Geographic2D;
use PHPCoord\ProjectedPoint;
use PHPCoord\UnitOfMeasure\Length\Metre;

function convertCoord($easting, $northing)
{
    $crs = Projected::fromSRID(Projected::EPSG_AMERSFOORT_RD_NEW);
    $from = ProjectedPoint::createFromEastingNorthing(
        new Metre($easting),
        new Metre($northing),
        $crs
    );

    $coords = (string) $from->convert(Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84));
    $coords = explode(",", trim($coords, '()'));

    $lonlat[] = floatval($coords[1]);
    $lonlat[] = floatval($coords[0]);

    return $lonlat;
}

function getPointLonLat()
{
    // of course below will be variables, but I experience the issue even calling this function multiple times.
    $x = 94904.701655864;
    $y = 467709.4147013;

    $lonlat = convertCoord($x, $y);

    return $lonlat;
}

Accuracy of EPSG_AMERSFOORT_RD_NEW ⇒ EPSG_WGS_84 conversion

I must say first of all I'm quite impressed by this library. Great job on it.

Now, I've noticed that I'm not the first one who has a question about the accuracy of the conversion, and I appreciate how hard of a problem this is. So with that out of the way.

I've got the following code:

$point = ProjectedPoint::createFromEastingNorthing(
    new Metre(86058.2205),
    new Metre(445832.8025),
    Projected::fromSRID(Projected::EPSG_AMERSFOORT_RD_NEW)
);

$gpsPoint = $point->convert(Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84));

// Result:
(51.997030373929, 4.383346111941)

// Expected (taken from Google maps):
(51.996591, 4.3831851)

This turns out to be almost 100m off, about 60/70m to the east and 10/20m to the north. The location comes from official government sources, but they only provide the coordinates in EPSG:28992. Though I do expect the data to be quite accurate.

Edit: made a mistake with google map coords.

Accuracy of Lat/Lng to Easting/Northing

I'm having issues with the accuracy of the conversion between a given set of Lat Lng coordinates and their equivalent Easting / Northing's.

Example
Lat: 51.57166, Lng: -3.21813 is a bus station in Caerphilly map

Using
$LatLng = new LatLng(51.57166, -3.21813, 0, RefEll::airy1830()); $OSRef = $LatLng->toOSRef();

Returns
[x:protected] => 311261 [y:protected] => 185622
Which is around 80 meters away map

toWGS84() function

Probably a complete noob question so I do apologise but when I do $latLng = $OSRef->toLatLng(); it returns an object, but when I do $latLng = $OSRef->toLatLng()->toWGS84(); it returns NULL

Any pointers greatly appreciated.

Easting / Northing to LatLon Accuracy

Hi,

I have been using this class to convert a bunch of Easting / Northing, I found when checking the converted values against a map that the LatLng was slightly off.

When the results where compared against a online tool for I noticed that the only difference was the length of the results.

To test this I adjusted LatLng.php

$this->lat = round($lat, 5);
$this->lng = round($lng, 5);
to
$this->lat = round($lat, 13);
$this->lng = round($lng, 13);

This changes moved the point on the map by about 100 meters and was more accurate.

Does the class support getting LatLng out in a longer format?

Thanks for the great work!

Irish Grid error with valid coordinates

Good morning, first of all thank you for this great Lib! Really helpful.

I'm having trouble converting to the Irish Grid (EPSG_TM75_IRISH_GRID) in some valid coordinates (Unable to perform conversion, please file a bug if you think this is incorrect)

        $from = GeographicPoint::create(
            new Degree(54.040039),
            new Degree(-6.1846184),
            null,
            Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84),
        );

        $toOSGrid = Projected::fromSRID(Projected::EPSG_TM75_IRISH_GRID);
        $to = $from->convert($toOSGrid);

According to https://irish.gridreferencefinder.com/?gr=J1896211603%7C54.04003822493_s__c__s_-6.1846160888672%7C1&t=54.04003822493%20%2C%20-6.1846160888672&v=r this is valid. If the latitude is below 54 it works perfectly.

We're on PHP 7.4, so if any possible fix could be ported to the ^4 branch it'd be amazing!

Unable to perform conversion

I have quite a lot Estonian addresses and their x, y coordinates. And I'm trying to get from them lat, long coordinates. But for some reason around 4000 addresses throws error: "Unable to perform conversion, please file a bug if you think this is incorrect".

Here's my code example:

 $srcPoint = ProjectedPoint::createFromEastingNorthing(
      new Metre($x_coordinate), // example: 738480.02
      new Metre($y_coordinate), // example: 6588088.08
      Projected::fromSRID(Projected::EPSG_ESTONIAN_COORDINATE_SYSTEM_OF_1997)
  );
  $toCRS = Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84);
  $dstPoint = $srcPoint->convert($toCRS);

  $latitude = $dstPoint->getLatitude();
  $longitude = $dstPoint->getLongitude();

I'm using version 4.7.0, because this project is stuck with old php 7 version.
I tried online x, y transformation and that should work just fine: https://epsg.io/transform#s_srs=3301&t_srs=4326&x=738480.0200000&y=6588088.0800000

Possibility to map UTM coordinates to a different zone?

Hi,

question: is it possible with this library to map a set of UTM coordinates to a neighboring zone?

Long-winded explanation: for a project we are required to support a maps provider who, because of reasons, expects all coordinates for markers to be in UTM zone 32N.
But when I, for example, drop in the LatLng for a spot in Berlin and convert to UTM, I get coordinates for zone 33N, which is correct, but on that map results in a marker nowhere near Berlin.
Is it, with this library, somehow possible to convert UTM coordinates between zones?

Best regards
Marc-Oliver

Irish Grid to WGS84 problems

Hi,

There appears to be an issue with the conversion from Irish Grid to WGS84.
Given the following code:

$coord = new IrishGridRef(322364.659, 226034.372);
$newCoords = $coord->toLatLng()->toWGS84();

I would expect to see the following Lat & Lng:

lat: 53.270753
lng: -6.1663770

Instead I get the following:

lat: 53.27059696595
lng: -6.1670186227361

This is over 40 meters off what is expected.
As reference I am using https://irish.gridreferencefinder.com/ which appears to accurately plot all of the positions I am entering with Irish Grid and ITM.

Any ideas what could be the problem here?

Many thanks!

Lat/long from eastings & northings v4

Hey, nice library - I susspect im being stupid but alot of the existing code / references online point to old versions, reading the docs you provide an example but its not clear to me what todo in the following situation;

How do you arrive at the lat/long pair that would match the output of online tools? (at least the ones returned by a UK based google search?)

Take the following example from the ordnance survey data and using this link for geocoding;

Postcode Eastings Northings
"BH1 1AA" 409722 92041

If you encode the the postcode using the link above you arrive at 50.727612, -1.861430, if you use the code copied from the documentation here

<?php
require __DIR__ . "/vendor/autoload.php";
use PHPCoord\CoordinateReferenceSystem\Projected;
use PHPCoord\ProjectedPoint;
use PHPCoord\UTMPoint;
use PHPCoord\UnitOfMeasure\Length\Metre;
use PHPCoord\CoordinateReferenceSystem\Geographic2D;

$from = ProjectedPoint::createFromEastingNorthing(
    new Metre(409722),
    new Metre(92041),
    Projected::fromSRID(Projected::EPSG_OSGB36_BRITISH_NATIONAL_GRID)
);
$toCRS = Projected::fromSRID(Projected::EPSG_WGS_84_UTM_ZONE_31N);
$to = $from->convert($toCRS);
echo $to;

You don't get a similar result, Ive experimented with a few different constants from the Projected class but with no luck, am I using the wrong ones?

EPSG_AMERSFOORT_RD_NEW ⇒ EPSG_WGS_84 conversion no longer working

I updated to the new version of the library, and updated the datapack-europe to 1.2. I had to adapt the code to fit the changed parameter order. But I still get an UnknownConversionException.

Here's the code (essentially all that changed is that param 3 is now param 1):

         $centerPoint = ProjectedPoint::createFromEastingNorthing(
            Projected::fromSRID(Projected::EPSG_AMERSFOORT_RD_NEW),
            $easting,
            $northing,
        );

        return $centerPoint->convert(Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84));

Do I need to change something else or is this a regression?

Uncaught Error: Class 'PHPCoord\CoordinateReferenceSystem\Projected' not found

I get a PHP error when running a simple example. Maybe I misunderstand namespaces, but I'm following the examples.
Uncaught Error: Class 'PHPCoord\CoordinateReferenceSystem\Projected' not found

Reproduce:

step 1:
composer require php-coord/php-coord

step 2:
create php file based on this example:
https://www.phpcoord.net/en/stable/creating_points_projected.html

<?php
require_once __DIR__ . '/vendor/autoload.php';

use PHPCoord\CoordinateReferenceSystem\Projected;
use PHPCoord\ProjectedPoint;
use PHPCoord\UnitOfMeasure\Length\Metre;

// Nelson's Column in British National Grid (unknown date), traditional arguments
$crs = Projected::fromSRID(Projected::EPSG_OSGB36_BRITISH_NATIONAL_GRID);
$point = ProjectedPoint::createFromEastingNorthing(
    new Metre(530017),
    new Metre(180419),
    $crs
);
?>

Feature request: support Irish grid

As far as I can tell (I don't have much experience with GIS) this would be very similar or the same as the OSRef, just with a few different constants. I've been trying to follow along here to implement this:

https://www.ordnancesurvey.co.uk/docs/support/guide-coordinate-systems-great-britain.pdf

though so far pretty confused by the various standards, and statements like "this is not a transformation", which begs the question, "what is and isn't a transformation?".

Library upgrade assistance

Hi,

Wondering if you can help. I'm a long time user and need to upgrade as the old version is no longer compatible with PHP 8.

It looks like the library has grown a few arms and legs since and I'm a bit confused with all the classes and datum so please excuse my ignorance. This is how far I managed to get:

------ Old usage:

require "phpcoord-2.3.php";

$os = new OSRef(199800, 554200);
$ll = $os->toLatLng();
echo $ll->lat . " " . $ll->lng;

------ New attempt:

require "vendor/autoload.php";

use PHPCoord\CoordinateReferenceSystem\Projected;
use PHPCoord\ProjectedPoint;
use PHPCoord\UnitOfMeasure\Length\Metre;
use PHPCoord\CoordinateReferenceSystem\Geographic2D;

$from = ProjectedPoint::createFromEastingNorthing(
new Metre(554200),
new Metre(199800),
Projected::fromSRID(Projected::EPSG_OSGB_1936_BRITISH_NATIONAL_GRID)
);

$to = $from->asGeographicPoint();
echo $to->getLatitude() . " " . $to->getLongitude();

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.