[OracleCustomTypeMappingAttribute("MDSYS.SDO_GEOMETRY")]
public class SdoGeometry : OracleCustomTypeBase<SdoGeometry>
{
private enum OracleObjectColumns { SDO_GTYPE, SDO_SRID, SDO_POINT, SDO_ELEM_INFO, SDO_ORDINATES }
private decimal? sdo_Gtype;
[OracleObjectMappingAttribute(0)]
public decimal? Sdo_Gtype
{
get { return sdo_Gtype; }
set { sdo_Gtype = value; }
}
private decimal? sdo_Srid;
[OracleObjectMappingAttribute(1)]
public decimal? Sdo_Srid
{
get { return sdo_Srid; }
set { sdo_Srid = value; }
}
private SdoPoint point;
[OracleObjectMappingAttribute(2)]
public SdoPoint Point
{
get { return point; }
set { point = value; }
}
private decimal[] elemArray;
[OracleObjectMappingAttribute(3)]
public decimal[] ElemArray
{
get { return elemArray; }
set { elemArray = value; }
}
private decimal[] ordinatesArray;
[OracleObjectMappingAttribute(4)]
public decimal[] OrdinatesArray
{
get { return ordinatesArray; }
set { ordinatesArray = value; }
}
[OracleCustomTypeMappingAttribute("MDSYS.SDO_ELEM_INFO_ARRAY")]
public class ElemArrayFactory : OracleArrayTypeFactoryBase<decimal> {}
[OracleCustomTypeMappingAttribute("MDSYS.SDO_ORDINATE_ARRAY")]
public class OrdinatesArrayFactory : OracleArrayTypeFactoryBase<decimal> {}
public override void MapFromCustomObject()
{
SetValue((int)OracleObjectColumns.SDO_GTYPE, Sdo_Gtype);
SetValue((int)OracleObjectColumns.SDO_SRID, Sdo_Srid);
SetValue((int)OracleObjectColumns.SDO_POINT, Point);
SetValue((int)OracleObjectColumns.SDO_ELEM_INFO, ElemArray);
SetValue((int)OracleObjectColumns.SDO_ORDINATES, OrdinatesArray);
}
public override void MapToCustomObject()
{
Sdo_Gtype = GetValue<decimal?>((int)OracleObjectColumns.SDO_GTYPE);
Sdo_Srid = GetValue<decimal?>((int)OracleObjectColumns.SDO_SRID);
Point = GetValue<SdoPoint>((int)OracleObjectColumns.SDO_POINT);
ElemArray = GetValue<decimal[]>((int)OracleObjectColumns.SDO_ELEM_INFO);
OrdinatesArray = GetValue<decimal[]>((int)OracleObjectColumns.SDO_ORDINATES);
}
} OracleCommand cmd = new OracleCommand()
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = " select id,geo from geoinfo ";
using (OracleDataReader readerGeoInfo = cmd.ExecuteReader())
{
while (readerGeoInfo.Read())
{
GeoInfo geoInfo = new GeoInfo();
if (!readerGeoInfo.IsDBNull(0))
{
geoInfo.Id = readerGeoInfo.GetDecimal(0);
}
if (!readerGeoInfo.IsDBNull(1))
{
geoInfo.Geo = (SdoGeometry)readerGeoInfo.GetValue(1);
}
geoInfoList.Add(geoInfo);
}
readerGeoInfo.Close();
}cmd.CommandText = " insert into geoinfo values (geoinfo_seq.nextval,:param) ";
cmd.Parameters.Clear();
OracleParameter oracleParameterGeo = new OracleParameter();
oracleParameterGeo.OracleDbType = OracleDbType.Object;
oracleParameterGeo.UdtTypeName = "MDSYS.SDO_GEOMETRY";
cmd.Parameters.Add(oracleParameterGeo);
//creating point
SdoGeometry geoPoint = new SdoGeometry();
geoPoint.Sdo_Gtype = 2001;
geoPoint.Point = new SdoPoint();
geoPoint.Point.X = 200;
geoPoint.Point.Y = 400;
oracleParameterGeo.Value = geoPoint;
//insert point in table geoinfo
cmd.ExecuteNonQuery();
//creating polygon
SdoGeometry geoPolygon = new SdoGeometry();
geoPolygon.Sdo_Gtype = 2003;
geoPolygon.ElemArray = new decimal[] { 1, 1003, 1 };
geoPolygon.OrdinatesArray = new decimal[] { 3, 3, 3, 10, 10, 10, 10, 3, 3, 3 };
oracleParameterGeo.Value = geoPolygon;
//insert polygon into table geoinfo
cmd.ExecuteNonQuery();使用C#操作Oracle Spatial的SDO_GEOMETRY对像(读取和写入),布布扣,bubuko.com
使用C#操作Oracle Spatial的SDO_GEOMETRY对像(读取和写入)
原文:http://blog.csdn.net/rrrrssss00/article/details/22879719