Beispiel #1
0
        public void OgrDataReaderTestReadGpxTracksViaBabel()
        {
            var babelPath = GetFullPathFromWindows("GPSbabel.exe");

            if (String.IsNullOrEmpty(babelPath))
            {
                Assert.Ignore("GPSbabel.exe was not found! Ignoring Babel based tests! If left to continue a (System.ApplicationException : Could not create process gpsbabel...) would have been thrown! ");
                return;
            }

            var gpxTestFile = GpxTestFileCreator.CreateTrackMakerGpsGpxTestFile();

            using (var dr = new OgrDataReader($"GPSBabel:gpx:features=tracks:{gpxTestFile}", new GpsBabelFileNameExtractor()))
            {
                var layer = dr.GetLayers().Keys.First();
                Assert.NotNull(layer);
                Assert.AreEqual(658, layer.Vertex.Length);
                var geom = layer.Features[0];
                Assert.AreEqual(5, layer.Features.Count);
                Assert.AreEqual(-47.616119460, layer.Vertex[0], _tolerance);
                Assert.AreEqual(-21.616149930, layer.Vertex[1], _tolerance);
                Assert.AreEqual(-47.611553182, layer.Vertex[656], _tolerance);
                Assert.AreEqual(-21.733156522, layer.Vertex[657], _tolerance);
                //layer.SaveAs($"OgrDataReaderTestReadGpxTracksViaBabel\\OgrDataReaderTestReadGpxTracksViaBabel.shp", true);
            }

            GpxTestFileCreator.DeleteTrackMakerGpsGpxTestFile();
        }
Beispiel #2
0
        public void OgrDataReaderTestReadGpxRoutesViaBabel()
        {
            var babelPath = GetFullPathFromWindows("GPSbabel.exe");

            if (String.IsNullOrEmpty(babelPath))
            {
                Assert.Ignore("GPSbabel.exe was not found! Ignoring Babel based tests! If left to continue a (System.ApplicationException : Could not create process gpsbabel...) would have been thrown! ");
                return;
            }

            var gpxTestFile = GpxTestFileCreator.CreateMapSourceSimpleWaypointERouteTestFile();

            using (var dr = new OgrDataReader($"GPSBabel:gpx:features=routes:{gpxTestFile}", new GpsBabelFileNameExtractor()))
            {
                var layer = dr.GetLayers().Keys.First();
                Assert.NotNull(layer);
                Assert.AreEqual(4, layer.Vertex.Length);
                var geom = layer.Features[0];
                Assert.AreEqual(1, geom.NumParts());
                Assert.AreEqual(-45.707053346559405, layer.Vertex[0], _tolerance);
                Assert.AreEqual(-23.718632999807596, layer.Vertex[1], _tolerance);
                Assert.AreEqual(-45.714390277862549, layer.Vertex[2], _tolerance);
                Assert.AreEqual(-23.71721469797194, layer.Vertex[3], _tolerance);
                //layer.SaveAs($"OgrDataReaderTestReadGpxRoutesViaBabel\\OgrDataReaderTestReadGpxRoutesViaBabel.shp", true);
            }

            GpxTestFileCreator.DeleteMapSourceSimpleWaypointERouteTestFile();
        }
Beispiel #3
0
 public FeatureType GetFeatureType(string fileName)
 {
     using (var reader = new OgrDataReader(fileName))
     {
         return(reader.GetFeatureType());
     }
 }
Beispiel #4
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);
        }
