SDF Example for Insert , Update, Read

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

SDF Example for Insert , Update, Read

raghulan
Hello Ppl,

 I am look for some some example code in C# to do the following..

I have a SDF file (created using Civil3D 2012) - which has a feature class "Pipes"
and the inside I got few proeprties such as radius, style name, etc.

There are more than one pipe (pipe names - p1, p2, p3, etc)

-------------------------------------------------------------
I am a new bee...help with this please.

I want to insert some values in the selected scheme, selected feature class("pipes") and then identifying the row (which is pipe name = "p2") nad then in the column (Pipe radius)...
how do i do it using iinsert and iupdate command ...also how do i read a specific value

please help me with some code snippets..
-Raghulan Gowthaman
Senior civil BIM Consultant
Reply | Threaded
Open this post in threaded view
|

Re: SDF Example for Insert , Update, Read

Greg Boone
A simple SDF ApplySchema/Insert test (C#) can be found here:

        http://trac.osgeo.org/fdo/browser/trunk/Providers/SDF/Managed/UnitTest/ProviderTests/SchemaTests.cs

You can find other C# provider tests (for SHP access) in:

        http://trac.osgeo.org/fdo/browser/trunk/Providers/SHP/Managed/UnitTest/ProviderTests

I know they illustrate SHP file access, not SDF, but by reading these tests you can find the correct command patterns to use.

Getting back to SDF, you can find a number of C++ tests here:

http://trac.osgeo.org/fdo/browser/trunk/Providers/SDF/Src/UnitTest

Following the C# examples above, you can see how the C++ tests can be converted to C#.

Greg


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of raghulan
Sent: Tuesday, October 09, 2012 11:11 PM
To: [hidden email]
Subject: [fdo-users] SDF Example for Insert , Update, Read

Hello Ppl,

 I am look for some some example code in C# to do the following..

I have a SDF file (created using Civil3D 2012) - which has a feature class "Pipes"
and the inside I got few proeprties such as radius, style name, etc.

There are more than one pipe (pipe names - p1, p2, p3, etc)

-------------------------------------------------------------
I am a new bee...help with this please.

I want to insert some values in the selected scheme, selected feature
class("pipes") and then identifying the row (which is pipe name = "p2") nad then in the column (Pipe radius)...
how do i do it using iinsert and iupdate command ...also how do i read a specific value

please help me with some code snippets..



--
View this message in context: http://osgeo-org.1560.n6.nabble.com/SDF-Example-for-Insert-Update-Read-tp5007560.html
Sent from the FDO Users mailing list archive at Nabble.com.
_______________________________________________
fdo-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fdo-users
_______________________________________________
fdo-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fdo-users
Reply | Threaded
Open this post in threaded view
|

Re: SDF Example for Insert , Update, Read

raghulan
Greg,

 Thanks for the help..I made some progress...
here is my code snippet..please let me know where I am getting it wrong...(Once I get it right sure i want to post some tutorials for basics)


My schema Structure (SDF File)
====================================================
Schema name: Civil_schema
Feature classes : Pipes, structure, point, ...
properties inside Pipes feature class : PipeRadius, PipeType,....

====================================================
Now that I have the schema, I have two pipe data inside (two rows - PipeName = p1 and p2)
I want to insert PipeType as Iron for R-1P1 and PVC for R-1P2

for some reason my insert and update command isnt working...


Code snippet
====================================================

//static sdf file
string sdffile = "c:\test.sdf";

//created a IConnection con (i have this in correct - just dont want to write all)

using(con)
{
    using (osgeo_command.Feature.IUpdate update_data =                 con.CreateCommand(osgeo_command.CommandType.CommandType_Update) as osgeo_command.Feature.IUpdate)
       {
            //set the target schema
            update_data.SetFeatureClassName("Civil_schema:Pipes"); //schema name:clas name = this worked for reading
            update_data.SetFilter("Name = R-1P1"); // this is to identify the row - i am not going to update this row

            // property value collection
            PropertyValueCollection pcoll = update_data.PropertyValues;

            //creating a property value that needs to be added
             PropertyValue propvalue = null;
             propvalue = new PropertyValue();

             ValueExpression expression = (ValueExpression)Expression.Parse("'Iron'"); //want to add iron as my pipe type

            propvalue = new PropertyValue("Pipetype", expression);//here i am specifying the column name as Pipetype

            pcoll.Add(propvalue);

             if (1 != update_data.Execute())
                    {
                        ed.WriteMessage("\nUpdate failed");//this writes the message in autocad
                    }

       }
}

==============================================================
I dont know where i am going wrong...could you guys point me the correct direction please..

-Raghulan Gowthaman
Senior civil BIM Consultant
Reply | Threaded
Open this post in threaded view
|

Re: SDF Example for Insert , Update, Read

Jackie Ng
Are these values strings? They need to be wrapped in single-quotes.

- Jackie
Reply | Threaded
Open this post in threaded view
|

Re: SDF Example for Insert , Update, Read

raghulan
Yes they are strings..
When i tried this

ValueExpression expression = (ValueExpression)Expression.Parse("Iron");

I am getting following error

System.InvalidCastException: Unable to cast object of type 'OSGeo.FDO.Expression.Identifier' to type 'OSGeo.FDO.Expression.ValueExpression'.
   at C3D_SDF.CRUD.update_data(String sdf_file, IConnection con, Editor ed) in D:\SkyDrive\Dev Zone\Ms.NET\Projects\C3D_SDF\C3D_SDF\CRUD.cs:line 138

ValueExpression expression = (ValueExpression)Expression.Parse('Iron');//this is not working either.
-Raghulan Gowthaman
Senior civil BIM Consultant
Reply | Threaded
Open this post in threaded view
|

Re: SDF Example for Insert , Update, Read

Romica Dascalescu
Try :
ValueExpression expression = new StringValue("Iron");

Romy
________________________________________
From: [hidden email] [[hidden email]] on behalf of raghulan [[hidden email]]
Sent: Thursday, October 11, 2012 1:04 AM
To: [hidden email]
Subject: Re: [fdo-users] SDF Example for Insert , Update, Read

Yes they are strings..
When i tried this

ValueExpression expression = (ValueExpression)Expression.Parse("Iron");

I am getting following error

System.InvalidCastException: Unable to cast object of type
'OSGeo.FDO.Expression.Identifier' to type
'OSGeo.FDO.Expression.ValueExpression'.
   at C3D_SDF.CRUD.update_data(String sdf_file, IConnection con, Editor ed)
in D:\SkyDrive\Dev Zone\Ms.NET\Projects\C3D_SDF\C3D_SDF\CRUD.cs:line 138

ValueExpression expression =
(ValueExpression)Expression.Parse('Iron');//this is not working either.



--
View this message in context: http://osgeo-org.1560.n6.nabble.com/SDF-Example-for-Insert-Update-Read-tp5007560p5007904.html
Sent from the FDO Users mailing list archive at Nabble.com.
_______________________________________________
fdo-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fdo-users
_______________________________________________
fdo-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fdo-users
Reply | Threaded
Open this post in threaded view
|

Re: SDF Example for Insert , Update, Read

raghulan
This post was updated on .
Tried that its not working..Could guys let me know if my coding logic is correct..
esp...filter to identify the row..and column and the update command.
do i need to create any transaction and commit the transaction at the end..
==================================================
 // this is to identify the row - i am going to update this row
 update_data.SetFilter("Name = R-1P1");
----------------------------------------------------------------------------------------
//here i am specifying the column name as PipeType
propvalue = new PropertyValue("PipeType", expression);
----------------------------------------------------------------------------------------
//Add the property value to the property collection
 pcoll.Add(propvalue);

Then update_data.Execute()

===================================================
Is this correct?
-Raghulan Gowthaman
Senior civil BIM Consultant
Reply | Threaded
Open this post in threaded view
|

Re: SDF Example for Insert , Update, Read

raghulan
This post was updated on .
I think the issue might be with my <setfilter>....
=================================================
Could you give me some example to usage of set filter..

Imagine my table as below
=============================
ID  |  PipeName | PipeType
--------------------------------------------------
1    | R-1P1       |
--------------------------------------------------
2    | R-1P2       |
=============================

Now I want to select the row using the pipename = R-1P2
and update the value for PipeType.
How do i set the filter?
===========================================
-Raghulan Gowthaman
Senior civil BIM Consultant
Reply | Threaded
Open this post in threaded view
|

Re: SDF Example for Insert , Update, Read

raghulan
In reply to this post by raghulan
Found there was an issue with the filter...

correct filter is -
var filter = "('[Name]'='R-1P1')";
update_data.SetFilter(filter);//this is my command

now still i am getting update failed error (which I made to print if the update failed..)
any ideas..!!
-Raghulan Gowthaman
Senior civil BIM Consultant
Reply | Threaded
Open this post in threaded view
|

Re: SDF Example for Insert , Update, Read

Jackie Ng
Is "Name" an actual property that exists?

- Jackie
Reply | Threaded
Open this post in threaded view
|

Re: SDF Example for Insert , Update, Read

raghulan
hi Jacki, thanks for your continuous help...
yes name does exists..I wrote wrongly as PipeName previously.sorry....


here is my table
Imagine my table as below
=============================
ID  |  Name       | PipeType
--------------------------------------------------
1    | R-1P1       |
--------------------------------------------------
2    | R-1P2       |
=============================
-Raghulan Gowthaman
Senior civil BIM Consultant
Reply | Threaded
Open this post in threaded view
|

Re: SDF Example for Insert , Update, Read

Jackie Ng
Do not wrap property names in single-quotes, otherwise FDO treats them as string literal values. Also dont apply [] around them either as FDO filters do not recognise these tokens.

- Jackie