Ejemplo n.º 1
0
 /// <summary>
 /// 根据给出的经纬度数据集或者投影坐标数据集,计算其是否在指定的范围内,并且计算出有效率,以及实际输出范围
 /// </summary>
 /// <param name="xs"></param>
 /// <param name="ys"></param>
 /// <param name="validEnv"></param>
 /// <param name="oSpatialRef"></param>
 /// <param name="tSpatialRef"></param>
 /// <param name="validRate"></param>
 /// <param name="outEnv"></param>
 /// <returns></returns>
 public bool VaildEnvelope(double[] xs, double[] ys, PrjEnvelope validEnv, SpatialReference oSpatialRef,
                           SpatialReference tSpatialRef, out double validRate, out PrjEnvelope outEnv)
 {
     if (validEnv == null || validEnv.IsEmpty)
     {
         throw new ArgumentNullException("validEnv", "参数[有效范围]不能为空");
     }
     if (tSpatialRef == null)
     {
         tSpatialRef = SpatialReferenceFactory.CreateSpatialReference(4326);
     }
     if (oSpatialRef == null)
     {
         oSpatialRef = SpatialReferenceFactory.CreateSpatialReference(4326);
     }
     using (IProjectionTransform transform =
                ProjectionTransformFactory.GetProjectionTransform(oSpatialRef, tSpatialRef))
     {
         if (oSpatialRef.IsSame(tSpatialRef) != 1)
         {
             transform.Transform(xs, ys);
         }
         return(PrjEnvelope.HasValidEnvelope(xs, ys, validEnv, out validRate, out outEnv));
     }
 }
