Here the code I have written to a Shape file in MapGuide Open Source (in PHP running on IIS 7.5). The code is actually the modified class MarkupEditor (markupeditor.php) from the General Tracks (Gt) Example.
class MarkupEditor
{
private $args = null;
private $site = null;
function __construct($args){
$this->args = $args;
$this->site = new MgSiteConnection();
$this->site->Open(new MgUserInformation($args['SESSION']));
}
//
// Rest of the original code in the class
//
function AddPointToShp($featureID){
$geometryFactory = new MgGeometryFactory();
$agfWriter = new MgAgfReaderWriter();
$vertices = explode(",", $this->args['GEOMETRY']);
$coord = $geometryFactory->CreateCoordinateXY((double) $vertices[0], (double) $vertices[1]);
$point = $geometryFactory->CreatePoint($coord);
$point = $point->Transform($this->GetTransform());
$byteReader = $agfWriter->Write($point);
$propertyValues = new MgPropertyCollection();
$propertyValues->Add(new MgInt32Property("FeatId", $featureID));
$propertyValues->Add(new MgStringProperty("TYPE", "Breader"));
$propertyValues->Add(new MgStringProperty("DESC", "OCB'));
$propertyValues->Add(new MgGeometryProperty("Geometry", $byteReader));
$this->InsertMarkupFeatureToShp($propertyValues);
}
function InsertMarkupFeatureToShp($propertyValues){
try{
$featureService = $this->site->CreateService(MgServiceType::FeatureService);
$featureSourceId = $this->args['MARKUPLAYER'];
$commands = new MgFeatureCommandCollection();
$commands->Add(new MgInsertFeatures($this->args['OPENMAKUP'], $propertyValues));
$featureService->UpdateFeatures($featureSourceId, $commands, false);
}
catch (MgFeatureServiceException $ex){
echo '<b>MgFeatureServiceException : </b>'.$ex->GetExceptionMessage();
}
catch (MgInvalidArgumentException $ex){
echo '<b>MgInvalidArgumentException : </b>'.$ex->GetExceptionMessage();
}
catch (MgInvalidOperationException $ex){
echo '<b>MgInvalidOperationException : </b>'.$ex->GetExceptionMessage();
}
catch (MgFdoException $ex){
echo '<b>MgFdoException : </b>'.$ex->GetExceptionMessage();
}
}
}
The members of $args array passed in the constructor are:
Array
(
[MARKUPLAYER] => Library://DataStore/Data/Electrical/Breaker.FeatureSource
[SESSION] => 970bab06-4bd2-11e1-8000-000000000000_en_7F0000010AFC0AFB0AFA
[MAPNAME] => DataStore
[OPENMARKUP] => Default:breaker
[TGT] => 1
[POPUP] => 0
[GEOMETRY] => 1.5041909054501184,0.39827301781943014
)
$featureID in function AddPointToShp() is a numeric value. The code always stops execution at this line in function InsertMarkupFeatureToShp():
$featureService->UpdateFeatures($featureSourceId, $commands, false);
It does not even generate an exception so that I may be able to find out what is wrong.
Some posts on osgeo.org say that GT Example is used to write to SDF only. Where as, I am able to read any field from a desired SHP file using some other modified functions in the same file.
Any help please?
UPDATE
I have converted the target Coordinate System to the one as in existing SHP file. Now I get the MgInvalidArgumentException:
Invalid argument(s): [1] = " " The string cannot be empty.
Also I have tested $propertyValues [$propertyValues->GetCount()]. It returns the count as 4.