예제 #1
0
파일: Utilities.php 프로젝트: kanbang/Colt
function CreateFeatureSource($map, $dataSourceId, $featureName, $featureService, $geomType, $schema = "")
{
    //create feature source
    $classDef = new MgClassDefinition();
    $classDef->SetName($featureName);
    $classDef->SetDescription($featureName . " feature layer");
    $classDef->SetDefaultGeometryPropertyName("GEOM");
    //Set KEY property
    $prop = new MgDataPropertyDefinition("KEY");
    $prop->SetDataType(MgPropertyType::Int32);
    $prop->SetAutoGeneration(true);
    $prop->SetReadOnly(true);
    $classDef->GetIdentityProperties()->Add($prop);
    $classDef->GetProperties()->Add($prop);
    $prop = new MgGeometricPropertyDefinition("GEOM");
    $prop->SetGeometryTypes($geomType);
    $classDef->GetProperties()->Add($prop);
    //Create the schema
    if ($schema == "") {
        $schema = "DrawToolSchema";
    }
    $schema = new MgFeatureSchema($schema, "Temporary draw layer schema");
    $schema->GetClasses()->Add($classDef);
    //finally, creation of the feature source
    $params = new MgCreateSdfParams("LatLong", GetMapSRS($map), $schema);
    $featureService->CreateFeatureSource($dataSourceId, $params);
}
예제 #2
0
 function ClassDefinition()
 {
     $classDef = new MgClassDefinition();
     $classDef->SetName("StringKey");
     $classDef->SetDescription("String key feature class");
     $classDef->SetDefaultGeometryPropertyName("GEOM");
     // Set key property
     $prop = new MgDataPropertyDefinition("SKEY");
     $prop->SetDataType(MgPropertyType::String);
     $prop->SetAutoGeneration(false);
     $classDef->GetIdentityProperties()->Add($prop);
     $classDef->GetProperties()->Add($prop);
     $prop = new MgDataPropertyDefinition("NAME");
     $prop->SetDataType(MgPropertyType::String);
     $classDef->GetProperties()->Add($prop);
     // Set geometry property
     $prop = new MgGeometricPropertyDefinition("GEOM");
     $prop->SetGeometryTypes(4);
     $classDef->GetProperties()->Add($prop);
     return $classDef;
 }
 public function CreateFeatureSource($resId, $inputFormat)
 {
     //Check for unsupported representations
     $fmt = $this->ValidateRepresentation($inputFormat, array("xml", "json"));
     $sessionId = "";
     if ($resId->GetRepositoryType() == MgRepositoryType::Session) {
         $sessionId = $resId->GetRepositoryName();
     }
     $mimeType = $this->GetMimeTypeForFormat($fmt);
     $this->EnsureAuthenticationForSite($sessionId, false, $mimeType);
     $siteConn = new MgSiteConnection();
     $siteConn->Open($this->userInfo);
     $site = $siteConn->GetSite();
     $this->VerifyWhitelist($resId->ToString(), $mimeType, "CREATEFEATURESOURCE", $fmt, $site, $this->userName);
     $this->EnsureAuthenticationForSite($sessionId);
     $siteConn = new MgSiteConnection();
     $siteConn->Open($this->userInfo);
     $featSvc = $siteConn->CreateService(MgServiceType::FeatureService);
     if ($fmt == "json") {
         $body = $this->app->request->getBody();
         $json = json_decode($body);
         if ($json == NULL) {
             throw new Exception($this->app->localizer->getText("E_MALFORMED_JSON_BODY"));
         }
     } else {
         $body = $this->app->request->getBody();
         $jsonStr = MgUtils::Xml2Json($body);
         $json = json_decode($jsonStr);
     }
     if (!isset($json->FeatureSourceParams)) {
         throw new Exception($this->app->localizer->getText("E_MALFORMED_JSON_BODY"));
     }
     $fsParams = $json->FeatureSourceParams;
     if (!isset($fsParams->File)) {
         throw new Exception($this->app->localizer->getText("E_MALFORMED_JSON_BODY"));
     }
     if (!isset($fsParams->SpatialContext)) {
         throw new Exception($this->app->localizer->getText("E_MALFORMED_JSON_BODY"));
     }
     if (!isset($fsParams->FeatureSchema)) {
         throw new Exception($this->app->localizer->getText("E_MALFORMED_JSON_BODY"));
     }
     $mkParams = new MgFileFeatureSourceParams();
     if (isset($fsParams->File->Provider)) {
         $mkParams->SetProviderName($fsParams->File->Provider);
     }
     if (isset($fsParams->File->FileName)) {
         $mkParams->SetFileName($fsParams->File->FileName);
     }
     if (isset($fsParams->SpatialContext->Name)) {
         $mkParams->SetSpatialContextName($fsParams->SpatialContext->Name);
     }
     if (isset($fsParams->SpatialContext->Description)) {
         $mkParams->SetSpatialContextDescription($fsParams->SpatialContext->Description);
     }
     if (isset($fsParams->SpatialContext->CoordinateSystem)) {
         $mkParams->SetCoordinateSystemWkt($fsParams->SpatialContext->CoordinateSystem);
     }
     if (isset($fsParams->SpatialContext->XYTolerance)) {
         $mkParams->SetXYTolerance($fsParams->SpatialContext->XYTolerance);
     }
     if (isset($fsParams->SpatialContext->ZTolerance)) {
         $mkParams->SetZTolerance($fsParams->SpatialContext->ZTolerance);
     }
     $mkSchema = $fsParams->FeatureSchema;
     $schema = new MgFeatureSchema();
     if (isset($mkSchema->Name)) {
         $schema->SetName($mkSchema->Name);
     }
     if (isset($mkSchema->Description)) {
         $schema->SetDescription($mkSchema->Description);
     }
     $classes = $schema->GetClasses();
     foreach ($mkSchema->ClassDefinition as $mkClass) {
         $cls = new MgClassDefinition();
         if (isset($mkClass->Name)) {
             $cls->SetName($mkClass->Name);
         }
         if (isset($mkClass->Description)) {
             $cls->SetDescription($mkClass->Description);
         }
         if (isset($mkClass->DefaultGeometryPropertyName)) {
             $cls->SetDefaultGeometryPropertyName($mkClass->DefaultGeometryPropertyName);
         }
         $clsProps = $cls->GetProperties();
         $idProps = $cls->GetIdentityProperties();
         foreach ($mkClass->PropertyDefinition as $propDef) {
             if (isset($propDef->PropertyType)) {
                 $mkProp = null;
                 switch ($propDef->PropertyType) {
                     case MgFeaturePropertyType::DataProperty:
                         $mkProp = new MgDataPropertyDefinition($propDef->Name);
                         if (isset($propDef->DataType)) {
                             $mkProp->SetDataType($propDef->DataType);
                         }
                         if (isset($propDef->Nullable)) {
                             $mkProp->SetNullable($propDef->Nullable);
                         }
                         if (isset($propDef->IsAutoGenerated)) {
                             $mkProp->SetAutoGeneration($propDef->IsAutoGenerated);
                         }
                         if (isset($propDef->DefaultValue)) {
                             $mkProp->SetDefaultValue($propDef->DefaultValue);
                         }
                         if (isset($propDef->Length)) {
                             $mkProp->SetLength($propDef->Length);
                         }
                         if (isset($propDef->Precision)) {
                             $mkProp->SetPrecision($propDef->Precision);
                         }
                         if (isset($propDef->Scale)) {
                             $mkProp->SetScale($propDef->Scale);
                         }
                         break;
                     case MgFeaturePropertyType::GeometricProperty:
                         $mkProp = new MgGeometricPropertyDefinition($propDef->Name);
                         if (isset($propDef->GeometryTypes)) {
                             $mkProp->SetGeometryTypes($propDef->GeometryTypes);
                         }
                         if (isset($propDef->HasElevation)) {
                             $mkProp->SetHasElevation($propDef->HasElevation);
                         }
                         if (isset($propDef->HasMeasure)) {
                             $mkProp->SetHasMeasure($propDef->HasMeasure);
                         }
                         if (isset($propDef->SpatialContextAssociation)) {
                             $mkProp->SetSpatialContextAssociation($propDef->SpatialContextAssociation);
                         }
                         break;
                     default:
                         throw new Exception($this->app->localizer->getText("E_UNSUPPORTED_PROPERTY_TYPE"));
                 }
                 if ($mkProp != null) {
                     if (isset($propDef->Description)) {
                         $mkProp->SetDescription($propDef->Description);
                     }
                     if (isset($propDef->ReadOnly)) {
                         $mkProp->SetReadOnly($propDef->ReadOnly);
                     }
                     $clsProps->Add($mkProp);
                     if (isset($propDef->IsIdentity) && $propDef->IsIdentity == true) {
                         $idProps->Add($mkProp);
                     }
                 }
             }
         }
         if (isset($mkClass->DefaultGeometryPropertyName)) {
             $cls->SetDefaultGeometryPropertyName($mkClass->DefaultGeometryPropertyName);
         }
         $classes->Add($cls);
     }
     $mkParams->SetFeatureSchema($schema);
     try {
         $featSvc->CreateFeatureSource($resId, $mkParams);
     } catch (MgException $ex) {
         $this->OnException($ex, $mimeType);
     }
 }
