Here the code I have written to a shapefile 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));

    function InsertMarkupFeatureToShp($propertyValues){
            $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:

    [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 shapefile using some other modified functions in the same file.

Any help please?


I have converted the target Coordinate System to the one as in existing shapefile. 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.

  • aww man, that's a lot of "->" haha. dont understand exactly what you're trying to do from your code, can you explain it in plain english? typically, i like to use gen2shp. it's dead simple to create the gen format then convert it to shp using that program. But i dont think that's what you're looking for?
    – janechii
    Jan 31 '12 at 16:09
  • :) I simply want to write new Point, Line or Polygon (whose co-ordinates are known), to an existing SHP file.
    – Kumar Kush
    Jan 31 '12 at 16:41
  • sorry I don't have any suggestions on your issue, but I'm currently having lots of trouble with the same setup (MapGuide OS 2.1, PHP, IIS 7.5). If you are feeling charitable I'd love to start a conversation about how you configured it
    – tomfumb
    Feb 13 '12 at 19:28
  • @tomfumb: Sorry! Was on long holidays. It's not about feeling charitable. I have went through the same you are facing. I am available for conversation and let's see, what we can do in your case.
    – Kumar Kush
    Feb 21 '12 at 5:32
  • @kush.impetus thanks very much for the offer but I had to give up on this approach due to time / budget issues. I think my problem was 64-bit IIS not talking properly to 32-bit ISAPI component in MapGuide. Eventually I just installed MapGuide with bundled Apache and set an IIS site to forward all requests to Apache. It's not ideal but it works and shows good performance. I also tried figuring this out in the MapGuide forum here: osgeo-org.1560.n6.nabble.com/…
    – tomfumb
    Feb 21 '12 at 17:59

Might be a bit late on this one but perhaps you are required to pass a MgResourceIdentifier to UpdateFeatures ?


$featureService->UpdateFeatures($featureSourceId, $commands, false);

might require changing to

$featureResSourceId = new MgResourceIdentifier($featureResSourceId);
$featureService->UpdateFeatures($featureResSourceId, $commands, false);

Don't forget that this will change your library dataset it may be read only depending on the current logged on user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.