Exemple #1
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());
        }
        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);
        }
Exemple #3
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);
        }
Exemple #4
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;
                }
            }
        }
        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());
        }
Exemple #6
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;
                }
            }
        }
        private void button18_Click(object sender, EventArgs e)
        {
            string wkt = "GEOGCS[\"等经纬度投影\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]]";

            wkt = "PROJCS[\"Hammer投影\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Hammer-Aitoff (world)\"]PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],PARAMETER[\"central_meridian\",105],UNIT[\"Meter\",1]]";
            ISpatialReference srcSpatialRef   = SpatialReferenceFactory.GetSpatialReferenceByWKT(wkt, enumWKTSource.EsriPrjFile);
            string            proj4           = srcSpatialRef.ToProj4String();
            ISpatialReference inverSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByProj4String(proj4);

            inverSpatialRef.IsSame(srcSpatialRef);

            IProjectionTransform tr = ProjectionTransformFactory.GetProjectionTransform(srcSpatialRef, SpatialReference.GetDefault());

            double[] x = new double[] { 1534910 };
            double[] y = new double[] { 4255978 };
            x = new double[] { 121.913 };
            y = new double[] { 38.957 };
            tr.InverTransform(x, y);
            tr.Transform(x, y);
        }
Exemple #8
0
        private string[] GetOptions(string outImage, double outResX, double outResY, string outSpatialRef, CoordEnvelope CoordEnv, out string driver)
        {
            driver = "LDF";
            string ext = Path.GetExtension(outImage).ToLower();

            switch (ext)
            {
            case ".ldf":
            {
                driver = "LDF";
                string[] optionString = new string[] {
                    "INTERLEAVE=BSQ",
                    "VERSION=LDF",
                    "WITHHDR=TRUE",
                    "SPATIALREF=" + outSpatialRef,
                    "MAPINFO={" + 1 + "," + 1 + "}:{" + CoordEnv.MinX + "," + CoordEnv.MaxY + "}:{" + outResX + "," + outResY + "}"
                };
                return(optionString);
            }

            case ".tif":
            case ".tiff":
            {
                driver = "GDAL";
                string[] optionString = new string[] {
                    "DRIVERNAME=GTiff",
                    "TFW=YES",
                    "WKT=" + SpatialReferenceFactory.GetSpatialReferenceByProj4String(outSpatialRef).ToWKTString(),
                    "GEOTRANSFORM=" + string.Format("{0},{1},{2},{3},{4},{5}", CoordEnv.MinX, outResX, 0, CoordEnv.MaxY, 0, -outResY)
                };
                return(optionString);
            }

            default:
            {
                throw new Exception("暂不支持的输出数据格式");
            }
            }
        }