Exemple #1
0
     //echo "/* setting combinedFilter:".$combinedFilter."*/";
     $queryOptions->SetFilter($combinedFilter);
 }
 if ($spatialFilter !== false) {
     $spatialContext = $featureService->GetSpatialContexts($featureResId, true);
     $srsLayerWkt = false;
     if ($spatialContext != null && $spatialContext->ReadNext() != null) {
         $srsLayerWkt = $spatialContext->GetCoordinateSystemWkt();
         /* skip this layer if the srs is empty */
     }
     if ($srsLayerWkt == null) {
         $srsLayerWkt = $srsDefMap;
     }
     /* create a coordinate system from the layer's SRS wkt */
     $srsLayer = $srsFactory->Create($srsLayerWkt);
     $verMajor = subStr(GetSiteVersion(), 0, 1);
     if ($verMajor == '1') {
         $srsXform = new MgCoordinateSystemTransform($srsMap, $srsLayer);
     } else {
         $srsXform = $srsFactory->GetTransform($srsMap, $srsLayer);
     }
     $wktRW = new MgWktReaderWriter();
     $geom = $wktRW->Read($spatialFilter, $srsXform);
     $queryOptions->SetSpatialFilter($featureGeometryName, $geom, $variant);
 }
 /* select the features */
 try {
     $featureReader = $featureService->SelectFeatures($featureResId, $class, $queryOptions);
 } catch (MgException $e) {
     echo "ERROR2: " . $e->GetExceptionMessage() . "\n";
     echo $e->GetDetails() . "\n";
Exemple #2
0
 *****************************************************************************/
include 'Common.php';
if (InitializationErrorOccurred()) {
    //If initialization error occurred, then the error JSON has already been written
    //so just exit.
    exit;
}
include 'Utilities.php';
include '../../../common/php/Utilities.php';
try {
    $site = $siteConnection->GetSite();
    $sessionId = $site->CreateSession();
    $user->SetMgSessionId($sessionId);
    header('Content-type: application/json');
    header('X-JSON: true');
    $result = null;
    $result->sessionId = $sessionId;
    $result->userName = $username;
    $result->siteVersion = GetSiteVersion();
    $result->acceptLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
    echo var2json($result);
    /* start a php session in the web tier as well, using same session id */
    session_id(str_replace('_', '-', $sessionId));
    session_start();
    $_SESSION['username'] = $username;
    loadFusionConfig();
} catch (MgException $e) {
    echo "ERROR: " . $e->GetExceptionMessage() . "n";
    echo $e->GetDetails() . "n";
    echo $e->GetStackTrace() . "n";
}
Exemple #3
0
function getUtmWkt($lon, $lat)
{
    $siteVersion = explode(".", GetSiteVersion());
    if ((int) $siteVersion[0] > 2 || (int) $siteVersion[0] == 2 && (int) $siteVersion[1] > 0) {
        //v2.1.x or greater
        $epsg42003 = 'PROJCS["WORLD-MERCATOR",GEOGCS["LL84",DATUM["WGS84",SPHEROID["WGS84",6378137.000,298.25722293]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Mercator_2SP"],PARAMETER["false_easting",0.000],PARAMETER["false_northing",0.000],PARAMETER["standard_parallel_1",0.00000000000000],PARAMETER["central_meridian",0.00000000000000],UNIT["Meter",1.00000000000000]]';
    } else {
        $epsg42003 = "PROJCS[\"WGS 84 / Auto Orthographic\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Decimal_Degree\",0.0174532925199433]],PROJECTION[\"Orthographic\"],PARAMETER[\"central_meridian\",%.3e],PARAMETER[\"latitude_of_origin\",%.3e],UNIT[\"Meter\",1]]";
    }
    return sprintf($epsg42003, $lon, $lat);
}
Exemple #4
0
/**
  keep all the attributes of selected features in an array
*/
function BuildSelectionArray($featureReader, $layerName, $properties, $bComputedProperties, $srsLayer, $bNeedsTransform, $layerObj)
{
    $agf = new MgAgfReaderWriter();
    $srsFactory = new MgCoordinateSystemFactory();
    $properties->{$layerName}->propertynames = array();
    $properties->{$layerName}->propertyvalues = array();
    $properties->{$layerName}->propertytypes = array();
    $properties->{$layerName}->numelements = 0;
    $properties->{$layerName}->values = array();
    $properties->{$layerName}->metadatanames = array();
    array_push($properties->{$layerName}->metadatanames, 'dimension');
    array_push($properties->{$layerName}->metadatanames, 'bbox');
    array_push($properties->{$layerName}->metadatanames, 'center');
    array_push($properties->{$layerName}->metadatanames, 'area');
    array_push($properties->{$layerName}->metadatanames, 'length');
    $mappings = $_SESSION['property_mappings'][$layerObj->GetObjectId()];
    foreach ($mappings as $name => $value) {
        $propType = $featureReader->GetPropertyType($name);
        array_push($properties->{$layerName}->propertynames, $name);
        array_push($properties->{$layerName}->propertyvalues, $value);
        array_push($properties->{$layerName}->propertytypes, $propType);
    }
    $srsTarget = null;
    $srsXform = null;
    while ($featureReader->ReadNext()) {
        $properties->{$layerName}->values[$properties->{$layerName}->numelements] = array();
        $properties->{$layerName}->metadata[$properties->{$layerName}->numelements] = array();
        $dimension = '';
        $bbox = '';
        $center = '';
        $area = '';
        $length = '';
        if ($bComputedProperties) {
            $classDef = $featureReader->GetClassDefinition();
            $geomName = $classDef->GetDefaultGeometryPropertyName();
            if ($geomName != '') {
                $geomByteReader = $featureReader->GetGeometry($geomName);
                /* is this needed? We declare one outside the loop too?*/
                $agf = new MgAgfReaderWriter();
                $geom = $agf->Read($geomByteReader);
                $envelope = $geom->Envelope();
                $ll = $envelope->GetLowerLeftCoordinate();
                $ur = $envelope->GetUpperRightCoordinate();
                $bbox = $ll->GetX() . ',' . $ll->GetY() . ',' . $ur->GetX() . ',' . $ur->GetY();
                $centroid = $geom->GetCentroid()->GetCoordinate();
                $center = $centroid->GetX() . ',' . $centroid->GetY();
                /* 0 = point, 1 = curve, 2 = surface */
                $dimension = $geom->GetDimension();
                if ($geom->GetDimension() > 0) {
                    if ($bNeedsTransform && $srsTarget == null && $srsXform == null) {
                        $srsTarget = $srsFactory->Create(getUtmWkt($centroid->GetX(), $centroid->GetY()));
                        $verMajor = subStr(GetSiteVersion(), 0, 1);
                        if ($verMajor == '1') {
                            $srsXform = new MgCoordinateSystemTransform($srsLayer, $srsTarget);
                        } else {
                            $srsXform = $srsFactory->GetTransform($srsLayer, $srsTarget);
                        }
                    }
                    if ($srsXform != null) {
                        try {
                            $ageom = $geom->Transform($srsXform);
                            $geom = $ageom;
                        } catch (MgException $ee) {
                            echo "/*transform exception:";
                            echo "ERROR: " . $ee->GetMessage() . "\n";
                            echo $ee->GetDetails() . "\n*/";
                        }
                    }
                    if ($geom->GetDimension() > 1) {
                        $area = $geom->GetArea();
                    }
                    if ($geom->GetDimension() > 0) {
                        $length = $geom->GetLength();
                    }
                }
            }
        }
        array_push($properties->{$layerName}->metadata[$properties->{$layerName}->numelements], $dimension);
        array_push($properties->{$layerName}->metadata[$properties->{$layerName}->numelements], $bbox);
        array_push($properties->{$layerName}->metadata[$properties->{$layerName}->numelements], $center);
        array_push($properties->{$layerName}->metadata[$properties->{$layerName}->numelements], $area);
        array_push($properties->{$layerName}->metadata[$properties->{$layerName}->numelements], $length);
        $numproperties = count($properties->{$layerName}->propertynames);
        for ($j = 0; $j < $numproperties; $j++) {
            $propname = $properties->{$layerName}->propertynames[$j];
            $value = GetPropertyValueFromFeatReader($featureReader, $properties->{$layerName}->propertytypes[$j], $propname);
            $value = htmlentities($value, ENT_COMPAT, 'UTF-8');
            $value = addslashes($value);
            $value = preg_replace("/\r?\n/", "<br>", $value);
            array_push($properties->{$layerName}->values[$properties->{$layerName}->numelements], $value);
            //$properties->$layerName->values[$properties->$layerName->numelements][$propname] = $value;
        }
        $properties->{$layerName}->numelements = $properties->{$layerName}->numelements + 1;
    }
    return $properties;
}