public LocalNativeFeature(MgFeatureReader reader, FixedWKTReader mgReader, MgAgfReaderWriter agfRw, MgWktReaderWriter wktRw)
            : base(Utility.ConvertClassDefinition(reader.GetClassDefinition()))
        {
            for (int i = 0; i < reader.GetPropertyCount(); i++)
            {
                string name = _ordinalMap[i];
                GetByteReaderMethod getblob = () => { return(reader.GetBLOB(name)); };
                GetByteReaderMethod getclob = () => { return(reader.GetCLOB(name)); };
                GetByteReaderMethod getgeom = () => { return(reader.GetGeometry(name)); };
                if (!reader.IsNull(name))
                {
                    var pt = (PropertyValueType)reader.GetPropertyType(name);
                    switch (pt)
                    {
                    case PropertyValueType.Blob:
                        ((BlobValue)_values[name]).Value = Utility.StreamAsArray(new MgReadOnlyStream(getblob));
                        break;

                    case PropertyValueType.Boolean:
                        ((BooleanValue)_values[name]).Value = reader.GetBoolean(name);
                        break;

                    case PropertyValueType.Byte:
                        ((ByteValue)_values[name]).Value = reader.GetByte(name);
                        break;

                    case PropertyValueType.Clob:
                        byte[] b = Utility.StreamAsArray(new MgReadOnlyStream(getclob));
                        ((ClobValue)_values[name]).Value = Encoding.UTF8.GetChars(b);
                        break;

                    case PropertyValueType.DateTime:
                        ((DateTimeValue)_values[name]).Value = Utility.ConvertMgDateTime(reader.GetDateTime(name));
                        break;

                    case PropertyValueType.Double:
                        ((DoubleValue)_values[name]).Value = reader.GetDouble(name);
                        break;

                    case PropertyValueType.Feature:
                        ((FeatureValue)_values[name]).Value = GetFeatureArray(reader, name);
                        break;

                    case PropertyValueType.Geometry:
                        //TODO: See if SWIG issues come into play here
                        try
                        {
                            //TODO: See if SWIG issues come into play here
                            var geom = agfRw.Read(reader.GetGeometry(name));
                            var wkt  = wktRw.Write(geom);
                            ((GeometryValue)_values[name]).Value = mgReader.Read(wkt);
                        }
                        catch     //Invalid geometry fail!
                        {
                            ((GeometryValue)_values[name]).SetNull();
                        }
                        break;

                    case PropertyValueType.Int16:
                        ((Int16Value)_values[name]).Value = reader.GetInt16(name);
                        break;

                    case PropertyValueType.Int32:
                        ((Int32Value)_values[name]).Value = reader.GetInt32(name);
                        break;

                    case PropertyValueType.Int64:
                        ((Int64Value)_values[name]).Value = reader.GetInt64(name);
                        break;

                    case PropertyValueType.Single:
                        ((SingleValue)_values[name]).Value = reader.GetSingle(name);
                        break;

                    case PropertyValueType.String:
                        ((StringValue)_values[name]).Value = reader.GetString(name);
                        break;
                    }
                }
            }
        }