Ejemplo n.º 2
0
 private void TryCreateSpatialRef()
 {
     try
     {
         _projectionRef = Dataset.GetProjectionRef();
         if (!string.IsNullOrWhiteSpace(_projectionRef))
         {
             _spatialRef = SpatialReferenceFactory.GetSpatialReferenceByWKT(_projectionRef, enumWKTSource.EsriPrjFile);
         }
         if (string.IsNullOrWhiteSpace(_projectionRef))
         {
             TryReadSpatialRefFromSecondaryFile();
         }
         if (_spatialRef == null)
         {
             _coordType = enumCoordType.Raster;
         }
         else
         {
             _coordType = _spatialRef.ProjectionCoordSystem != null ? enumCoordType.PrjCoord : enumCoordType.GeoCoord;
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Ejemplo n.º 3
0
        private enumCoordinateType GetCoordinateType(SpatialFeatureClass spatialFeatureClass, out ISpatialReference spref)
        {
            spref = null;
            try
            {
                ISpatialReference rf = SpatialReferenceFactory.GetSpatialReferenceByPrjFile(spatialFeatureClass.SpatialRef) as ISpatialReference;
                spref = rf;
                if (rf == null)
                {
                    goto ensureByEnvelopeLine;
                }
                if (rf.ProjectionCoordSystem == null)
                {
                    return(enumCoordinateType.Geographic);
                }
                else
                {
                    return(enumCoordinateType.Projection);
                }
            }
            catch
            {
                goto ensureByEnvelopeLine;
            }
ensureByEnvelopeLine:
            return(spatialFeatureClass.Envelope.IsGeoRange() ? enumCoordinateType.Geographic : enumCoordinateType.Projection);
        }
Ejemplo n.º 4
0
        public override void ComputeDstEnvelope(AbstractWarpDataset srcRaster, SpatialReference dstSpatialRef,
                                                out PrjEnvelope maxPrjEnvelope, Action <int, string> progressCallback)
        {
            InitLocationArgs(srcRaster);
            var projTrans = ProjectionTransformFactory.GetProjectionTransform(_srcSpatialRef, dstSpatialRef);

            float srcResolutionX = Convert.ToSingle(_srcGeoTrans[1]);
            float srcResolutionY = Math.Abs(Convert.ToSingle(_srcGeoTrans[5]));

            double srcLeftTopX = _srcGeoTrans[0];
            double srcLeftTopY = _srcGeoTrans[3];
            int    srcWidth    = srcRaster.Width;
            int    srcHeight   = srcRaster.Height;
            Size   srcSize     = new Size(srcWidth, srcHeight);

            int wSample = 1;
            int hSample = 1;

            if (srcWidth > 1000)
            {
                wSample = srcWidth / 1000;
            }

            if (srcHeight > 1000)
            {
                hSample = srcHeight / 1000;
            }

            double[] xs    = new double[(srcWidth / wSample) * (srcHeight / hSample)];
            double[] ys    = new double[(srcWidth / wSample) * (srcHeight / hSample)];
            int      index = 0; //非真实的索引号,采样后的

            for (int rowInx = 0; rowInx <= (srcHeight - hSample); rowInx += hSample)
            {
                for (int colInx = 0; colInx <= (srcWidth - wSample); colInx += wSample)
                {
                    xs[index] = srcLeftTopX + colInx * srcResolutionX;
                    ys[index] = srcLeftTopY - rowInx * srcResolutionY;
                    index++;
                }
            }

            if (dstSpatialRef.IsSame(SpatialReferenceFactory.CreateSpatialReference(4326)) == 1)
            {
                projTrans.Transform(xs, ys);
                GeosCorrection(dstSpatialRef, xs, ys);
                maxPrjEnvelope = PrjEnvelope.GetEnvelope(xs, ys, null);
            }
            else
            {
                _rasterProjector.ComputeDstEnvelope(_srcSpatialRef, xs, ys, srcSize, dstSpatialRef, out maxPrjEnvelope,
                                                    null);
            }

            if (_setting != null && _setting.OutEnvelope != null)
            {
                //求交
                maxPrjEnvelope.Intersect(_setting.OutEnvelope);
            }
        }
 public string TestDstExtendWGS84()
 {
     try
     {
         PrjEnvelope dstEnvelope;
         dstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj");
         srcFilename   = @"D:\mas数据\Mersi\FY3A_MERSI_GBAL_L1_20110501_0250_1000M_MS.HDF";
         srcRaster     = GeoDataDriver.Open(srcFilename) as IRasterDataProvider;
         IFileProjector proj = FileProjector.GetFileProjectByName("FY3_MERSI");
         proj.ComputeDstEnvelope(srcRaster, dstSpatialRef, out dstEnvelope, _progressCallback);
         Console.WriteLine(dstEnvelope.ToString());
         return(dstEnvelope.ToString());
     }
     finally
     {
         if (srcRaster != null)
         {
             if (srcRaster.BandProvider != null)
             {
                 srcRaster.BandProvider.Dispose();
             }
             srcRaster.Dispose();
         }
     }
 }
Ejemplo n.º 6
0
        protected override void FillEntityToCotrols()
        {
            if (_isNew)
            {
                Text = "新建空间要素类...";
                if (_dataset != null)
                {
                    FillDataset(_dataset);
                }
                return;
            }
            else
            {
                Text = "编辑空间要素类属性...";
            }
            SpatialFeatureClass ds = _entity as SpatialFeatureClass;

            if (ds.SpatialFeatureDataset != null)
            {
                FillDataset(ds.SpatialFeatureDataset);
            }
            txtName.Text       = _entity.Name;
            txtDecription.Text = _entity.Description;
            txtMapScale.Value  = ds.MapScale;
            txtSource.Text     = ds.Source;
            if (ds.SpatialRef != null)
            {
                ISpatialReference sref = SpatialReferenceFactory.GetSpatialReferenceByWKT(ds.SpatialRef, enumWKTSource.EsriPrjFile);
                ucSpatialRef1.SpatialReference = sref;
            }
        }
Ejemplo n.º 7
0
        //[SetUp]
        public void DataReady(Action <int, string> progressCallback)
        {
            try
            {
                ///等经纬度投影
                dstFilename   = @"D:\mas数据\Mersi\fy3_Block.ldf";
                dstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj");//
                srcFilename   = @"D:\mas数据\Mersi\FY3A_MERSI_GBAL_L1_20110501_0250_1000M_MS.HDF";
                dstEnvelope   = PrjEnvelope.CreateByCenter(116.890377, 27.7621965, 33.49, 21.53);

                srcRaster  = GeoDataDriver.Open(srcFilename) as IRasterDataProvider;
                prjSetting = new FY3_MERSI_PrjSettings();
                //prjSetting.OutResolutionX = 0.01F;
                //prjSetting.OutResolutionY = 0.01F;
                prjSetting.OutPathAndFileName = dstFilename;
                prjSetting.OutFormat          = "LDF";
                //prjSetting.OutEnvelope = dstEnvelope;
                //prjSetting.BandMapTable = bandmapList;
                prjSetting.IsRadiation = true;
                _progressCallback      = progressCallback;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 8
0
        //[SetUp]
        public void DataReady(Action <int, string> progressCallback)
        {
            ///等经纬度投影
            dstFilename   = @"D:\mas数据\MODIS\TERRA_2010_03_25_03_09_GZ.MOD02HKM.ldf";
            dstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj"); //
            srcFilename   = @"D:\mas数据\MODIS\TERRA_2010_03_25_03_09_GZ.MOD02HKM.HDF";
            dstEnvelope   = PrjEnvelope.CreateByCenter(110, 32, 5, 5);                            //
            string secondFile = @"D:\mas数据\MODIS\TERRA_2010_03_25_03_09_GZ.MOD03.HDF";
            IRasterDataProvider secondFileRaster = GeoDataDriver.Open(secondFile) as IRasterDataProvider;

            srcRaster = GeoDataDriver.Open(srcFilename) as IRasterDataProvider;
            //List<BandMap> bandmapList = new List<BandMap>();
            prjSetting = new EOS_MODIS_PrjSettings();

            prjSetting.OutResolutionX     = 0.0025F;
            prjSetting.OutResolutionY     = 0.0025F;
            prjSetting.OutPathAndFileName = dstFilename;
            prjSetting.OutFormat          = "LDF";
            //prjSetting.OutEnvelope = dstEnvelope;
            //prjSetting.BandMapTable = bandmapList;
            //prjSetting.IsRadiation = false;
            prjSetting.SecondaryOrbitRaster = null;
            prjSetting.LocationFile         = secondFileRaster;
            _progressCallback = progressCallback;
        }
        public void ParserTiff()
        {
            string            spreftxt = File.ReadAllText("f:\\2.prj");
            ISpatialReference spref    = SpatialReferenceFactory.GetSpatialReferenceByWKT(spreftxt, enumWKTSource.GDAL);

            Assert.NotNull(spref);
            Console.Write(spref.ToWKTString());
        }
Ejemplo n.º 10
0
 public FY3L2L3FileProjector()
     : base()
 {
     _name            = "FY3L2L3";
     _fullname        = "FY3L2L3轨道文件投影";
     _rasterProjector = new RasterProjector();
     _srcSpatialRef   = SpatialReferenceFactory.CreateSpatialReference(4326);
 }
Ejemplo n.º 11
0
        public void TestProjMap()
        {
            string            proj4Str      = "proj +proj=stere +lon_0=0 +lat_0=-90 +lat_ts=-71 +ellps=WGS84 +datum=WGS84";
            ISpatialReference srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj");

            srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByProj4String(proj4Str);
            Console.WriteLine(srcSpatialRef.ToString());
        }
Ejemplo n.º 12
0
 public FY2_NOMProjection()
     : base()
 {
     _name            = "FY2NOM";
     _fullname        = "FY2_NOM数据投影";
     _rasterProjector = new RasterProjector();
     _srcSpatialRef   = SpatialReferenceFactory.CreateSpatialReference(4326);
     _supportAngles   = new string[] { "NOMSatelliteZenith", "NOMSunGlintAngle", "NOMSunZenith" };
 }
        public void Test()
        {
            ISpatialReference srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj");

            srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("Mercator (sphere).prj");
            string proj4 = srcSpatialRef.ToProj4String();

            Assert.AreEqual(proj4, "+proj=merc +x_0=0 +y_0=0 +lon_0=0 +lat_1=0 +datum=WGS84 +a=6371000 +b=6356863.01877305+f=正无穷大 +nodefs");
            srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByProj4String(proj4);
        }
Ejemplo n.º 14
0
 public FY3_VIRRFileProjector()
     : base()
 {
     _name                = "FY3_VIRR";
     _fullname            = "FY3_VIRR轨道文件投影";
     _rasterProjector     = new RasterProjector();
     _srcSpatialRef       = SpatialReferenceFactory.CreateSpatialReference(4326);
     _supportExtBandNames = new string[] { "Height", "LandCover", "LandSeaMask" };
     //_NODATA_VALUE = 65535;
 }
Ejemplo n.º 15
0
        private void button1_Click(object sender, EventArgs e)
        {
            ISpatialReference srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj");
            string            prj4          = srcSpatialRef.ToProj4String();
            ISpatialReference dstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj");

            using (IProjectionTransform tran = ProjectionTransformFactory.GetProjectionTransform(srcSpatialRef, dstSpatialRef))
            {
            }
        }
Ejemplo n.º 16
0
 public FY3_MERSIFileProjector()
     : base()
 {
     _name            = "FY3_MERSI";
     _fullname        = "FY3_MERSI轨道数据投影";
     _rasterProjector = new RasterProjector();
     _srcSpatialRef   = SpatialReferenceFactory.CreateSpatialReference(4326);
     _left            = 10;
     _right           = 10;
     //_NODATA_VALUE = 65535;
 }
Ejemplo n.º 17
0
        //private void button4_Click(object sender, EventArgs e)
        //{
        //    ISpatialReference srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj");
        //    srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("Mercator (sphere).prj");
        //    string proj4 = srcSpatialRef.ToProj4String();
        //    srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByProj4String(proj4);
        //}

        //private void button4_Click(object sender, EventArgs e)
        //{
        //    TestFy3AVirrProjection fyp = new TestFy3AVirrProjection();
        //    Action<int, string> progressCallback = new Action<int, string>(OutProgress);
        //    fyp.DataReady(progressCallback);
        //    Stopwatch stopwatch = new Stopwatch();
        //    stopwatch.Start();
        //    fyp.TestFy3VIRR();
        //    stopwatch.Stop();
        //    WriteLine("数据投影{0}ms", stopwatch.ElapsedMilliseconds);
        //    stopwatch.Restart();
        //}

        private void TestPrj4Parser_Click(object sender, EventArgs e)
        {
            ISpatialReference srcSpatialRef = null;// SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj");
            string            prjFile       = "f:\\32600.prj";

            srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("Mercator (sphere).prj");
            string            proj4           = srcSpatialRef.ToProj4String();
            ISpatialReference inverSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByProj4String(proj4);

            bool isSame = srcSpatialRef.IsSame(inverSpatialRef);
        }
Ejemplo n.º 18
0
 public override void ComputeDstEnvelope(AbstractWarpDataset srcRaster, SpatialReference dstSpatialRef, out PrjEnvelope maxPrjEnvelope, Action <int, string> progressCallback)
 {
     if (dstSpatialRef == null || dstSpatialRef.IsGeographic() == 1)
     {
         maxPrjEnvelope = new PrjEnvelope(60, 150, -70, 70, SpatialReferenceFactory.CreateSpatialReference(4326));
     }
     else
     {
         maxPrjEnvelope = null;
     }
 }
Ejemplo n.º 19
0
 public FY3B_MERSIFileProjector()
     : base()
 {
     _name                = "FY3B_MERSI";
     _fullname            = "FY3B_MERSI轨道数据投影";
     _rasterProjector     = new RasterProjector();
     _srcSpatialRef       = SpatialReferenceFactory.CreateSpatialReference(4326);
     _left                = 10;
     _right               = 10;
     _supportExtBandNames = new string[] { "DEM", "LandCover", "LandSeaMask" };
     //_NODATA_VALUE = 65535;
 }
Ejemplo n.º 20
0
        private ISpatialReference GetSpatialReference(string projectionIdentify)
        {
            switch (projectionIdentify)
            {
            case "ABS":
                return(SpatialReferenceFactory.GetSpatialReferenceByPrjFile("\\"));

            //return new SpatialReference(new GeographicCoordSystem(), new ProjectionCoordSystem());
            case "GLL":
            default:
                return(SpatialReference.GetDefault());
            }
        }
Ejemplo n.º 21
0
 private static PrjEnvelopeItem ParseEnvelope(XElement xElement)
 {
     if (xElement == null || xElement.Value == null)
     {
         return(null);
     }
     return(new PrjEnvelopeItem(xElement.Attribute("name").Value,
                                new PrjEnvelope(double.Parse(xElement.Attribute("minx").Value)
                                                , double.Parse(xElement.Attribute("maxx").Value)
                                                , double.Parse(xElement.Attribute("miny").Value)
                                                , double.Parse(xElement.Attribute("maxy").Value)
                                                , SpatialReferenceFactory.CreateSpatialReference(4326))));
 }
Ejemplo n.º 22
0
 public override void ComputeDstEnvelope(AbstractWarpDataset srcRaster, SpatialReference dstSpatialRef, out PrjEnvelope maxPrjEnvelope, Action <int, string> progressCallback)
 {
     if (srcRaster != null)
     {
         Size     srcSize = new Size(srcRaster.Width, srcRaster.Height);
         double[] xs, ys;
         ReadyLocations(srcRaster, SpatialReferenceFactory.CreateSpatialReference(4326), dstSpatialRef, out srcSize, out xs, out ys, out maxPrjEnvelope, progressCallback);
     }
     else
     {
         maxPrjEnvelope = PrjEnvelope.Empty;
     }
 }
Ejemplo n.º 23
0
        internal void ParserMvgHeaderParams(object[] options, out ISpatialReference spatialRef, out HdrMapInfo mapInfo, out bool isWithHdr,
                                            out Int16 valueCount, out Int16[] values, out string[] valueNames)
        {
            spatialRef = null;
            mapInfo    = null;
            isWithHdr  = true;
            valueCount = 0;
            values     = null;
            valueNames = null;
            if (options == null || options.Length == 0)
            {
                return;
            }
            foreach (object option in options)
            {
                string param = option.ToString();
                int    k     = param.IndexOf('=');
                string key   = param.Substring(0, k).ToUpper().Trim();
                string value = param.Substring(k + 1).ToUpper().Trim();
                switch (key)
                {
                case "VALUECOUNT":
                    valueCount = Convert.ToInt16(value);
                    break;

                case "VALUES":
                    values = ParserValues(value);
                    break;

                case "VALUENAMES":
                    valueNames = ParserValueNames(value);
                    break;

                case "SPATIALREF":
                    spatialRef = SpatialReferenceFactory.GetSpatialReferenceByProj4String(value);
                    break;

                case "MAPINFO":
                    mapInfo = ParseMapInfo(value);
                    break;

                case "WITHHDR":
                    isWithHdr = value.ToUpper() == "TRUE" || value == "1";
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 24
0
 /// <summary>
 /// 经度跨越180度,进行修正
 /// </summary>
 protected void GeosInverCorrection(SpatialReference dstSpatialRef, double[] xs, double[] ys)
 {
     //都是WGS84
     if (dstSpatialRef.IsSame(SpatialReferenceFactory.CreateSpatialReference(4326)) == 1)
     {
         for (int i = 0; i < xs.Length; i++)
         {
             if (xs[i] > 180)
             {
                 xs[i] = xs[i] - 360;
             }
         }
     }
 }
Ejemplo n.º 25
0
        private void BindChild(TreeNode fNode)
        {
            string path = fNode.Name;

            if (path == null || !Directory.Exists(path))
            {
                return;
            }
            DirectoryInfo fDir = new DirectoryInfo(path);

            FileSystemInfo[]     finfos = fDir.GetFileSystemInfos();
            SpatialReferenceFile spatialRefFile;

            foreach (FileSystemInfo f in finfos)
            {
                spatialRefFile = new SpatialReferenceFile();
                string   type = f.GetType().ToString();
                TreeNode node = new TreeNode();
                node.Name = f.FullName;                //将文件的完整路径保存在节点的名字中
                if ("System.IO.DirectoryInfo" == type) //是文件夹才递归调用自己
                {
                    spatialRefFile.IsPrjFile = false;
                    node.Tag                = spatialRefFile;
                    node.ImageIndex         = 0;
                    node.SelectedImageIndex = 2;
                    node.Text               = f.Name; //将文件的名字保存在节点的文本显示中
                    fNode.Nodes.Add(node);
                    BindChild(node);
                }
                else
                {
                    if (!f.Name.Contains(".prj"))
                    {
                        continue;
                    }
                    if (f.Name.Substring(f.Name.LastIndexOf('.')) != ".prj")
                    {
                        continue;
                    }
                    node.Text = f.Name.Remove(f.Name.LastIndexOf('.'));
                    spatialRefFile.SpatialReference = SpatialReferenceFactory.GetSpatialReferenceByPrjFile(f.FullName);   //是否能成功解析prj文件
                    spatialRefFile.IsPrjFile        = true;
                    node.Tag                = spatialRefFile;
                    node.ImageIndex         = 1;
                    node.SelectedImageIndex = 1;
                    fNode.Nodes.Add(node);
                }
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 解析坐标系统文件夹,并添加到树中
        /// </summary>
        /// <param name="fNode"></param>
        private void BindChild(TreeNode fNode)
        {
            string path = fNode.Name;

            if (path == null || !Directory.Exists(path))
            {
                return;
            }
            string[]             paths = Directory.GetDirectories(path);
            string[]             files = Directory.GetFiles(path);
            SpatialReferenceFile spatialRefFile;

            for (int i = 0; i < paths.Length; i++)
            {
                string   subPath = paths[i];
                TreeNode node    = new TreeNode();
                node.Name                = subPath;
                spatialRefFile           = new SpatialReferenceFile();
                spatialRefFile.IsPrjFile = false;
                node.Tag                = spatialRefFile;
                node.ImageIndex         = 0;
                node.SelectedImageIndex = 2;
                node.Text               = Path.GetFileNameWithoutExtension(subPath);
                fNode.Nodes.Add(node);
                BindChild(node);
            }
            for (int i = 0; i < files.Length; i++)
            {
                string subFile = files[i];
                string fileExt = Path.GetExtension(subFile);
                if (fileExt != ".prj")
                {
                    continue;
                }
                TreeNode node = new TreeNode();
                node.Name      = subFile;
                node.Text      = Path.GetFileNameWithoutExtension(subFile);
                spatialRefFile = new SpatialReferenceFile();
                spatialRefFile.SpatialReference = SpatialReferenceFactory.GetSpatialReferenceByPrjFile(subFile);
                spatialRefFile.IsPrjFile        = true;
                node.Tag                = spatialRefFile;
                node.ImageIndex         = 1;
                node.SelectedImageIndex = 1;
                fNode.Nodes.Add(node);
            }
        }
        public void ParseProj4()
        {
            string proj4 = "+proj=merc +lon_0=0 +k0=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137";

            Console.WriteLine("INPUT:");
            Console.WriteLine(proj4);
            ISpatialReference spatialRef = SpatialReferenceFactory.GetSpatialReferenceByProj4String(proj4);

            Console.WriteLine("ESRI WKT:");
            Console.WriteLine(spatialRef.ToString());
            Console.WriteLine("PROJ.4:");
            Console.WriteLine(spatialRef.ToProj4String());
            Console.WriteLine("OGC WKT:");
            Console.WriteLine(spatialRef.ToWKTString());
            Console.WriteLine("ENVI Projection Info:");
            Console.WriteLine(spatialRef.ToEnviProjectionInfoString());
        }
Ejemplo n.º 28
0
        public override void Click()
        {
            IMapControl mapControl = (_hook as IHookOfAgileMap).MapControl;

            if (mapControl != null)
            {
                using (OpenFileDialog dlg = new OpenFileDialog())
                {
                    dlg.Filter = "ESRI Projection Files(*.prj)|*.prj";
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        ISpatialReference sref = SpatialReferenceFactory.GetSpatialReferenceByPrjFile(dlg.FileName);
                        mapControl.SpatialReference = sref;
                    }
                }
            }
        }
Ejemplo n.º 29
0
        private static ISpatialReference[] GetCustomSpatialReferences()
        {
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "坐标系统\\自定义");

            if (!Directory.Exists(path))
            {
                return(null);
            }
            string[] files = Directory.GetFiles(path);
            if (files == null || files.Length == 0)
            {
                return(null);
            }
            List <ISpatialReference> spatialReferenceList = new List <ISpatialReference>();
            ISpatialReference        spatialReference;

            for (int i = 0; i < files.Length; i++)
            {
                string file = files[i];
                spatialReference = SpatialReferenceFactory.GetSpatialReferenceByPrjFile(file);
                if (spatialReference == null)
                {
                    continue;
                }
                spatialReferenceList.Add(spatialReference);
            }
            //将等经纬度的调整为第一个
            List <ISpatialReference> glls = spatialReferenceList.FindAll(
                match =>
                match.Name.Contains("等经纬度") ||
                (match.ProjectionCoordSystem == null && match.GeographicsCoordSystem != null)
                );

            if (glls != null && glls.Count != 0)
            {
                foreach (ISpatialReference gl in glls)
                {
                    spatialReferenceList.Remove(gl);
                }
                spatialReferenceList.InsertRange(0, glls);
            }
            return(spatialReferenceList.ToArray());
        }
Ejemplo n.º 30
0
        private void ParseOptions(int width, int height, object[] options, out ISpatialReference spatialRef, out CoordEnvelope coordEnvelope, out HdrMapInfo mapInfo,
                                  out bool isWithHdr, out int extHeaderSize)
        {
            mapInfo       = null;
            spatialRef    = null;
            coordEnvelope = null;
            isWithHdr     = true;
            extHeaderSize = 0;
            if (options == null || options.Length == 0)
            {
                return;
            }
            foreach (object option in options)
            {
                string param = option.ToString();
                int    k     = param.IndexOf('=');
                string key   = param.Substring(0, k).ToUpper().Trim();
                string value = param.Substring(k + 1).ToUpper().Trim();
                switch (key.ToUpper())
                {
                case "SPATIALREF":
                    spatialRef = SpatialReferenceFactory.GetSpatialReferenceByProj4String(value);
                    break;

                case "MAPINFO":
                    mapInfo       = ParseMapInfoFromOptionValue(value);
                    coordEnvelope = CoordEnvelope.FromMapInfoString(value, new Size(width, height));
                    break;

                case "WITHHDR":
                    isWithHdr = value.ToUpper() == "TRUE" || value == "1";
                    break;

                case "EXTHEADERSIZE":
                    extHeaderSize = int.Parse(value);
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 31
0
 /**
  * Sets the interface for creating spatial reference systems.
  * You can call this to replace the default implememtation with
  * another one.
  *
  * @param factory
  *      New spatial reference factory implementation.
  */
 public void setSRSFactory(SpatialReferenceFactory _factory)
 {
     spatial_ref_factory = _factory;
 }