[mapguide-users] Re: create redline line and polygon using king fdo and MGOS

siva4gis leo.shiv at gmail.com
Sat May 15 04:20:23 EDT 2010


Hi Haris,


By using oracle custom data types you can save line,polygon directly in
oracle and you can see it in mapguide.

OracleArrayTypeFactory.cs

using System;
using Oracle.DataAccess.Types;
using Oracle.DataAccess.Client;


namespace Oracle.UdtBase
{
  public abstract class OracleArrayTypeFactoryBase<T> :
IOracleArrayTypeFactory
  {
    public Array CreateArray(int numElems)
    {
      return new T[numElems];
    }

    public Array CreateStatusArray(int numElems)
    {
      return null;
    }
  }
}

OracleCustomTypeBase.cs

using System;
using Oracle.DataAccess.Types;
using Oracle.DataAccess.Client;

namespace Oracle.UdtBase
{

  public abstract class OracleCustomTypeBase<T> : INullable,
IOracleCustomType, IOracleCustomTypeFactory
  where T : OracleCustomTypeBase<T>, new()
  {
    private static string errorMessageHead = "Error converting Oracle User
Defined Type to .Net Type "+ typeof(T).ToString()+ ", oracle column is null,
failed to map to . NET valuetype, column ";

    private OracleConnection connection;
    private IntPtr pUdt;


    private bool isNull;

    public virtual bool IsNull
    {
      get
      {
        return isNull;
      }
    }

    public static T Null
    {
      get
      {
        T t = new T();
        t.isNull = true;
        return t;
      }
    }

    public IOracleCustomType CreateObject()
    {
      return new T();
    }

    protected void SetConnectionAndPointer(OracleConnection _connection,
IntPtr _pUdt)
    {
      connection = _connection;
      pUdt = _pUdt;
    }

    public abstract void MapFromCustomObject();
    public abstract void MapToCustomObject();

    public void FromCustomObject(OracleConnection con, IntPtr pUdt)
    {
      SetConnectionAndPointer(con, pUdt);
      MapFromCustomObject();
    }
    public void ToCustomObject(OracleConnection con, IntPtr pUdt)
    {
      SetConnectionAndPointer(con, pUdt);
      MapToCustomObject();
    }

    protected void SetValue(string oracleColumnName, object value)
    {
      if (value != null)
      {
        OracleUdt.SetValue(connection, pUdt, oracleColumnName, value);
      }
    }
    protected void SetValue(int oracleColumn_Id, object value)
    {
      if (value != null)
      {
        OracleUdt.SetValue(connection, pUdt, oracleColumn_Id, value);
      }
    }

    protected U GetValue<U>(string oracleColumnName)
    {

      if (OracleUdt.IsDBNull(connection, pUdt, oracleColumnName))
      {
        if (default(U) is ValueType)
        {
          throw new Exception(errorMessageHead + oracleColumnName.ToString()
+ " of value type " + typeof(U).ToString());
        }
        else
        {
          return default(U);
        }
      }
      else
      {
        return (U)OracleUdt.GetValue(connection, pUdt, oracleColumnName);
      }
    }

    protected U GetValue<U>(int oracleColumn_Id)
    { 
      if (OracleUdt.IsDBNull(connection, pUdt, oracleColumn_Id))
      {
        if (default(U) is ValueType)
        {
          throw new Exception(errorMessageHead + oracleColumn_Id.ToString()
+ " of value type " + typeof(U).ToString());
        }
        else
        {
          return default(U);
        }
      }
      else
      {
        return (U)OracleUdt.GetValue(connection, pUdt, oracleColumn_Id);
      }
    }
  }
}


SdoGeometry.cs

using System;
using System.Collections.Generic;
using System.Text;
using Oracle.DataAccess.Types;
using Siva.Geo;
using Oracle.UdtBase;

namespace Siva.Geo
{
  [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 double[] ordinatesArray;

    [OracleObjectMappingAttribute(4)]
    public double[] 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<double>
{}

    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<double[]>((int)OracleObjectColumns.SDO_ORDINATES);
    }
  }
}


SdoPoint.cs

using System;
using System.Collections.Generic;
using System.Text;
using Oracle.DataAccess.Types;
using Oracle.UdtBase;

namespace Siva.Geo
{
  [OracleCustomTypeMappingAttribute("MDSYS.SDO_POINT_TYPE")]
  public class SdoPoint : OracleCustomTypeBase<SdoPoint>
  {
    private double? x;

    [OracleObjectMappingAttribute("X")]
    public double? X
    {
      get { return x; }
      set { x = value; }
    }

    private double? y;

    [OracleObjectMappingAttribute("Y")]
    public double? Y
    {
      get { return y; }
      set { y = value; }
    }

    private double? z;

    [OracleObjectMappingAttribute("Z")]
    public double? Z
    {
      get { return z; }
      set { z = value; }
    }

    public override void MapFromCustomObject()
    {
      SetValue("X", x);
      SetValue("Y", y);
      SetValue("Z", z);
    }

    public override void MapToCustomObject()
    {
        X = GetValue<double?>("X");
        Y = GetValue<double?>("Y");
        Z = GetValue<double?>("Z");
    }
  }
}

while inserting use dbtype as object

Create one object for sdo

private static Geo.SdoGeometry _sdoGeometry;
        public Geo.SdoGeometry SdoGeometry
        {
            get { return _sdoGeometry; }
            set { _sdoGeometry = value; }
        }

this.Dbm.AddOracleParameters(P_ + TblEnumerationblock.FN_GEOMETRY,
this.TblEnumerationblock.SdoGeometry, OracleDbType.Object,
ParameterDirection.Input);

if (OracleDbType == OracleDbType.Object)
                    this.Oracleparameter.UdtTypeName = "MDSYS.SDO_GEOMETRY";
                this.Oracleparameter.Direction = paramDirection;
-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/create-redline-line-and-polygon-using-king-fdo-and-MGOS-tp5039612p5058530.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list