コード例 #1
0
        public static object GetFieldValue(this OSGeo.OGR.Feature feature, string fieldName)
        {
            if (feature == null || string.IsNullOrEmpty(fieldName))
            {
                throw new Exception("参数设置错误");
            }
            using var fieldDefn = feature.GetFieldDefnRef(fieldName);
            object value;

            switch (fieldDefn.GetFieldType())
            {
            case OSGeo.OGR.FieldType.OFTString:
                value = feature.GetFieldAsString(fieldName);
                break;

            case OSGeo.OGR.FieldType.OFTInteger:
                value = feature.GetFieldAsInteger(fieldName);
                break;

            case OSGeo.OGR.FieldType.OFTInteger64:
                value = feature.GetFieldAsInteger64(fieldName);
                break;

            case OSGeo.OGR.FieldType.OFTReal:
                value = feature.GetFieldAsDouble(fieldName);
                break;

            default:
                throw new NotImplementedException();
            }
            return(value);
        }
コード例 #2
0
        public static object GetFieldValue(this OSGeo.OGR.Feature feature, int index)
        {
            if (feature == null || index < 0 || index >= feature.GetFieldCount())
            {
                throw new Exception("参数设置错误");
            }
            using var fieldDefn = feature.GetFieldDefnRef(index);
            object value;

            switch (fieldDefn.GetFieldType())
            {
            case  OSGeo.OGR.FieldType.OFTString:
                value = feature.GetFieldAsString(index);
                break;

            case OSGeo.OGR.FieldType.OFTInteger:
                value = feature.GetFieldAsInteger(index);
                break;

            case OSGeo.OGR.FieldType.OFTInteger64:
                value = feature.GetFieldAsInteger64(index);
                break;

            case OSGeo.OGR.FieldType.OFTReal:
                value = feature.GetFieldAsDouble(index);
                break;

            default:
                throw new NotImplementedException();
            }
            return(value);
        }
コード例 #3
0
ファイル: VectorConverter.cs プロジェクト: giszzt/GeoSOS
        /// <summary>
        /// Get value from Ogr feature
        /// </summary>
        /// <param name="feature">Ogr feature</param>
        /// <param name="i">Field index</param>
        /// <returns>Value</returns>
        public static object GetOgrValue(OSGeo.OGR.Feature feature, int i)
        {
            switch (feature.GetFieldDefnRef(i).GetFieldType())
            {
            case OSGeo.OGR.FieldType.OFTString:
                return(feature.GetFieldAsString(i));

            case OSGeo.OGR.FieldType.OFTInteger:
                return(feature.GetFieldAsInteger(i));

            case OSGeo.OGR.FieldType.OFTDateTime:
                return(GetFieldAsDateTime(feature, i));

            case OSGeo.OGR.FieldType.OFTReal:
                return(feature.GetFieldAsDouble(i));

            default:
                return(null);
            }
        }