Come aggiungere informazioni

Coordinate Systems

    Indice (TOC)
    No headers

    A single map will often combine data from different sources, and the different sources may use different coordinate systems. The map has its own coordinate system, and any feature sources used in the map may have different coordinate systems. It is important for display and analysis that all locations are transformed to the same coordinate system.

    Note

    A coordinate system can also be called a spatial reference system (SRS) or a coordinate reference system (CRS). This guide uses the abbreviation SRS.

    Infrastructure Map Server supports three different types of coordinate system:

    • Arbitrary X-Y
    • Geographic, or latitude/longitude
    • Projected

    An MgCoordinateSystem object represents a coordinate system.

    Note

    You cannot transform between arbitrary X-Y coordinates and either geographic or projected coordinates.

    To create an MgCoordinateSystem object from an MgMap object,

    • Get the WKT representation of the map coordinate system, using MgMap::GetMapSRS().
    • Create an MgCoordinateSystem object, using MgCoordinateSystemFactory::Create().

    To create an MgCoordinateSystem object from a map layer,

    • Get the feature source for the layer.
    • Get the active spatial context for the feature source.
    • Convert the spatial context to a WKT.
    • Create an MgCoordinateSystem object from the WKT.

    To transform geometry from one coordinate system to another, create an MgCoordinateSystemTransform object using an MgCoordinateSystemFactory and the two coordinate systems. Apply this transform to the MgGeometry object.

    For example, if you have geometry representing a feature on a layer that uses one coordinate system, and you want to compare it to a feature on another layer that uses a different coordinate system, perform the following steps:

    $featureSource1 = $layer1->GetFeatureSourceId();
    $contexts1 = $featureService->GetSpatialContexts(
        $featureSource1, true);
    $contexts1->ReadNext();
    $srs1 = $contexts1->GetCoordinateSystemWkt();
     
    $featureSource2 = $layer2->GetFeatureSourceId();
    $contexts2 = $featureService->GetSpatialContexts(
        $featureSource2, true);
    $contexts2->ReadNext();
    $srs2 = $contexts2->GetCoordinateSystemWkt();
     
    $coordSysFactory = new MgCoordinateSystemFactory();
    $xform = $coordSysFactory->GetTransform($srs1, $srs2);
    $geometry1xform = $geometry1->Transform($xform);