예제 #4
0
파일: draw_line.php 프로젝트: kanbang/Colt
 $layerLegendLabel = "New Lines";
 $groupName = "Analysis";
 $groupLegendLabel = "Analysis";
 //---------------------------------------------------//
 // Does the temporary feature source already exist?
 // If not, create it
 $featureSourceName = "Session:{$sessionId}//TemporaryLines.FeatureSource";
 $resourceIdentifier = new MgResourceIdentifier($featureSourceName);
 $featureSourceExists = DoesResourceExist($resourceIdentifier, $resourceService);
 if (!$featureSourceExists) {
     // Create a temporary feature source to draw the lines on
     // Create a feature class definition for the new feature
     // source
     $classDefinition = new MgClassDefinition();
     $classDefinition->SetName("Lines");
     $classDefinition->SetDescription("Lines to display.");
     $geometryPropertyName = "SHPGEOM";
     $classDefinition->SetDefaultGeometryPropertyName($geometryPropertyName);
     // Create an identify property
     $identityProperty = new MgDataPropertyDefinition("KEY");
     $identityProperty->SetDataType(MgPropertyType::Int32);
     $identityProperty->SetAutoGeneration(true);
     $identityProperty->SetReadOnly(true);
     // Add the identity property to the class definition
     $classDefinition->GetIdentityProperties()->Add($identityProperty);
     $classDefinition->GetProperties()->Add($identityProperty);
     // Create a name property
     $nameProperty = new MgDataPropertyDefinition("NAME");
     $nameProperty->SetDataType(MgPropertyType::String);
     // Add the name property to the class definition
     $classDefinition->GetProperties()->Add($nameProperty);
예제 #5
0
파일: createSdf.php 프로젝트: kanbang/Colt
    $site = new MgSiteConnection();
    $cred = new MgUserInformation();
    $cred->SetMgUsernamePassword("Administrator", "admin");
    $cred->SetLocale("en");
    $site->Open($cred);
    $svc = $site->CreateService(MgServiceType::FeatureService);
} catch (MgException $exc) {
    echo $exc->GetExceptionMessage() . "\n";
    echo $exc->GetDetails() . "\n";
    return;
}
echo "Created Services\n";
// Create class definition for new feature  class
$classDef = new MgClassDefinition();
$classDef->SetName("Buffer");
$classDef->SetDescription("Feature class for buffer layer");
$classDef->SetDefaultGeometryPropertyName("GEOM");
// Set key property
$prop = new MgDataPropertyDefinition("KEY");
$prop->SetDataType(MgPropertyType::Int32);
$prop->SetAutoGeneration(true);
$prop->SetReadOnly(true);
$classDef->GetIdentityProperties()->Add($prop);
$classDef->GetProperties()->Add($prop);
$prop = new MgDataPropertyDefinition("NAME");
$prop->SetDataType(MgPropertyType::String);
$classDef->GetProperties()->Add($prop);
// Set geometry property
$prop = new MgGeometricPropertyDefinition("GEOM");
$prop->SetGeometryTypes(MgFeatureGeometricType::Surface);
$classDef->GetProperties()->Add($prop);
예제 #6
0
파일: buffer.php 프로젝트: kanbang/Colt
 $mapSrsUnits = "";
 $srsMap = $srsFactory->Create($srsDefMap);
 $arbitraryMapSrs = $srsMap->GetType() == MgCoordinateSystemType::Arbitrary;
 if ($arbitraryMapSrs) {
     $mapSrsUnits = $srsMap->GetUnits();
 }
 //Create/Modify layer definition
 $layerDefContent = BuildLayerDefinitionContent();
 $resourceSrvc->SetResource($layerDefId, $layerDefContent, null);
 if ($layer == null) {
     $newBuffer = true;
     //Targetting a new layer. create a data source for it
     //
     $classDef = new MgClassDefinition();
     $classDef->SetName($featureName);
     $classDef->SetDescription(GetLocalizedString("BUFFERCLASSDESCR", $locale));
     $classDef->SetDefaultGeometryPropertyName("GEOM");
     //Set KEY property
     $prop = new MgDataPropertyDefinition("KEY");
     $prop->SetDataType(MgPropertyType::Int32);
     $prop->SetAutoGeneration(true);
     $prop->SetReadOnly(true);
     $classDef->GetIdentityProperties()->Add($prop);
     $classDef->GetProperties()->Add($prop);
     //Set ID property.
     $prop = new MgDataPropertyDefinition("ID");
     $prop->SetDataType(MgPropertyType::Int32);
     $classDef->GetProperties()->Add($prop);
     //Set geometry property
     $prop = new MgGeometricPropertyDefinition("GEOM");
     //$prop->SetGeometryTypes(MgFeatureGeometricType::mfgtSurface); //TODO use the constant when exposed
예제 #7
0
파일: measure.php 프로젝트: kanbang/Colt
 //create the line string geometry representing this segment
 //
 $geomFactory = new MgGeometryFactory();
 $coordinates = new MgCoordinateCollection();
 $coordinates->Add($geomFactory->CreateCoordinateXY($x1, $y1));
 $coordinates->Add($geomFactory->CreateCoordinateXY($x2, $y2));
 $geom = $geomFactory->CreateLineString($coordinates);
 if ($segId == 1) {
     //first segment
     //
     if (!DataSourceExists($resourceSrvc, $dataSourceId)) {
         //create feature source
         //
         $classDef = new MgClassDefinition();
         $classDef->SetName($featureName);
         $classDef->SetDescription(GetLocalizedString("MEASUREFEATURECLASS", $locale));
         $classDef->SetDefaultGeometryPropertyName("GEOM");
         //Set KEY property
         $prop = new MgDataPropertyDefinition("KEY");
         $prop->SetDataType(MgPropertyType::Int32);
         $prop->SetAutoGeneration(true);
         $prop->SetReadOnly(true);
         $classDef->GetIdentityProperties()->Add($prop);
         $classDef->GetProperties()->Add($prop);
         //Set PARTIAL property. Hold the distance for this segment
         $prop = new MgDataPropertyDefinition("PARTIAL");
         $prop->SetDataType(MgPropertyType::Double);
         $classDef->GetProperties()->Add($prop);
         //Set TOTAL property. Hold the total distance up to this segment, including it
         $prop = new MgDataPropertyDefinition("TOTAL");
         $prop->SetDataType(MgPropertyType::Double);
 $siteConnection = new MgSiteConnection();
 $siteConnection->Open($userInfo);
 $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService);
 $featureService = $siteConnection->CreateService(MgServiceType::FeatureService);
 //---------------------------------------------------//
 // Open the map
 $map = new MgMap($siteConnection);
 $map->Open($mapName);
 //---------------------------------------------------//
 // Create a feature source with point data.
 // (The Sheboygan sample data does not contain such data,
 // so we'll create it.)
 // Create a feature class definition for the new feature source
 $classDefinition = new MgClassDefinition();
 $classDefinition->SetName("Points");
 $classDefinition->SetDescription("Feature class with point data.");
 $classDefinition->SetDefaultGeometryPropertyName("GEOM");
 // Create an identify property
 $identityProperty = new MgDataPropertyDefinition("KEY");
 $identityProperty->SetDataType(MgPropertyType::Int32);
 $identityProperty->SetAutoGeneration(true);
 $identityProperty->SetReadOnly(true);
 // Add the identity property to the class definition
 $classDefinition->GetIdentityProperties()->Add($identityProperty);
 $classDefinition->GetProperties()->Add($identityProperty);
 // Create a name property
 $nameProperty = new MgDataPropertyDefinition("NAME");
 $nameProperty->SetDataType(MgPropertyType::String);
 // Add the name property to the class definition
 $classDefinition->GetProperties()->Add($nameProperty);
 // Create a geometry property