How to insert SDO_GEOMETRY object variable from C# code into oracle table containing coloumn of sdo_geometry type?

StackOverflow https://stackoverflow.com/questions/22604183

  •  20-06-2023
  •  | 
  •  

Question

I am having an SDO_GEOMETRY object variable that fetches sdo_geometry type data from map. I need to save this data into table as SDO_Geometry field. I was able to successfully fetch SDO_GEOMETRY field from Table and use it , now i am blocked in saving the fetched SDO_Geometry field.

I have a stored procedure that can take SDO_Geometry type variable as input.

     P_GEOMETRY IN  MDSYS.SDO_GEOMETRY, -- this is the input parameter of Stored Procedure

my code that provides sdo_geometry type of object is :

    parameter.AddWithValue("P_GEOMETRY", geom, OracleDbType.Object, ParameterDirectionWrap.Input);

where geom is sdo_geometry class object that contains sdo_geometry field. the error i am getting in my sample .net application is

     Invalid parameter binding 
     Parameter name: P_GEOMETRY

which is the best way to avoid this problem.

Was it helpful?

Solution 3

Hi i found the following solution usefull,

OracleParameter endGeometry = cmd.CreateParameter();
endGeometry.OracleDbType = OracleDbType.Object;
endGeometry.UdtTypeName = "MDSYS.SDO_GEOMETRY";
endGeometry.Value = routeSegment.endPointGeometry;
endGeometry.ParameterName = "P_END_GEOM";    

parameter.Add(endGeometry);   

parameter then passed to stored procedure as input along with other variables

OTHER TIPS

You have two choices: You can write a wrapper PL/SQL procedure that takes whatever input you decide and then sets up the call using SDO_GEOMETRY within PL/SQL. Or you can use Oracle Developer Tools for Visual Studio Custom Class wizard to generate C# code that maps to the SDO_GEOMETRY user defined type.

To do the latter:

Install Oracle Developer Tools for Visual Studio, connect in server explorer using ODP.NET, and navigate to the User Defined Types node, then find the spatial types you need (including SDO_GEOMETRY) and then run Custom Class Wizard to generate a class that you can use to pass data into your stored procedure.

Here is a walk through that should assist you with the general concepts:

http://apex.oracle.com/pls/apex/f?p=44785:24:106658667466148:::24:P24_CONTENT_ID,P24_PROD_SECTION_GRP_ID,P24_PREV_PAGE:4258,,24

If you are concerned about performance and there is a lot of data involved, consider using associative arrays instead and forgo UDTs on the client side.

Here is another solution which works for me.

Convert fetched SDO_Geometry to WKB byte array using NetTopologySuite for example. Then in your stored procedure convert byte array to SDO_GEOMETRY using function SDO_UTIL.FROM_WKBGEOMETRY(P_GEOMETRY)

In your case parameter would look like something similar to this parameter.AddWithValue("P_GEOMETRY", wkbByteArray, OracleDbType.Raw, ParameterDirectionWrap.Input);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top