Accessing spatial data programmatically

Via the HTTP API

Spatial data access via the HTTP API is read-only. When the UNLVSpatial module is enabled, its HTTP API documentation will appear in the dmBridge HTTP API documentation and will not be duplicated here.

Via the PHP API

Loading spatial data

The following example will retrieve an object's spatial data.

$col = DMCollectionFactory::getCollection("/sample");
$obj = DMObjectFactory::getObject($col, 5);

try {
    if ($obj->getSpatialModelClassName() == "UNLVSpatialRectObject") {
        echo $obj->getSpatialNorthLat();
        echo $obj->getSpatialSouthLat();
        echo $obj->getSpatialWestLong();
        echo $obj->getSpatialEastLong();
    } else { // it must be a point
        echo $obj->getSpatialLat();
        echo $obj->getSpatialLong();
} catch (DMNoSuchMethodException $e) {
    echo "This object has no spatial metadata.";

Querying spatial data

Spatial data can be easily retrieved using a UNLVSpatialQuery. An example:

$example_obj = new UNLVSpatialRectObject();

$term = new UNLVSpatialQueryTerm();

$query = new UNLVSpatialQuery();

$results = $query->getSearchResults();

UNLVSpatialQuery has additional methods for pagination, specifying search collections, and more. See the PHP API documentation for more information.

Adding and updating spatial data

The recommended way of adding spatial data is to instantiate a new UNLVSpatialObject; associate it with an existing DMObject; and persist it, as in the following example:

// Update a rectangle object
$collection = DMCollectionFactory::getCollection("/whatever");
$obj = DMObjectFactory::getObject($collection, 123);

$sp_obj = new UNLVSpatialRectObject();


// Update a point object
$collection = DMCollectionFactory::getCollection("/whatever");
$obj = DMObjectFactory::getObject($collection, 456);

$sp_obj = new UNLVSpatialPointObject();


The call to updateObject() will insert the data if it does not already exist, and update it if it does.

Deleting spatial data

To delete spatial data, first we retrieve the DMObject whose spatial data we want to delete, then we "delete" it:

$collection = DMCollectionFactory::getCollection("/whatever");
$obj = DMObjectFactory::getObject($collection, 123);


The call to deleteObject() does not actually delete the given object -- only its spatial metadata.