Saturday, January 24, 2009

FDO Oracle Spatial .net

Hi All,
Today we are going to tell you abour accessing the oracle spatial data using FDO in .net
make all necessary settings for FDO as we described in the previous post.
Here is the code..

private static IProviderRegistry FDORegistry = FeatureAccessManager.GetProviderRegistry();
private IConnectionManager FDOManager = FeatureAccessManager.GetConnectionManager();
ProviderCollection pcol = FDORegistry.GetProviders();
private IConnection FDOConnection = FeatureAccessManager.GetConnectionManager().CreateConnection("Autodesk.Oracle.3.3");


public ConnectionState Constate;
string featureclsname;

  • Connect to Oracle using following function.

public FDOOracleClass(string username,string password,string servicename,string featureclassname)
{
FDOConnection.ConnectionInfo.ConnectionProperties.SetProperty("USERNAME", username);
FDOConnection.ConnectionInfo.ConnectionProperties.SetProperty("PASSWORD", password);
FDOConnection.ConnectionInfo.ConnectionProperties.SetProperty("SERVICE", servicename);
FDOConnection.ConnectionInfo.ConnectionProperties.SetProperty("DATASTORE", username);

featureclsname = featureclassname;

Constate = FDOConnection.Open();
}

  • Check the Connection state
    public ConnectionState CheckConnected
    {
    get
    {
    return Constate;
    }
    }

  • By using this function we can retrive the Geometry and required attributes...
    public GeometryCollection SelectAllQuery()
    {
    GeometryCollection Geo_Collection = new GeometryCollection();
    try
    {
    ISelect sel = (ISelect)FDOConnection.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_Select);
    sel.SetFeatureClassName(featureclsname);
    // sel.LockType = OSGeo.FDO.Commands.Locking.LockType.LockType_Unsupported;

    // select column_name,table_name from user_tab_columns where data_type = 'SDO_GEOMETRY'
    IFeatureReader FDOReader = sel.Execute();
    FgfGeometryFactory gFac = new FgfGeometryFactory();
    while (FDOReader.ReadNext())
    {
    int wauid = FDOReader.GetInt16("TEST1");// Attribute field 1
    int Infuid = FDOReader.GetInt16("TEST2"); // Attribute field 2
    Byte[] Tmppts = FDOReader.GetGeometry("GEOM"); // name of geometry column
    Geo_Collection.Add(gFac.CreateGeometryFromFgf(Tmppts));
    }
    }
    catch(OSGeo.FDO.Common.Exception ex)
    {
    MessageBox.Show(ex.Message.ToString());
    }
    return Geo_Collection;
    }

if u want to know how to manipluate the geometry Please post you comment.

Thank You,

2 comments:

Anonymous said...

Hello,

Can you post also a sample with geometry manipulation?

Anonymous said...

Hi,

Obviously you know about programming with FDO. I don't, and unfortunately I also don't have the time to become familiar with this subject.
My question is : Can you program a service for me that just writes a geometry into an Oracle spatial field ?
Please contact me on jg@gbor.nl
Kind regards,
Jan Groenestein