Esempio n. 1
0
 static function CreateMarkupSchema($geomType = -1)
 {
     $markupSchema = new MgFeatureSchema();
     $markupSchema->SetName('MarkupSchema');
     if ($geomType == -1) {
         $geomType = MgFeatureGeometricType::Point | MgFeatureGeometricType::Curve | MgFeatureGeometricType::Surface;
     }
     $markupSchema->GetClasses()->Add(MarkupSchemaFactory::CreateMarkupClass($geomType));
     return $markupSchema;
 }
Esempio n. 2
0
 function CreateMarkup()
 {
     $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
     $featureService = $this->site->CreateService(MgServiceType::FeatureService);
     $map = new MgMap();
     $map->Open($resourceService, $this->args['MAPNAME']);
     $featureSourceId = "";
     $bUpdate = array_key_exists("EDITMARKUPLAYER", $this->args) && array_key_exists("MARKUPLAYERNAME", $this->args) && array_key_exists("EDITFEATURESOURCE", $this->args);
     // Create the Markup Feature Source if not updating
     if (!$bUpdate) {
         $markupName = $this->args["MARKUPNAME"];
         $this->UniqueMarkupName($markupName);
         $markupFsId = new MgResourceIdentifier($this->GetResourceIdPrefix() . $markupName . '.FeatureSource');
         //MARKUPGEOMTYPE is any constant from MgFeatureGeometricType
         if (array_key_exists("MARKUPGEOMTYPE", $this->args)) {
             $markupSchema = MarkupSchemaFactory::CreateMarkupSchema(intval($this->args["MARKUPGEOMTYPE"]));
         } else {
             $markupSchema = MarkupSchemaFactory::CreateMarkupSchema(-1);
         }
         $fsParams = new MgFileFeatureSourceParams($this->args["MARKUPFDOPROVIDER"], 'Default', $map->GetMapSRS(), $markupSchema);
         $featureService->CreateFeatureSource($markupFsId, $fsParams);
         $featureSourceId = $markupFsId->ToString();
     } else {
         $featureSourceId = $this->args["EDITFEATURESOURCE"];
     }
     //HACK: SQLite leaky abstraction (hard-coded schema name), SHP probably has some leaks of its own, so we can't assume MarkupSchema:Markup
     //as the class name interrogate our schema to figure it out
     $fsId = new MgResourceIdentifier($featureSourceId);
     $schemas = $featureService->DescribeSchema($fsId, "", null);
     $schema = $schemas->GetItem(0);
     $classes = $schema->GetClasses();
     $cls = $classes->GetItem(0);
     $className = $schema->GetName() . ":" . $cls->GetName();
     $markupLayerDefinition = $this->CreateMarkupLayerDefinitionContent($featureSourceId, $className);
     $byteSource = new MgByteSource($markupLayerDefinition, strlen($markupLayerDefinition));
     //Save to new resource or overwrite existing
     $layerDefId = new MgResourceIdentifier($bUpdate ? $this->args["EDITMARKUPLAYER"] : $this->GetResourceIdPrefix() . $markupName . '.LayerDefinition');
     $resourceService->SetResource($layerDefId, $byteSource->GetReader(), null);
     $cmds = new MgFeatureCommandCollection();
     //Register markup with markup registry if not updating
     if (!$bUpdate) {
         $props = new MgPropertyCollection();
         $props->Add(new MgStringProperty("ResourceId", $markupFsId->ToString()));
         $props->Add(new MgStringProperty("LayerDefinition", $layerDefId->ToString()));
         $props->Add(new MgStringProperty("Name", $layerDefId->GetName()));
         $props->Add(new MgStringProperty("FdoProvider", $this->args["MARKUPFDOPROVIDER"]));
         $props->Add(new MgInt32Property("GeometryTypes", intval($this->args["MARKUPGEOMTYPE"])));
         $insertCmd = new MgInsertFeatures("Default:MarkupRegistry", $props);
         $cmds->Add($insertCmd);
     }
     if ($cmds->GetCount() > 0) {
         $res = $featureService->UpdateFeatures($this->markupRegistryId, $cmds, false);
         MarkupManager::CleanupReaders($res);
     }
     return $layerDefId->ToString();
 }