VDS Technologies

 

Cannot Select and Edit Shapes in Postgres Layer

6/13/2014 10:13:48 AM
Total Posts 11

Cannot Select and Edit Shapes in Postgres Layer

Hi,

I am trying to edit the_geom field of a spatial table Postgres Table. I am able to add the layer but I am unable to select any shape in the event map_InfoTool. 

I add a Postgres Layer as follows:

    void AddDatabaseLayer()
    {
        PostgreSqlLayer pgLayer = new PostgreSqlLayer("Devart.Data.Universal", "provider=PostgreSQL;User Id=user;Password=password;Host=localhost;Database=gisdata", "areas", "the_geom");
        pgLayer.FieldList = "ID, DESCRIPTION"; 
        pgLayer.ShapeType = ShapeType.Polygon;        
        AspMap.Layer layer = map.AddLayer(pgLayer);

        if (layer == null)
            return;

        layer.Name = "polygons";
        layer.Opacity = 0.4;
        layer.ShowLabels = true;
        layer.LabelStyle = LabelStyle.PolygonCenter;
        layer.LabelField = "DESCRIPTION";
        layer.LabelFont.Name = "Verdana";
        layer.LabelFont.Size = 12;
        layer.LabelFont.Color = Color.White;
        layer.LabelFont.OutlineColor = Color.Black;
        layer.LabelFont.Outline = true;
        layer.Symbol.Size = 1;
        layer.Symbol.FillColor = Color.LightGreen;
        layer.Symbol.LineColor = Color.Green;
    }

 

I try to get a shape as follows:

    protected void map_InfoTool(object sender, InfoToolEventArgs e)
    {
        RestoreState();
        Recordset rs = map.Identify(e.InfoPoint, 10);        
        if (rs.EOF || rs.Layer.Name != "polygons") return;
        map.EditShape(rs.Shape);             
        ViewState["shapeID"] = rs["ID"];
        shapeTitle.Text = rs["TITLE"].ToString();
        remove.Visible = true;
        cancel.Visible = true;
        operation.Text = "Edit shape:";
    } 

 

However I never get past this line:  if (rs.EOF || rs.Layer.Name != "polygons") return; 

because the ResultSet never has features in the Postgres layer.

I can see the layer and the coordinate system is  WGS_84. But i cannot select a shape. But when I do not add fields then I can select features but I am unable to edit but when I add fields in this line: pgLayer.FieldList = "ID, DESCRIPTION"; then I cannot select the layer features. 

How do I select a shape in the Postgres layer?

Thank you.

 

6/14/2014 12:41:02 AM
MVP
Total Posts 323

Re: Cannot Select and Edit Shapes in Postgres Layer

Do you able to see the labels from the layer on the map (from the DESCRIPTION field)? If yes, we need to look at this database file, please send us a backup file using the form at http://www.vdstech.com/ctsupport.aspx or support@vdstech.com

6/16/2014 6:14:23 AM
Total Posts 11

Re: Cannot Select and Edit Shapes in Postgres Layer

Yes I see the labels.

I now made a copy of the table using the command:

select * into gis_data_1 from gis_data

And it works now! However I cannot update the record using the rs.Update() command. I get the error:

"An exception of type 'System.Exception' occurred in AspMapNET.dll but was not handled in user code. Additional information: Update requires a valid UpdateCommand when passed DataRow collection with modified rows."

This is how I connect to the db. 

PostgreSqlLayer pgLayer = new PostgreSqlLayer("Devart.Data.Universal", "provider=PostgreSQL;User Id=user;Password=password;Host=localhost;Database=gis_data_1", "areas", "the_geom");

But I cannot run the rs.Update().

Thank You

 

 

 

6/16/2014 6:39:39 AM
MVP
Total Posts 323

Re: Cannot Select and Edit Shapes in Postgres Layer

As described in the ''Editing Spatial and Attribute Data/Editing records" topic in the documentation:
A database table must have a primary key field, which will be automatically used by AspMap to update records. The key field must be specified in the FieldList property. If the table does not have a primary key field, an exception will be thrown.

Seems as the ID field is not a primary key field.

6/17/2014 1:34:52 AM
Total Posts 11

Re: Cannot Select and Edit Shapes in Postgres Layer

Thank you. There is a unique id field but I had not added the PK constraint. I added it and was able to save the changes. 

What I notice though is that I am unable to move the shape as in the sample in LocationEditorApp where once can move the point anywhere and then click save to persist the change.  How does one edit not just the points of the polygon but physically move the  entire shape?

Thank you

6/17/2014 6:09:15 AM
MVP
Total Posts 323

Re: Cannot Select and Edit Shapes in Postgres Layer

Moving the entire shape is not supported currently.

6/18/2014 7:40:15 AM
Total Posts 11

Re: Cannot Select and Edit Shapes in Postgres Layer

Thank you. Do you perhaps have a rough idea when this will be supported?

6/18/2014 7:44:15 AM
MVP
Total Posts 323

Re: Cannot Select and Edit Shapes in Postgres Layer

Yes, it will be supported in next releases.