Beispiel #1
0
/**
  keep all the attributes of selected features in an array
*/
function BuildSelectionArray($featureReader, $layerName, $properties, $bComputedProperties, $srsLayer, $bNeedsTransform, $layerObj, $isLayerNameEncoded)
{
    $agf = new MgAgfReaderWriter();
    $srsFactory = new MgCoordinateSystemFactory();
    if ($isLayerNameEncoded) {
        // Add prefix to avoid layer name beginning with number
        // So $isLayerNameEncoded should be true when and only when the properties will be stored in session
        $layerName = GetEncodedLayerName($layerName);
    }
    $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');
    if (isset($_SESSION)) {
        $mappings = $_SESSION['property_mappings'][$layerObj->GetObjectId()];
        foreach ((array) $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) {
                    //conver the geometry to UTM auto so that local measurements
                    //are accruate in meters
                    if ($bNeedsTransform && $srsTarget == null && $srsXform == null) {
                        $wkt = getUtmWkt($centroid->GetX(), $centroid->GetY());
                        $srsTarget = $srsFactory->Create($wkt);
                        $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->GetExceptionMessage() . "\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;
}
Beispiel #2
0
 /* if number of layers and number of startcount should be the same */
 if (count($aStartCount) > 0 && count($aLayers) != count($aStartCount)) {
     echo "error : number of layers and number of startcount should be the same";
     exit;
 }
 $properties = $_SESSION['selection_array'];
 $aSelectedLayers = $properties->layers;
 if (count($aSelectedLayers) > 0) {
     $result->extents = NULL;
     $result->extents->minx = $properties->extents->minx;
     $result->extents->miny = $properties->extents->miny;
     $result->extents->maxx = $properties->extents->maxx;
     $result->extents->maxy = $properties->extents->maxy;
     for ($i = 0; $i < count($aSelectedLayers); $i++) {
         $layerName = $aSelectedLayers[$i];
         $layerNameInProperties = GetEncodedLayerName($layerName);
         if (($bAllLayers || in_array($layerName, $aLayers)) && isset($properties->{$layerNameInProperties}) && $properties->{$layerNameInProperties}->numelements > 0) {
             array_push($result->layers, $layerName);
             $result->{$layerName}->propertynames = $properties->{$layerNameInProperties}->propertynames;
             $result->{$layerName}->propertyvalues = $properties->{$layerNameInProperties}->propertyvalues;
             $result->{$layerName}->propertytypes = $properties->{$layerNameInProperties}->propertytypes;
             $result->{$layerName}->metadatanames = $properties->{$layerNameInProperties}->metadatanames;
             /*if start and count are given, validate them. If valid return the valid elements.
               if not return all elements. */
             $start = -1;
             $count = -1;
             if (count($aStartCount) > 0) {
                 for ($j = 0; $j < count($aLayers); $j++) {
                     if ($aLayers[$j] == $layerName) {
                         $aIndiceCount = split(':', $aStartCount[$j]);
                         if (count($aIndiceCount) == 2) {