Feature row data access

Sep 29, 2011 at 6:38 AM

Hello

Is it possible to read data from a layer directly without an intersection query ?

To read data , I do this:

I open a layer...

VectorLayer myLayer = new SharpMap.Layers.VectorLayer("My layer");
string connStr = "xxxxx....
myLayer.DataSource = new SharpMap.Providers.xxx; <-whatever the provider

myMap.Layers.Add(myLayer);

I fill the DS


FeatureDataSet DS = new FeatureDataSet();
mylayer.ExecuteIntersectionQuery(my bounding box , DS);

and I read the DT in the DS.

Is it possible to access to 'internal' DS created during the 'myLayer.DataSource' without created a new DS ?. It seems possible because in the CustomTheme delagate there is the datarow with all the datas.

Eric

Coordinator
Sep 30, 2011 at 7:36 AM

you can use a GeometryFeatureProvider, filled with the data of your original datasource.

var pgProv = new SharpMap.Data.Providers.PostGis(....);

var ds = new FeatureDataSet();

pgProv.ExecuteFeatureQuery(pgProv.GetExtents(), ds);

var gpfProv = new GeometryFeatureProvider((FeatureDataTable)ds.Tables[0]);

(this has not seen a compiler, may need some modification)

Hth FObermaier

Sep 30, 2011 at 10:14 AM

Thanks for this input, I will try this afternoon..

one more question, I have this code which works well:

        Dim prov As SharpMap.Data.Providers.ShapeFile = New SharpMap.....
        prov.Open()

        Dim layWorld As SharpMap.Layers.VectorLayer = New SharpMap.Layers.VectorLayer("World", prov)
        MsgBox(prov.GetGeometryByID(1).AsText)
        MsgBox(prov.GetFeature(1).Item(0).ToString)

But if I use the SQLServer2008 provider the GetGeometryById works, but I get an error on GetFeature. I think this method is not implemented in the SQLServer2008 provider, is it true ?

Eric

Sep 30, 2011 at 12:40 PM

I 've try The GeometryFeatureProvider , but as I'm working with SQLServer, it's not possible.

Regarding the GetFeatureById, I use an new class whiwh inherits the SQLServer provider and change a line of code to work

Changing 

public FeatureDataRow GetFeature(uint rowId)  
       {  
           using (SqlConnection conn = new SqlConnection(_connectionString))  
           {  
               string strSQL = "select g.* , g." + GeometryColumn + ".STAsBinary() As sharpmap_tempgeometry from " + Table + " g WHERE " + ObjectIdColumn + "=" + rowId + "";  
               using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn))  
               {  
                   FeatureDataSet ds = new FeatureDataSet();  
                   conn.Open();  
                   adapter.Fill(ds);  
                   conn.Close();  

By

  public FeatureDataRow GetFeature(uint rowId)  
       {  
           using (SqlConnection conn = new SqlConnection(_connectionString))  
           {  
               string strSQL = "select g.* , g." + GeometryColumn + ".STAsBinary() As sharpmap_tempgeometry from " + Table + " g WHERE " + ObjectIdColumn + "=" + rowId + "";  
               using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn))  
               {  
     ----->        DataSet ds = new  DataSet();  
                   conn.Open();  
                   adapter.Fill(ds);  
                   conn.Close();  

Now it works, but I am not expert enought to know why...

Eric

Coordinator
Oct 1, 2011 at 6:56 PM

So we should fix the SqlServer2008 provider to make it work.

Coordinator
Oct 1, 2011 at 7:00 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.