Esempio n. 1
0
        private static Map InitializeDXF(float angle)
        {
            Map map = new Map();
            //Set the datasource to a shapefile in the App_data folder
            Ogr provider;
            try
            {
                provider = new Ogr("GeoData/SampleDXF.dxf",0);
            }
            catch (TypeInitializationException ex)
            {
                if (ex.Message == "The type initializer for 'OSGeo.OGR.Ogr' threw an exception.")
                {
                    throw new Exception(
                        String.Format(
                            "The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. They are a part of fwtools {0}. You can download it from: http://home.gdal.org/fwtools/",
                            GdalRasterLayer.FWToolsVersion));
                }
                throw;
            }
            VectorLayer lay = new VectorLayer("SampleDXF", provider);
            map.Layers.Add(lay);
            map.ZoomToExtents();
            Matrix mat = new Matrix();
            mat.RotateAt(angle, map.WorldToImage(map.Center));
            map.MapTransform = mat;

            _ogrSampleDataset = "SampleDXF";
            return map;

        }
Esempio n. 2
0
        public void TestCreateFromFeatureDataTable()
        {
            var fds = new SharpMap.Data.FeatureDataSet();
            FeatureDataTable fdt = null;
            try
            {
                var p = new Ogr("C:\\Users\\obe.IVV-AACHEN\\Downloads\\SharpMap Codeplex\\SHPFiles\\RxLevel-Idle.shp");
                p.SRID = 4326;
                var layer = string.Empty;
                if (!string.IsNullOrEmpty(layer)) p.LayerName = layer;

                p.ExecuteIntersectionQuery(p.GetExtents(), fds);
                fdt = fds.Tables[0];
                if (fdt.Rows.Count == 0)
                    throw new Exception("no data in layer");
            }
            catch (Exception ex)
            {
                throw new IgnoreException("Getting data failed", ex);
            }

            Assert.DoesNotThrow(() => Ogr.CreateFromFeatureDataTable(fdt, 
                ((FeatureDataRow)fdt.Rows[0]).Geometry.OgcGeometryType, 4326, 
                "Mapinfo File", 
                "C:\\Users\\obe.IVV-AACHEN\\Downloads\\SharpMap Codeplex\\SHPFiles\\RxLevel-Idle.tab"));
        }
Esempio n. 3
0
        internal static Map InitializeMap(float angle, string[] filenames)
        {
            var providers = new SharpMap.Data.Providers.Ogr[filenames.Length];
            for (int i = 0; i < filenames.Length; i++)
            {
                providers[i] = new Ogr(filenames[i]);
            }

            var map = LayerTools.GetMapForProviders(providers);

            Matrix mat = new Matrix();
            mat.RotateAt(angle, map.WorldToImage(map.Center));
            map.MapTransform = mat;
            map.ZoomToExtents();
            return map;
        }
Esempio n. 4
0
        internal static Map InitializeMap(float angle, string[] filenames)
        {
            var providers = new SharpMap.Data.Providers.Ogr[filenames.Length];

            for (int i = 0; i < filenames.Length; i++)
            {
                providers[i] = new Ogr(filenames[i]);
            }

            var map = LayerTools.GetMapForProviders(providers);

            Matrix mat = new Matrix();

            mat.RotateAt(angle, map.WorldToImage(map.Center));
            map.MapTransform = mat;
            map.ZoomToExtents();
            return(map);
        }
Esempio n. 5
0
        public void TestCreateFromFeatureDataTable(string filePath, int srid, string driver, string connection)
        {
            var fds = new SharpMap.Data.FeatureDataSet();
            if (!Path.IsPathRooted(filePath))
                filePath = TestUtility.GetPathToTestFile(filePath);

            if (!System.IO.File.Exists(filePath))
                throw new IgnoreException($"'{filePath}' not found.");

            FeatureDataTable fdt = null;
            try
            {
                var p = new OgrProvider(filePath);
                if (p.SRID == 0)
                    p.SRID = srid;
                else
                    srid = p.SRID;

                string layer = string.Empty;
                if (!string.IsNullOrEmpty(layer)) p.LayerName = layer;

                p.ExecuteIntersectionQuery(p.GetExtents(), fds);
                fdt = fds.Tables[0];
                if (fdt.Rows.Count == 0)
                    throw new Exception("no data in layer");
                p.Dispose();
            }
            catch (Exception ex)
            {
                throw new IgnoreException("Getting data failed", ex);
            }

            Assert.DoesNotThrow(() => OgrProvider.CreateFromFeatureDataTable(fdt, 
                ((FeatureDataRow)fdt.Rows[0]).Geometry.OgcGeometryType, srid, 
                driver, connection));
        }
Esempio n. 6
0
        private static Map InitializeS57(float angle)
        {
            //Initialize a new map of size 'imagesize'
            Map map = new Map();

            //Set the datasource to a shapefile in the App_data folder
            Ogr provider;
            try
            {
                provider = new Ogr("GeoData/S57/US5TX51M.000");
            }
            catch (TypeInitializationException ex)
            {
                if (ex.Message == "The type initializer for 'OSGeo.OGR.Ogr' threw an exception.")
                {
                    throw new Exception(
                        String.Format(
                            "The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. They are a part of fwtools {0}. You can download it from: http://home.gdal.org/fwtools/",
                            GdalRasterLayer.FWToolsVersion));
                }
                throw;
            }

            VectorLayer lay;
            Random rnd = new Random(9);
            for (Int32 i = provider.NumberOfLayers - 1; i >= 0; i--)
            {
                Ogr prov = new Ogr("GeoData/S57/US5TX51M.000", i);
                if (!prov.IsFeatureDataLayer) continue;
                string name = prov.LayerName;
                System.Diagnostics.Debug.WriteLine(string.Format("Layer {0}: {1}", i, name));
                //if (provider.GeometryType )
                lay = new VectorLayer(string.Format("Layer_{0}", name), prov);
                if (prov.OgrGeometryTypeString.IndexOf("Polygon") > 0)
                {
                    lay.Style.Fill =
                        new SolidBrush(Color.FromArgb(150, Convert.ToInt32(rnd.NextDouble() * 255),
                                                      Convert.ToInt32(rnd.NextDouble() * 255),
                                                      Convert.ToInt32(rnd.NextDouble() * 255)));
                    lay.Style.Outline =
                        new Pen(
                            Color.FromArgb(150, Convert.ToInt32(rnd.NextDouble() * 255),
                                           Convert.ToInt32(rnd.NextDouble() * 255),
                                           Convert.ToInt32(rnd.NextDouble() * 255)),
                            Convert.ToInt32(rnd.NextDouble() * 3));
                    lay.Style.EnableOutline = true;
                }
                else
                {
                    lay.Style.Line =
                        new Pen(
                            Color.FromArgb(150, Convert.ToInt32(rnd.NextDouble()*255),
                                           Convert.ToInt32(rnd.NextDouble()*255), Convert.ToInt32(rnd.NextDouble()*255)),
                            Convert.ToInt32(rnd.NextDouble()*3));
                }
                map.Layers.Add(lay);
            }
            _ogrSampleDataset = "S-57";
            map.ZoomToExtents();

            Matrix mat = new Matrix();
            mat.RotateAt(angle, map.WorldToImage(map.Center));
            map.MapTransform = mat;

            return map;
        }