Computes the distance between two coordinates.
.NET Syntax
Java Syntax
PHP Syntax
Example (PHP)
$coord1 is New York City, and $coord2 is Boston, Massachusetts. $distance is 361777.95418396 meters.
$geometryFactory = new MgGeometryFactory(); $coord1 = $geometryFactory->CreateCoordinateXY(-74.806394, 40.714169); $coord2 = $geometryFactory->CreateCoordinateXY(-71.061342, 42.355892); $distance = $coordSysMeasure->Getdistance($coord1, $coord2);
Example (C#)
using OSGeo.MapGuide; private MgCoordinateSystemMeasure geogCSMeasure; private MgGeometryFactory geometryFactory; private MgCoordinate geogCSXYCoord; private MgCoordinate geogCSX1Y1Coord; private double geogCSX = -160.101421317; private double geogCSY = 22.0234263273; private double geogCSX1 = -159.721535121256; private double geogCSY1 = 24.0028259520524; private double geogCSDistance = 2.0; private double distance; private double tolerance = 0.001; private Boolean isEquivalent; geometryFactory = new MgGeometryFactory(); geogCSXYCoord = geometryFactory.CreateCoordinateXY(geogCSX, geogCSY); geogCSX1Y1Coord = geometryFactory.CreateCoordinateXY(geogCSX1, geogCSY1); distance = geogCSMeasure.GetDistance(geogCSXYCoord, geogCSX1Y1Coord); // distance has the value of geogCSDistance isEquivalent = Math.Abs(distance - geogCSDistance) < tolerance;
Implements MgMeasure.
|