コード例 #1
0
ファイル: OgrProvider.cs プロジェクト: ssteenkiste/Sharpmap
        private static FeatureDataRow LoadOgrFeatureToFeatureDataRow(FeatureDataTable table, OSGeo.OGR.Feature ogrFeature, GeoAPI.Geometries.IGeometryFactory factory)
        {
            var values = new object[ogrFeature.GetFieldCount()];

            for (var iField = 0; iField < ogrFeature.GetFieldCount(); iField++)
            {
                // No need to get field value if there's no value available...
                if (!ogrFeature.IsFieldSet(iField))
                {
                    continue;
                }

                int count;
                switch (ogrFeature.GetFieldType(iField))
                {
                case OgrFieldType.OFTString:
                case OgrFieldType.OFTWideString:
                    values[iField] = ogrFeature.GetFieldAsString(iField);
                    break;

                case OgrFieldType.OFTStringList:
                case OgrFieldType.OFTWideStringList:
                    values[iField] = ogrFeature.GetFieldAsStringList(iField);
                    break;

                case OgrFieldType.OFTInteger:
                    values[iField] = ogrFeature.GetFieldAsInteger(iField);
                    break;

                case OgrFieldType.OFTIntegerList:
                    values[iField] = ogrFeature.GetFieldAsIntegerList(iField, out count);
                    break;

                case OgrFieldType.OFTReal:
                    values[iField] = ogrFeature.GetFieldAsDouble(iField);
                    break;

                case OgrFieldType.OFTRealList:
                    values[iField] = ogrFeature.GetFieldAsDoubleList(iField, out count);
                    break;

                case OgrFieldType.OFTDate:
                case OgrFieldType.OFTDateTime:
                case OgrFieldType.OFTTime:
                    Int32 y, m, d, h, mi, s, tz;
                    ogrFeature.GetFieldAsDateTime(iField, out y, out m, out d, out h, out mi, out s, out tz);
                    try
                    {
                        if (y == 0 && m == 0 && d == 0)
                        {
                            values[iField] = DateTime.MinValue.AddMinutes(h * 60 + mi);
                        }
                        else
                        {
                            values[iField] = new DateTime(y, m, d, h, mi, s);
                        }
                    }
// ReSharper disable once EmptyGeneralCatchClause
                    catch { }
                    break;

                default:
                    Debug.WriteLine("Cannot handle Ogr DataType '{0}'", ogrFeature.GetFieldType(iField));
                    break;
                }
            }

            var fdr = (FeatureDataRow)table.LoadDataRow(values, true);

            using (var gr = ogrFeature.GetGeometryRef())
            {
                fdr.Geometry = ParseOgrGeometry(gr, factory);
                gr.Dispose();
            }
            return(fdr);
        }