Beispiel #5
0
        public void OgrDataReaderTestReadGeoJSON()
        {
            var geoJSONTestFile = GeoJSONTestFileCreator.CreateGeoJSONTestFile();

            using (var dr = new OgrDataReader(geoJSONTestFile))
            {
                var layer = dr.GetLayers().Keys.First();
                Assert.NotNull(layer);
                Assert.AreEqual(14, layer.Vertex.Length);
                var geom = layer.Features[0];
                Assert.AreEqual(1, geom.NumParts());
                Assert.AreEqual(79.39064024773653, layer.Vertex[0], _tolerance);
                Assert.AreEqual(11.677958136567844, layer.Vertex[1], _tolerance);
                Assert.AreEqual(79.39064024773653, layer.Vertex[12], _tolerance);
                Assert.AreEqual(11.677958136567844, layer.Vertex[13], _tolerance);
                //layer.SaveAs($"OgrDataReaderTestReadGeoJSON\\OgrDataReaderTestReadGeoJSON.shp", true);
            }

            GeoJSONTestFileCreator.DeleteGeoJSONTestFile();
        }
Beispiel #6
0
        public void OgrDataReaderTestReadKmz()
        {
            var kmzTestFile = KmlTestFileCreator.CreateKmzTestFile();

            using (var dr = new OgrDataReader(kmzTestFile))
            {
                var layer = dr.GetLayers().Keys.First();
                Assert.NotNull(layer);
                Assert.AreEqual(658, layer.Vertex.Length);
                var geom = layer.Features[0];
                Assert.AreEqual(5, geom.NumParts());
                Assert.AreEqual(-47.616070987315659, layer.Vertex[0], _tolerance);
                Assert.AreEqual(-21.6161403350719, layer.Vertex[1], _tolerance);
                Assert.AreEqual(-47.61150467733979, layer.Vertex[656], _tolerance);
                Assert.AreEqual(-21.73314675187378, layer.Vertex[657], _tolerance);
                //layer.SaveAs($"OgrDataReaderTestReadKmz\\OgrDataReaderTestReadKmz.shp", true);
            }

            KmlTestFileCreator.DeleteKmzTestFile();
        }
Beispiel #7
0
        public void OgrDataReaderTestReadGpx()
        {
            var gpxTestFile = GpxTestFileCreator.CreateMapSourceSimpleWaypointERouteTestFile();

            //standard gpx reader only reads waypoints!
            using (var dr = new OgrDataReader(gpxTestFile))
            {
                var layer = dr.GetLayers().Keys.First();
                Assert.NotNull(layer);
                Assert.AreEqual(8, layer.Vertex.Length);
                var geom = layer.Features[0];
                Assert.AreEqual(1, geom.NumParts());
                Assert.AreEqual(-45.707975439727306, layer.Vertex[0], _tolerance);
                Assert.AreEqual(-23.719357447698712, layer.Vertex[1], _tolerance);
                Assert.AreEqual(-45.714390277862549, layer.Vertex[6], _tolerance);
                Assert.AreEqual(-23.71721469797194, layer.Vertex[7], _tolerance);
                //layer.SaveAs($"OgrDataReaderTestReadGpx\\OgrDataReaderTestReadGpx.shp", true);
            }

            GpxTestFileCreator.DeleteMapSourceSimpleWaypointERouteTestFile();
        }
Beispiel #8
0
        public FeatureType GetFeatureType(string fileName)
        {
            OgrDataReader reader = new OgrDataReader(fileName);

            return(reader.GetFeatureType());
        }
        /// <summary>
        /// Opens the specified file
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public IFeatureSet Open(string fileName)
        {
            WkbReader wkbReader = new WkbReader();

            OgrDataReader reader = new OgrDataReader(fileName);
            IFeatureSet fs = new FeatureSet();
            fs.Name = Path.GetFileNameWithoutExtension(fileName);
            fs.Filename = 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));
            }
            while (reader.Read())
            {
                byte[] wkbGeometry = (byte[])reader["Geometry"];

                IGeometry 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;
        }
 public FeatureType GetFeatureType(string fileName)
 {
     OgrDataReader reader = new OgrDataReader(fileName);
     return reader.GetFeatureType();
 }
Beispiel #11
0
 public FeatureType GetFeatureType(string fileName)
 {
     using (var reader = new OgrDataReader(fileName))
     {
         return reader.GetFeatureType();
     }
 }