Ejemplo n.º 1
0
 public FeatureType GetFeatureType(string fileName)
 {
     using (var reader = new OgrDataReader(fileName))
     {
         return(reader.GetFeatureType());
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Opens the specified file
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public IFeatureSet Open(string fileName)
        {
            IFeatureSet fs = new FeatureSet();

            fs.Name     = Path.GetFileNameWithoutExtension(fileName);
            fs.Filename = fileName;
            using (var reader = new OgrDataReader(fileName))
            {
                // skip the geometry column which is always column 0
                for (int i = 1; i < reader.FieldCount; i++)
                {
                    string sFieldName = reader.GetName(i);
                    Type   type       = reader.GetFieldType(i);

                    int    uniqueNumber = 1;
                    string uniqueName   = sFieldName;
                    while (fs.DataTable.Columns.Contains(uniqueName))
                    {
                        uniqueName = sFieldName + uniqueNumber;
                        uniqueNumber++;
                    }
                    fs.DataTable.Columns.Add(new DataColumn(uniqueName, type));
                }

                var wkbReader = new WKBReader();
                while (reader.Read())
                {
                    var wkbGeometry = (byte[])reader["Geometry"];

                    var geometry = wkbReader.Read(wkbGeometry);

                    IFeature feature = new Feature(geometry);
                    feature.DataRow = fs.DataTable.NewRow();
                    for (int i = 1; i < reader.FieldCount; i++)
                    {
                        object value = reader[i];
                        if (value == null)
                        {
                            value = DBNull.Value;
                        }
                        feature.DataRow[i - 1] = value;
                    }
                    fs.Features.Add(feature);
                }

                try
                {
                    fs.Projection = reader.GetProj4ProjectionInfo();
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex);
                }
            }

            return(fs);
        }