예제 #2
0
        /// <summary>Получает набор свойств MgPropertyCollection из текущей записи _reader в соответствии со списком _listed_prop_defs</summary>
        /// <param name="_reader"></param>
        /// <param name="_listed_prop_defs"></param>
        /// <returns></returns>
        internal static MgPropertyCollection GetPropertiesFromReader(MgFeatureReader _reader, MgPropertyDefinitionCollection _listed_prop_defs)
        {
            MgPropertyCollection result_props = new MgPropertyCollection();

            MgPropertyDefinitionCollection reader_prop_defs = _reader.GetClassDefinition().GetProperties();

            foreach (MgPropertyDefinition curr_prop_def in _listed_prop_defs)
            {
                if (!reader_prop_defs.Contains(curr_prop_def.Name) || _reader.IsNull(curr_prop_def.Name))
                {
                    continue;
                }

                int property_type = _reader.GetPropertyType(curr_prop_def.Name);
                if (property_type == MgPropertyType.Blob)
                {
                    result_props.Add(
                        new MgBlobProperty(curr_prop_def.Name, _reader.GetBLOB(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Boolean)
                {
                    result_props.Add(
                        new MgBooleanProperty(curr_prop_def.Name, _reader.GetBoolean(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Byte)
                {
                    result_props.Add(
                        new MgByteProperty(curr_prop_def.Name, _reader.GetByte(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Clob)
                {
                    result_props.Add(
                        new MgClobProperty(curr_prop_def.Name, _reader.GetCLOB(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.DateTime)
                {
                    result_props.Add(
                        new MgDateTimeProperty(curr_prop_def.Name, _reader.GetDateTime(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Double)
                {
                    result_props.Add(
                        new MgDoubleProperty(curr_prop_def.Name, _reader.GetDouble(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Feature)
                {
                    result_props.Add(
                        new MgFeatureProperty(curr_prop_def.Name, _reader.GetFeatureObject(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Geometry)
                {
                    result_props.Add(
                        new MgGeometryProperty(curr_prop_def.Name, _reader.GetGeometry(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Int16)
                {
                    result_props.Add(
                        new MgInt16Property(curr_prop_def.Name, _reader.GetInt16(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Int32)
                {
                    result_props.Add(
                        new MgInt32Property(curr_prop_def.Name, _reader.GetInt32(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Int64)
                {
                    result_props.Add(
                        new MgInt64Property(curr_prop_def.Name, _reader.GetInt64(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Raster)
                {
                    result_props.Add(
                        new MgRasterProperty(curr_prop_def.Name, _reader.GetRaster(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Single)
                {
                    result_props.Add(
                        new MgSingleProperty(curr_prop_def.Name, _reader.GetSingle(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.String)
                {
                    result_props.Add(
                        new MgStringProperty(curr_prop_def.Name, _reader.GetString(curr_prop_def.Name))
                        );
                }
            }              //foreach

            return(result_props);
        }
예제 #3
0
 public LocalNativeFeature(MgFeatureReader reader, FixedWKTReader mgReader, MgAgfReaderWriter agfRw, MgWktReaderWriter wktRw)
     : base(Utility.ConvertClassDefinition(reader.GetClassDefinition()))
 {
     for (int i = 0; i < reader.GetPropertyCount(); i++)
     {
         string name = _ordinalMap[i];
         GetByteReaderMethod getblob = () => { return reader.GetBLOB(name); };
         GetByteReaderMethod getclob = () => { return reader.GetCLOB(name); };
         GetByteReaderMethod getgeom = () => { return reader.GetGeometry(name); };
         if (!reader.IsNull(name))
         {
             var pt = (PropertyValueType)reader.GetPropertyType(name);
             switch (pt)
             {
                 case PropertyValueType.Blob:
                     ((BlobValue)_values[name]).Value = Utility.StreamAsArray(new MgReadOnlyStream(getblob));
                     break;
                 case PropertyValueType.Boolean:
                     ((BooleanValue)_values[name]).Value = reader.GetBoolean(name);
                     break;
                 case PropertyValueType.Byte:
                     ((ByteValue)_values[name]).Value = reader.GetByte(name);
                     break;
                 case PropertyValueType.Clob:
                     byte[] b = Utility.StreamAsArray(new MgReadOnlyStream(getclob));
                     ((ClobValue)_values[name]).Value = Encoding.UTF8.GetChars(b);
                     break;
                 case PropertyValueType.DateTime:
                     ((DateTimeValue)_values[name]).Value = Utility.ConvertMgDateTime(reader.GetDateTime(name));
                     break;
                 case PropertyValueType.Double:
                     ((DoubleValue)_values[name]).Value = reader.GetDouble(name);
                     break;
                 case PropertyValueType.Feature:
                     ((FeatureValue)_values[name]).Value = GetFeatureArray(reader, name);
                     break;
                 case PropertyValueType.Geometry:
                     //TODO: See if SWIG issues come into play here
                     try
                     {
                         //TODO: See if SWIG issues come into play here
                         var geom = agfRw.Read(reader.GetGeometry(name));
                         var wkt = wktRw.Write(geom);
                         ((GeometryValue)_values[name]).Value = mgReader.Read(wkt);
                     }
                     catch //Invalid geometry fail!
                     {
                         ((GeometryValue)_values[name]).SetNull();
                     }
                     break;
                 case PropertyValueType.Int16:
                     ((Int16Value)_values[name]).Value = reader.GetInt16(name);
                     break;
                 case PropertyValueType.Int32:
                     ((Int32Value)_values[name]).Value = reader.GetInt32(name);
                     break;
                 case PropertyValueType.Int64:
                     ((Int64Value)_values[name]).Value = reader.GetInt64(name);
                     break;
                 case PropertyValueType.Single:
                     ((SingleValue)_values[name]).Value = reader.GetSingle(name);
                     break;
                 case PropertyValueType.String:
                     ((StringValue)_values[name]).Value = reader.GetString(name);
                     break;
             }
         }
     }
 }