Exemple #1
0
        public IRasterDataProvider Add(string file, out string errorMsg)
        {
            errorMsg = "";
            IRasterDataProvider prd = null;

            try
            {
                prd = GeoDataDriver.Open(file) as IRasterDataProvider;
                if (prd != null)
                {
                    IRasterDataProvider newprd = ProjectionFactory.CheckPrjArg(prd);
                    if (newprd != prd)
                    {
                        prd.Dispose();
                    }
                    if (Add(newprd, out errorMsg))
                    {
                        return(newprd);
                    }
                }
                if (prd != null)
                {
                    prd.Dispose();
                }
                return(null);
            }
            catch
            {
                if (prd != null)
                {
                    prd.Dispose();
                }
                throw;
            }
        }
Exemple #2
0
 public static Layer GetGML(string layerName, string fileName, bool visibility)
 {
     return(new Layer(layerName, string.Format(@"new OpenLayers.Layer.GML('{0}', '{1}', {{projection: {2},
         visibility: {3}, format: OpenLayers.Format.KML, formatOptions: {{extractStyles: true, extractAttributes:
         true}}, 'sphericalMercator': true}})", layerName, fileName, ProjectionFactory.GetGoogle(),
                                               visibility ? "true" : "false"), true));
 }
        private void projection(Bitmap img, Graphics horizontal, Graphics vertical)
        {
            ProjectionFactory factory = new ProjectionFactory(img);

            factory.Threshold = (int)numericUpDown1.Value;

            drawHorizontal(horizontal, factory.getHorizontalProject());
            drawVertical(vertical, factory.getVerticalProject());
        }
        internal ProjectionCollectionType(TypeKind kind, Type type, ProjectionFactory factory)
            : base(type, kind, factory)
        {
            // Must register before getting key/item types, due to possible cycles
            // Example: A -> IList<B> -> B -> IList<B>
            factory.RegisterProjectionType(this);

            Type keyType, itemType;
            GetSubtypes(out keyType, out itemType);

            this.keyType  = factory.GetProjectionTypeUnsafe(keyType );
            this.itemType = factory.GetProjectionTypeUnsafe(itemType);
        }
Exemple #5
0
 private async Task TryDispatch(ProjectionDescriptor descriptor, MessageEnvelope envelope, ProjectingContext context)
 {
     try
     {
         var instance = ProjectionFactory.CreateProjectionInstance(descriptor.ProjectionType);
         if (instance == null)
         {
             throw new NullReferenceException($"Projection instance {descriptor.ProjectionType.FullName} is null.");
         }
         await descriptor.Invoke(instance, envelope.Message, envelope.Meta, context);
     }
     catch (Exception e)
     {
         throw new ProjectingException(descriptor, envelope, context, e);
     }
 }
        internal ProjectionStructureType(Type type, ProjectionFactory factory)
            : base(type, TypeKind.Structure, factory)
        {
            // Ensure base types exist before self
            //   - Safe because no type can have itself as a base (i.e. no cycles)
            //   - Causes inits to be called in order from more-base to more-derived
            int basePropertyCount;
            baseTypes = CollectBaseTypes(type, out basePropertyCount);

            // Register self
            //   - Required before creating metaobjects that can refer back to this type
            factory.RegisterProjectionType(this);

            // Create members after registration
            //   - Members can be of any type and thus can form cycles
            properties = CollectProperties(type, basePropertyCount);
        }
Exemple #7
0
        private bool ValidEnvelope(IRasterDataProvider inputRaster, PrjEnvelopeItem[] validEnvelopes, out string msg)
        {
            bool          hasValid = false;
            StringBuilder str      = new StringBuilder();
            PrjEnvelope   fileEnv  = ProjectionFactory.GetEnvelope(inputRaster);

            foreach (PrjEnvelopeItem validEnvelope in validEnvelopes)
            {
                hasValid = ProjectionFactory.HasInvildEnvelope(inputRaster, validEnvelope.PrjEnvelope);
                if (!hasValid)
                {
                    str.AppendLine("数据不在范围内:" + validEnvelope.Name + validEnvelope.PrjEnvelope.ToString());
                }
            }
            msg = str.ToString();
            return(hasValid);
        }
Exemple #8
0
        private void button5_Click(object sender, EventArgs e)
        {
            string            fileName = SelectFile("选择轨道数据");
            ISpatialReference prj      = SelectPrj("选择目标投影定义");
            ProjectionFactory quick    = new ProjectionFactory();

            string[] outFiles = null;
            string   errorMessage;

            try
            {
                PrjOutArg prjOutArg = new PrjOutArg(prj, null, 0, 0, Path.GetDirectoryName(fileName));
                outFiles = quick.Project(fileName, prjOutArg, _progressCallback, out errorMessage);
            }
            finally
            {
            }
        }
Exemple #9
0
        private void Project(string fileName, ISpatialReference proj)
        {
            string errorMsg;

            string[]             outFiles = null;
            Action <int, string> progress = new Action <int, string>(OnProgress);
            ProjectionFactory    quick    = new ProjectionFactory();

            try
            {
                _progressMonitor = _smartSession.ProgressMonitorManager.DefaultProgressMonitor;
                if (_progressMonitor != null)
                {
                    _progressMonitor.Reset("", 100);
                    _progressMonitor.Start(false);
                    _progressMonitor.Boost(0, "准备文件");
                }
                PrjOutArg prjOutArg = new PrjOutArg(proj, null, 0, 0, Path.GetDirectoryName(fileName));
                outFiles = quick.Project(fileName, prjOutArg, progress, out errorMsg);
            }
            finally
            {
                if (_progressMonitor != null)
                {
                    _progressMonitor.Finish();
                }
                progress = null;
            }
            if (outFiles != null && outFiles.Length != 0)
            {
                for (int i = 0; i < outFiles.Length; i++)
                {
                    if (!string.IsNullOrWhiteSpace(outFiles[i]))
                    {
                        OpenFileToWindows(outFiles[i]);
                    }
                }
            }
            if (errorMsg != null && errorMsg.Length != 0)
            {
                MsgBox.ShowInfo(errorMsg);
            }
        }
Exemple #10
0
        private bool ValidEnvelope(IRasterDataProvider inputRaster, PrjEnvelopeItem[] validEnvelopes, out string msg)
        {
            bool          hasValid = false;
            StringBuilder str      = new StringBuilder();

            foreach (PrjEnvelopeItem validEnvelope in validEnvelopes)
            {
                if (!ProjectionFactory.HasInvildEnvelope(inputRaster, validEnvelope.PrjEnvelope))
                {
                    str.AppendLine("数据不在范围内:" + validEnvelope.Name + validEnvelope.PrjEnvelope.ToString());
                }
                else
                {
                    hasValid = true;//只要这块数据在一个有效区域内,就返回true,执行整块数据投影。
                }
            }
            msg = str.ToString();
            return(hasValid);
        }
        internal ProjectionProperty(PropertyInfo property, ProjectionStructureType declaringType,
            ProjectionPropertyCollection properties, ProjectionFactory factory, ITraitResolution resolution)
        {
            this.name          = property.Name;
            this.declaringType = declaringType;
            this.propertyType  = factory.GetProjectionTypeUnsafe(property.PropertyType);
            this.accessors     = new IPropertyAccessor[4]; // factory.Providers.Count

            var getter = property.GetGetMethod();
            var setter = property.GetSetMethod();
            if (getter != null) { getterHandle = getter.MethodHandle; flags |= Flags.CanRead;  }
            if (setter != null) { setterHandle = setter.MethodHandle; flags |= Flags.CanWrite; }

            var aggregator = new ProjectionPropertyTraitAggregator(this, properties);
            resolution.ProvidePropertyTraits(this, property, aggregator);

            this.aggregator = aggregator;
            this.overrides  = aggregator.Overrides;
        }
Exemple #12
0
        private void calcRegionRange()
        {
            ProjectionFactory factory = new ProjectionFactory(_srcImg, _edgeValue - 1);

            int[] v = factory.getVerticalProject();
            for (int i = 0; i < v.Length; i++)
            {
                if (v[i] > 0)
                {
                    _regionfillStartWithVertical = i;
                    break;
                }
            }

            for (int i = v.Length - 1; i >= 0; i--)
            {
                if (v[i] > 0)
                {
                    _regionfillEndWithVertical = i + 1;
                    break;
                }
            }

            int[] h = factory.getHorizontalProject();
            for (int i = 0; i < v.Length; i++)
            {
                if (h[i] > 0)
                {
                    _regionfillStartWithHorizontal = i;
                    break;
                }
            }

            for (int i = h.Length - 1; i >= 0; i--)
            {
                if (h[i] > 0)
                {
                    _regionfillEndWithHorizontal = i + 1;
                    break;
                }
            }
        }
        private void projectionTest(Chart VerticalChart, Chart HorizontalChart, Bitmap img)
        {
            HorizontalChart.Series["Series1"].IsVisibleInLegend   = false;
            HorizontalChart.Series["Series1"].IsValueShownAsLabel = false;
            VerticalChart.Series["Series1"].IsVisibleInLegend     = false;
            VerticalChart.Series["Series1"].IsValueShownAsLabel   = false;


            ProjectionFactory factory = new ProjectionFactory(img);

            factory.Threshold = (int)numericUpDown1.Value;
            int[] horizontalProjection = factory.getHorizontalProject();
            int[] verticalProjection   = factory.getVerticalProject();
            for (int i = 0; i < horizontalProjection.Length; i++)
            {
                HorizontalChart.Series["Series1"].Points.AddXY(i, horizontalProjection[i]);
            }
            for (int i = 0; i < verticalProjection.Length; i++)
            {
                VerticalChart.Series["Series1"].Points.AddXY(i, verticalProjection[i]);
            }
        }
Exemple #14
0
        public void Do(InputArg inArg)
        {
            CheckAtg(inArg);
            string    projectionIdentify = inArg.ProjectionIdentify;
            OutputArg outArg             = new OutputArg();

            try
            {
                using (AbstractWarpDataset inputRaster = WarpDataset.Open(inArg.InputFilename))
                {
                    RasterDatasetInfo dsInfo =
                        mRasterSourceManager.GetInstance().GetRasterDatasetInfo(inArg.InputFilename);
                    DateTime?    dateTime     = mRasterSourceManager.GetInstance().GetImageTime(inArg.InputFilename);
                    DataIdentify dataIdentify = new DataIdentify();
                    outArg.OrbitFilename      = Path.GetFileName(inArg.InputFilename);
                    outArg.Satellite          = dsInfo.SatelliteID;
                    outArg.Sensor             = dsInfo.SensorID;
                    outArg.Level              = "L1";
                    outArg.ProjectionIdentify = projectionIdentify;
                    outArg.ObservationDate    = dateTime.HasValue ? dateTime.Value.ToString("yyyyMMdd") : "";
                    outArg.ObservationTime    = dateTime.HasValue ? dateTime.Value.ToString("HHmm") : "";
                    outArg.Station            = ParseStation(Path.GetFileName(inArg.InputFilename));
                    outArg.DayOrNight         = DayOrNight(inputRaster);
                    if (dateTime.HasValue)
                    {
                        outArg.OrbitIdentify = CalcOrbitIdentify(dateTime.Value, inArg.PervObservationDate,
                                                                 inArg.PervObservationTime, inArg.OrbitIdentify);
                    }
                    outArg.Length = new FileInfo(inArg.InputFilename).Length;
                    string validEnvelopeMsg = "";

                    #region 日夜检查

                    if (!string.IsNullOrWhiteSpace(inArg.DayNight))
                    {
                        if (inArg.DayNight != "daynight" && outArg.DayOrNight == "X")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "未设定处理白天和晚上数据,白天晚上标记未知:X";
                        }
                        else if (inArg.DayNight == "day" && outArg.DayOrNight != "D")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为只处理白天数据,当前数据标记为晚上";
                        }
                        else if (inArg.DayNight == "night" && outArg.DayOrNight != "N")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为只处理晚上数据,当前数据标记为白天";
                        }
                        else if (inArg.DayNight == "notnight" && outArg.DayOrNight == "N")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为不处理晚上数据,当前数据标记为晚上";
                        }
                        else if (inArg.DayNight == "notday" && outArg.DayOrNight == "D")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为不处理白天数据,当前数据标记为白天";
                        }
                    }

                    #endregion 日夜检查

                    if (inArg.ValidEnvelopes == null || inArg.ValidEnvelopes.Length == 0)
                    {
                        outArg.LogLevel = "error";
                        outArg.LogInfo  = "参数错误:未正确设置ValidEnvelopes";
                    }
                    else if (!ValidEnvelope(inputRaster, inArg.ValidEnvelopes, out validEnvelopeMsg))
                    {
                        outArg.LogLevel = "info";
                        outArg.LogInfo  = validEnvelopeMsg;
                    }
                    else
                    {
                        PrjOutArg prjArg;
                        if (inArg.Envelopes == null || inArg.Envelopes.Length == 0)
                        {
                            prjArg = new PrjOutArg(projectionIdentify, null, inArg.ResolutionX, inArg.ResolutionY,
                                                   inArg.OutputDir);
                        }
                        else
                        {
                            prjArg = new PrjOutArg(projectionIdentify, inArg.Envelopes, inArg.ResolutionX,
                                                   inArg.ResolutionY, inArg.OutputDir);
                        }
                        //prjArg.Args = new string[] { "SolarZenith"};
                        if (inArg.Bands != null && inArg.Bands.Length != 0)
                        {
                            prjArg.SelectedBands = inArg.Bands;
                            Console.WriteLine("SelectedBands:" + string.Join(",", prjArg.SelectedBands));
                        }

                        //扩展参数
                        List <string> extArgs = new List <string>();
                        extArgs.Add("IsClearPrjCache");
                        if (inArg.ExtArgs != null)
                        {
                            extArgs.AddRange(inArg.ExtArgs);
                        }
                        prjArg.Args = extArgs.ToArray();
                        ProjectionFactory prjFactory = new ProjectionFactory();
                        string            retMessage = "";
                        string[]          files      = prjFactory.Project(inputRaster, prjArg, new Action <int, string>(OnProgress),
                                                                          out retMessage);
                        prjFactory = null;
                        //投影结束,执行拼接,如果有拼接节点
                        List <OutFileArg> fileArgs = new List <OutFileArg>();
                        for (int i = 0; i < files.Length; i++)
                        {
                            string file = files[i];
                            if (string.IsNullOrWhiteSpace(file) || !File.Exists(file))
                            {
                                continue;
                            }
                            OutFileArg fileArg = new OutFileArg();
                            Envelope   env     = null;
                            float      resolutionX;
                            float      resolutionY;
                            string     overViewFilename = "";
                            using (AbstractWarpDataset outfileRaster = WarpDataset.Open(file))
                            {
                                Console.WriteLine("生成缩略图开始");
                                overViewFilename = OverViewHelper.OverView(outfileRaster, _prjPngSize);
                                Console.WriteLine("生成缩略图结束");
                                env         = outfileRaster.GetEnvelope();
                                resolutionX = outfileRaster.ResolutionX;
                                resolutionY = outfileRaster.ResolutionY;
                                var dt = dateTime.HasValue ? dateTime.Value : DateTime.Now;
                                TryMosaicFile(inArg, outfileRaster, dsInfo, dt, outArg.DayOrNight);
                            }

                            fileArg.OutputFilename = Path.GetFileName(file);
                            fileArg.Thumbnail      =
                                (string.IsNullOrWhiteSpace(overViewFilename) && File.Exists(overViewFilename)
                                    ? ""
                                    : Path.GetFileName(overViewFilename));
                            string solarZenithFile = Path.Combine(Path.GetDirectoryName(file),
                                                                  Path.GetFileNameWithoutExtension(file) + ".SolarZenith.ldf");
                            string solarZenithHdrFile = Path.Combine(Path.GetDirectoryName(file),
                                                                     Path.GetFileNameWithoutExtension(file) + ".SolarZenith.hdr");
                            fileArg.ExtendFiles = Path.ChangeExtension(Path.GetFileName(file), "hdr") +
                                                  (string.IsNullOrWhiteSpace(solarZenithFile) &&
                                                   File.Exists(solarZenithFile)
                                                      ? ""
                                                      : "," + Path.GetFileName(solarZenithFile)) +
                                                  (string.IsNullOrWhiteSpace(solarZenithHdrFile) &&
                                                   File.Exists(solarZenithHdrFile)
                                                      ? ""
                                                      : "," + Path.GetFileName(solarZenithHdrFile));
                            fileArg.Envelope = new PrjEnvelopeItem("GBAL",
                                                                   env == null
                                    ? null
                                    : new RasterProject.PrjEnvelope(env.MinX, env.MaxX, env.MinY, env.MaxY,
                                                                    SpatialReferenceFactory.CreateSpatialReference(4326)));
                            fileArg.ResolutionX = resolutionX.ToString();
                            fileArg.ResolutionY = resolutionY.ToString();
                            fileArg.Length      = new FileInfo(file).Length;
                            fileArgs.Add(fileArg);
                            if (inArg.IsOnlySaveMosaicFile)
                            {
                                TryDeleteFile(file);
                            }
                        }

                        outArg.OutputFiles = fileArgs.ToArray();
                        outArg.LogLevel    = "info";
                        if (string.IsNullOrWhiteSpace(retMessage))
                        {
                            outArg.LogInfo = "投影成功";
                        }
                        else
                        {
                            outArg.LogInfo = retMessage;
                        }
                        if (string.IsNullOrWhiteSpace(validEnvelopeMsg))
                        {
                            outArg.LogInfo = outArg.LogInfo + validEnvelopeMsg;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                outArg.LogLevel = "error";
                Console.WriteLine(ex.StackTrace);
                outArg.LogInfo = ex.Message + ex.StackTrace;
                Console.WriteLine("PIE.Meteo.ProjectTool.Execute()", ex);
            }
            finally
            {
                //输出参数文件重新命名
                string inputFileName = Path.GetFileName(inArg.InputFilename);

                System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"_\d{4}M");
                if (rex.IsMatch(inputFileName))
                {
                    string oldResStr = rex.Match(inputFileName).Groups[0].Value;
                    if (inArg.ProjectionIdentify == "GLL")
                    {
                        inputFileName = inputFileName.Replace(oldResStr,
                                                              $"_{PrjFileName.GLLResolutionIdentify(inArg.ResolutionX)}");
                    }
                    else
                    {
                        inputFileName = inputFileName.Replace(oldResStr,
                                                              $"_{PrjFileName.ResolutionIdentify(inArg.ResolutionX)}");
                    }
                }

                string outXmlFilename = Path.Combine(inArg.OutputDir, inputFileName + ".xml");
                OutputArg.WriteXml(outArg, outXmlFilename);
            }
        }
        private static ProjectionType[] GetProjectionTypes(Type[] interfaces, ProjectionFactory factory)
        {
            var baseTypes = new ProjectionType[interfaces.Length];

            for (var i = 0; i < interfaces.Length; i++)
            {
                var baseType = baseTypes[i] =
                    factory.GetProjectionTypeUnsafe(interfaces[i])
                    as ProjectionStructureType;
                if (baseType == null)
                    throw Error.InvalidProjectionType(interfaces[i]);
            }

            return baseTypes;
        }
Exemple #16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="argument">格式"*#*"冒号前面部分表示文件名称,冒号后面部分表示所选投影坐标的Wkt格式字符串</param>
 public override void Execute(string argument)
 {
     try
     {
         string            fileName = "";
         ISpatialReference proj     = null;
         GeoDo.RSS.Core.DrawEngine.CoordEnvelope[] envelopes;
         fileName = TryCheckArgsEnvironment(out envelopes);
         proj     = SpatialReference.GetDefault();
         List <PrjEnvelopeItem> lstEnvelope = new List <PrjEnvelopeItem>();
         for (int i = 0; i < envelopes.Length; i++)
         {
             GeoDo.RSS.Core.DrawEngine.CoordEnvelope env = envelopes[i];
             if (env.IsEmpty())
             {
                 throw new Exception("获得的感兴趣区域是空值:" + env.ToString());
             }
             PrjEnvelope prjEnv = new PrjEnvelope(env.MinX, env.MaxX, env.MinY, env.MaxY);
             lstEnvelope.Add(new PrjEnvelopeItem("AOI", prjEnv));
         }
         if (string.IsNullOrWhiteSpace(fileName))
         {
             throw new Exception("无法从参数中解析出文件名:" + argument);
         }
         string               errorMsg;
         string[]             outFiles        = null;
         IProgressMonitor     progressMonitor = null;
         Action <int, string> progress        = null;
         try
         {
             progressMonitor = _smartSession.ProgressMonitorManager.DefaultProgressMonitor;
             progress        = new Action <int, string>(
                 (int progerss, string text) =>
             {
                 if (progressMonitor != null)
                 {
                     progressMonitor.Boost(progerss, text);
                 }
             });
             if (progressMonitor != null)
             {
                 progressMonitor.Reset("", 100);
                 progressMonitor.Start(false);
                 progressMonitor.Boost(0, "准备文件");
             }
             string    outdir    = GetOutDirFromConfig(fileName);
             PrjOutArg prjOutArg = new PrjOutArg(proj, lstEnvelope.ToArray(), 0, 0, outdir);
             //添加对自定义感兴趣区的支持。
             ProjectionFactory quick = new ProjectionFactory();
             outFiles = quick.Project(fileName, prjOutArg, progress, out errorMsg);
         }
         finally
         {
             if (progressMonitor != null)
             {
                 progressMonitor.Finish();
             }
             progress = null;
         }
         if (outFiles != null && outFiles.Length != 0)
         {
             for (int i = 0; i < outFiles.Length; i++)
             {
                 if (!string.IsNullOrWhiteSpace(outFiles[i]))
                 {
                     OpenFileToWindows(outFiles[i]);
                 }
             }
         }
         if (errorMsg != null && errorMsg.Length != 0)
         {
             MsgBox.ShowInfo(errorMsg);
         }
     }
     catch (Exception ex)
     {
         MsgBox.ShowInfo(ex.Message);
     }
 }
Exemple #17
0
 private void GetOverview(IRasterDataProvider file, ISpatialReference spatialRef, int[] bandNos, out Bitmap bmp, out string errorMessage)
 {
     try
     {
         errorMessage = "";
         if (bandNos == null)
         {
             bandNos = new int[] { 1 }
         }
         ;
         if (!File.Exists(_prjFilename))
         {
             float resolution = 0.05f;
             if (file.DataIdentify != null && file.DataIdentify.Sensor == "VISSR")
             {
                 resolution = 0.1f;
             }
             if (file.DataIdentify != null && (file.DataIdentify.Satellite == "FY1D"))
             {
                 resolution = 0.1f;
             }
             PrjOutArg arg = new PrjOutArg(spatialRef, null, resolution, resolution, _prjFilename);
             arg.SelectedBands = bandNos.OrderBy((i) => { return(i); }).ToArray();
             ProjectionFactory proj  = new ProjectionFactory();
             string[]          files = proj.Project(file, arg, null, out errorMessage);
             if (files == null || files.Length == 0 || files[0] == null)
             {
                 bmp = null;
                 if (string.IsNullOrWhiteSpace(errorMessage))
                 {
                     errorMessage = "投影缩略图文件失败";
                 }
                 return;
             }
             _prjFilename = files[0];
         }
         using (IRasterDataProvider prd = GeoDataDriver.Open(_prjFilename) as IRasterDataProvider)
         {
             if (bandNos == null || bandNos.Length == 0)
             {
                 bandNos = prd.GetDefaultBands();
             }
             if (bandNos == null || bandNos.Length == 0)
             {
                 bmp = null;
                 if (string.IsNullOrWhiteSpace(errorMessage))
                 {
                     errorMessage = "获取缩略图显示波段列表为空";
                 }
                 return;
             }
             //bandNos = new int[] { 1, 1, 1 };
             int[]     orderBandMaps;
             PrjBand[] prjBands = BandNoToBand(bandNos, out orderBandMaps);
             bmp = GenerateOverview(prd, orderBandMaps);
         }
     }
     catch
     {
         bmp = null;
         throw;
     }
 }
Exemple #18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="argument">
 /// 格式"*#*"冒号前面部分表示文件名称,冒号后面部分表示所选投影坐标的Wkt格式字符串
 /// </param>
 public override void Execute(string argument)
 {
     try
     {
         string            fileName  = "";
         string            prjString = "";
         ISpatialReference proj      = null;
         if (string.IsNullOrWhiteSpace(argument))
         {
             fileName = TryGetFileFromActiveView();
             proj     = SpatialReference.GetDefault();
         }
         else
         {
             MatchCollection matches = Regex.Matches(argument, @"(?<file>[^#]*)#(?<proj>.*)");
             fileName  = matches[0].Groups["file"].Value;
             prjString = matches[0].Groups["proj"].Value;
             if (string.IsNullOrWhiteSpace(fileName) || fileName.ToLower() == "null")
             {
                 fileName = TryGetFileFromActiveView();
             }
             if (string.IsNullOrWhiteSpace(prjString) || prjString.ToLower() == "null")
             {
                 proj = SpatialReference.GetDefault();
             }
             else
             {
                 proj = SpatialReference.FromWkt(prjString, enumWKTSource.EsriPrjFile);
             }
         }
         if (string.IsNullOrWhiteSpace(fileName))
         {
             throw new Exception("无法从参数中解析出文件名:" + argument);
         }
         IProgressMonitor  progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor;
         ProjectionFactory quick    = new ProjectionFactory();
         string            errorMsg;
         string[]          outFiles = null;
         try
         {
             _progressMonitor = _smartSession.ProgressMonitorManager.DefaultProgressMonitor;
             if (_progressMonitor != null)
             {
                 _progressMonitor.Reset("", 100);
                 _progressMonitor.Start(false);
                 _progressMonitor.Boost(0, "准备文件");
             }
             PrjOutArg prjOutArg = new PrjOutArg(proj, null, 0, 0, Path.GetDirectoryName(fileName));
             outFiles = quick.Project(fileName, prjOutArg, new Action <int, string>(OnProgress), out errorMsg);
         }
         finally
         {
             if (_progressMonitor != null)
             {
                 _progressMonitor.Finish();
             }
         }
         if (outFiles != null && outFiles.Length != 0)
         {
             for (int i = 0; i < outFiles.Length; i++)
             {
                 if (!string.IsNullOrWhiteSpace(outFiles[i]))
                 {
                     OpenFileToWindows(outFiles[i]);
                 }
             }
         }
         if (errorMsg != null && errorMsg.Length != 0)
         {
             MsgBox.ShowInfo(errorMsg);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Exemple #19
0
 //: base(factory)
 internal ProjectionType(Type type, TypeKind kind, ProjectionFactory factory)
 {
     this.type    = type;
     this.kind    = kind;
     this.factory = factory;
 }
 internal ProjectionArrayType(Type type, ProjectionFactory factory)
     : base(TypeKind.Array, type, factory)
 {
 }
Exemple #21
0
        public void Do(InputArg inArg)
        {
            CheckAtg(inArg);
            string    projectionIdentify = inArg.ProjectionIdentify;
            OutputArg outArg             = new OutputArg();

            try
            {
                using (IRasterDataProvider inputRaster = GeoDataDriver.Open(inArg.InputFilename) as IRasterDataProvider)
                {
                    DataIdentify dataIdentify = inputRaster.DataIdentify;
                    outArg.OrbitFilename      = Path.GetFileName(inArg.InputFilename);
                    outArg.Satellite          = dataIdentify.Satellite;
                    outArg.Sensor             = dataIdentify.Sensor;
                    outArg.Level              = "L1";
                    outArg.ProjectionIdentify = projectionIdentify;
                    outArg.ObservationDate    = dataIdentify.OrbitDateTime.ToString("yyyyMMdd");
                    outArg.ObservationTime    = dataIdentify.OrbitDateTime.ToString("HHmm");
                    outArg.Station            = ParseStation(Path.GetFileName(inArg.InputFilename));
                    outArg.DayOrNight         = DayOrNight(inputRaster);
                    outArg.OrbitIdentify      = CalcOrbitIdentify(dataIdentify.OrbitDateTime, inArg.PervObservationDate, inArg.PervObservationTime, inArg.OrbitIdentify);
                    outArg.Length             = new FileInfo(inArg.InputFilename).Length;
                    string validEnvelopeMsg = "";
                    if (!string.IsNullOrWhiteSpace(inArg.DayNight))
                    {
                        if (inArg.DayNight != "daynight" && outArg.DayOrNight == "X")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "未设定处理白天和晚上数据,白天晚上标记未知:X";
                        }
                        else if (inArg.DayNight == "day" && outArg.DayOrNight != "D")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为只处理白天数据,当前数据标记为晚上";
                        }
                        else if (inArg.DayNight == "night" && outArg.DayOrNight != "N")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为只处理晚上数据,当前数据标记为白天";
                        }
                        else if (inArg.DayNight == "notnight" && outArg.DayOrNight == "N")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为不处理晚上数据,当前数据标记为晚上";
                        }
                        else if (inArg.DayNight == "notday" && outArg.DayOrNight == "D")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为不处理白天数据,当前数据标记为白天";
                        }
                    }
                    if (inArg.ValidEnvelopes == null || inArg.ValidEnvelopes.Length == 0)
                    {
                        outArg.LogLevel = "error";
                        outArg.LogInfo  = "参数错误:未正确设置ValidEnvelopes";
                    }
                    else if (!ValidEnvelope(inputRaster, inArg.ValidEnvelopes, out validEnvelopeMsg))
                    {
                        outArg.LogLevel = "info";
                        outArg.LogInfo  = validEnvelopeMsg;
                    }
                    else
                    {
                        GenericFilename genFilenmae = new GenericFilename();
                        PrjOutArg       prjArg;
                        if (inArg.Envelopes == null || inArg.Envelopes.Length == 0)
                        {
                            prjArg = new PrjOutArg(projectionIdentify, null, inArg.ResolutionX, inArg.ResolutionY, inArg.OutputDir);
                        }
                        else
                        {
                            prjArg = new PrjOutArg(projectionIdentify, inArg.Envelopes, inArg.ResolutionX, inArg.ResolutionY, inArg.OutputDir);
                        }
                        //prjArg.Args = new string[] { "SolarZenith"};
                        if (inArg.Bands != null && inArg.Bands.Length != 0)
                        {
                            prjArg.SelectedBands = inArg.Bands;
                            Console.WriteLine("SelectedBands:" + string.Join(",", prjArg.SelectedBands));
                        }
                        //扩展参数
                        List <string> extArgs = new List <string>();
                        extArgs.Add("IsClearPrjCache");
                        if (inArg.ExtArgs != null)
                        {
                            extArgs.AddRange(inArg.ExtArgs);
                        }
                        prjArg.Args = extArgs.ToArray();
                        ProjectionFactory prjFactory = new ProjectionFactory();
                        string            retMessage = "";
                        string[]          files      = prjFactory.Project(inputRaster, prjArg, new Action <int, string>(OnProgress), out retMessage);
                        prjFactory = null;
                        //投影结束,执行拼接,如果有拼接节点
                        List <OutFileArg> fileArgs = new List <OutFileArg>();
                        for (int i = 0; i < files.Length; i++)
                        {
                            string file = files[i];
                            if (string.IsNullOrWhiteSpace(file) || !File.Exists(file))
                            {
                                continue;
                            }
                            OutFileArg    fileArg = new OutFileArg();
                            CoordEnvelope env     = null;
                            float         resolutionX;
                            float         resolutionY;
                            string        overViewFilename = "";
                            using (IRasterDataProvider outfileRaster = GeoDataDriver.Open(file) as IRasterDataProvider)
                            {
                                overViewFilename = OverViewHelper.OverView(outfileRaster, _prjPngSize);
                                env         = outfileRaster.CoordEnvelope;
                                resolutionX = outfileRaster.ResolutionX;
                                resolutionY = outfileRaster.ResolutionY;
                                TryMosaicFile(inArg, outfileRaster, dataIdentify, outArg.DayOrNight);
                            }
                            fileArg.OutputFilename = Path.GetFileName(file);
                            fileArg.Thumbnail      = (string.IsNullOrWhiteSpace(overViewFilename) && File.Exists(overViewFilename) ? "" : Path.GetFileName(overViewFilename));
                            string solarZenithFile    = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".SolarZenith.ldf");
                            string solarZenithHdrFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".SolarZenith.hdr");
                            fileArg.ExtendFiles = Path.ChangeExtension(Path.GetFileName(file), "hdr") +
                                                  (string.IsNullOrWhiteSpace(solarZenithFile) && File.Exists(solarZenithFile) ? "" : "," + Path.GetFileName(solarZenithFile)) +
                                                  (string.IsNullOrWhiteSpace(solarZenithHdrFile) && File.Exists(solarZenithHdrFile) ? "" : "," + Path.GetFileName(solarZenithHdrFile));
                            fileArg.Envelope    = new PrjEnvelopeItem("GBAL", env == null ? null : new RasterProject.PrjEnvelope(env.MinX, env.MaxX, env.MinY, env.MaxY));
                            fileArg.ResolutionX = resolutionX.ToString();
                            fileArg.ResolutionY = resolutionY.ToString();
                            fileArg.Length      = new FileInfo(file).Length;
                            fileArgs.Add(fileArg);
                            if (inArg.IsOnlySaveMosaicFile)
                            {
                                TryDeleteFile(file);
                            }
                        }
                        outArg.OutputFiles = fileArgs.ToArray();
                        outArg.LogLevel    = "info";
                        if (string.IsNullOrWhiteSpace(retMessage))
                        {
                            outArg.LogInfo = "投影成功";
                        }
                        else
                        {
                            outArg.LogInfo = retMessage;
                        }
                        if (string.IsNullOrWhiteSpace(validEnvelopeMsg))
                        {
                            outArg.LogInfo = outArg.LogInfo + validEnvelopeMsg;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                outArg.LogLevel = "error";
                outArg.LogInfo  = ex.Message;
                LogFactory.WriteLine(ex);
            }
            finally
            {
                string outXmlFilename = Path.Combine(inArg.OutputDir, Path.GetFileName(inArg.InputFilename) + ".xml");
                OutputArg.WriteXml(outArg, outXmlFilename);
            }
        }
 internal ProjectionListType(Type type, ProjectionFactory factory)
     : base(TypeKind.List, type, factory)
 {
 }
 internal ProjectionSetType(Type type, ProjectionFactory factory)
     : base(TypeKind.Set, type, factory)
 {
 }
 internal ProjectionOpaqueType(Type type, ProjectionFactory factory)
     : base(type, TypeKind.Opaque, factory)
 {
     factory.RegisterProjectionType(this);
 }
 internal ProjectionDictionaryType(Type type, ProjectionFactory factory)
     : base(TypeKind.Dictionary, type, factory)
 {
 }
Exemple #26
0
        public IRasterDataProvider[] DoProject(PrjOutArg prjArgs, MosaicType mosaicType, Action <int, string> progressCallback, out string msg)
        {
            ProjectionFactory proj = new ProjectionFactory();

            msg = "";
            TryCreateOutDir(prjArgs.OutDirOrFile);
            StringBuilder   str            = new StringBuilder();
            List <string[]> projectedFiles = new List <string[]>();

            for (int fileIndex = 0; fileIndex < _fileItems.Count; fileIndex++)
            {
                string            errMessage;
                MosaicProjectItem item = _fileItems[fileIndex];
                if (item == null || item.MainFile == null)
                {
                    continue;
                }
                string file        = item.MainFile.fileName;
                string outfilename = "";
                if (mosaicType != MosaicType.NoMosaic &&
                    !IsDir(prjArgs.OutDirOrFile) && _fileItems.Count > 1)
                {
                    outfilename          = prjArgs.OutDirOrFile;
                    prjArgs.OutDirOrFile = Path.GetDirectoryName(outfilename) + "\\" + Guid.NewGuid().ToString() + Path.GetExtension(outfilename);
                }
                string[] files = proj.Project(file, prjArgs, progressCallback, out errMessage);
                if (!string.IsNullOrWhiteSpace(outfilename))
                {
                    prjArgs.OutDirOrFile = outfilename;
                }
                if (!string.IsNullOrWhiteSpace(errMessage))
                {
                    str.AppendLine(Path.GetFileName(file) + errMessage);
                }
                if (files == null || files.Length == 0)
                {
                    continue;
                }
                if (files.Length == 1 && files[0] == null)
                {
                    continue;
                }
                projectedFiles.Add(files);
            }
            msg = str.ToString();
            if (projectedFiles.Count == 0)
            {
                return(null);
            }
            if (projectedFiles.Count == 1 && projectedFiles[0] == null)
            {
                return(null);
            }
            int envCount = prjArgs.Envelopes == null ? 1 : prjArgs.Envelopes.Length;

            IRasterDataProvider[]      retEnvFiles         = new IRasterDataProvider[envCount];
            List <IRasterDataProvider> retEnvFilesNoMosaic = new List <IRasterDataProvider>();

            for (int i = 0; i < envCount; i++)
            {
                List <string> envFiles = new List <string>();
                for (int j = 0; j < _fileItems.Count; j++)
                {
                    if (j >= projectedFiles.Count)
                    {
                        break;
                    }
                    if (projectedFiles[j] != null && projectedFiles[j].Length > i)
                    {
                        if (projectedFiles[j] == null || projectedFiles[j].Length == 0 || string.IsNullOrWhiteSpace(projectedFiles[j][i]))
                        {
                            continue;
                        }
                        envFiles.Add(projectedFiles[j][i]);
                    }
                }
                //by chennan 批量分幅投影
                if (mosaicType != MosaicType.NoMosaic)
                {
                    if (envFiles.Count > 1)
                    {
                        List <IRasterDataProvider> mosaicFiles = new List <IRasterDataProvider>();
                        try
                        {
                            foreach (string envfile in envFiles)
                            {
                                IRasterDataProvider file = FileHelper.Open(envfile);
                                mosaicFiles.Add(file);
                            }
                            string mosaicFile = null;
                            if (prjArgs == null || string.IsNullOrWhiteSpace(prjArgs.OutDirOrFile))
                            {
                                string outDir = Path.GetDirectoryName(mosaicFiles[0].fileName);
                                mosaicFile = Path.Combine(outDir, Path.GetFileNameWithoutExtension(mosaicFiles[0].fileName) + "_MOSAIC.ldf");
                            }
                            else
                            {
                                if (IsDir(prjArgs.OutDirOrFile))
                                {
                                    mosaicFile = Path.Combine(prjArgs.OutDirOrFile, Path.GetFileNameWithoutExtension(mosaicFiles[0].fileName) + "_MOSAIC.ldf");
                                }
                                else
                                {
                                    mosaicFile = prjArgs.OutDirOrFile;
                                }
                            }
                            RasterMoasicProcesser processer       = new RasterMoasicProcesser();
                            IRasterDataProvider   drcDataProvider = processer.Moasic(mosaicFiles.ToArray(), "LDF", mosaicFile, true, new string[] { "0" }, progressCallback);
                            //拼接角度文件
                            if (prjArgs.Args != null && prjArgs.Args.Length > 0)
                            {
                                foreach (object arg in prjArgs.Args)
                                {
                                    if (arg is string)
                                    {
                                        bool     isMoasic  = true;
                                        string[] extentStr = null;
                                        List <IRasterDataProvider> mosaicExtFile = new List <IRasterDataProvider>();
                                        List <string> extFileList = new List <string>();
                                        try
                                        {
                                            string extFileName;
                                            string extension;
                                            string argStr = arg as string;
                                            if (argStr.Contains("="))
                                            {
                                                argStr = argStr.Split('=')[1];
                                                if (argStr.Contains(";"))
                                                {
                                                    extentStr = argStr.Split(';');
                                                }
                                            }
                                            if (extentStr != null)
                                            {
                                                for (int extentIndex = 0; extentIndex < extentStr.Length; extentIndex++)
                                                {
                                                    argStr    = extentStr[extentIndex];
                                                    extension = "." + argStr + ".ldf";
                                                    for (int j = 0; j < envFiles.Count; j++)
                                                    {
                                                        extFileName = Path.ChangeExtension(envFiles[j], extension);
                                                        if (!File.Exists(extFileName))
                                                        {
                                                            isMoasic = false;
                                                            break;
                                                        }
                                                        else
                                                        {
                                                            isMoasic = true;
                                                        }
                                                        IRasterDataProvider file = FileHelper.Open(extFileName);
                                                        mosaicExtFile.Add(file);
                                                        extFileList.Add(extFileName);
                                                    }
                                                    if (isMoasic)
                                                    {
                                                        string outFileName = Path.ChangeExtension(mosaicFile, extension);
                                                        IRasterDataProvider drcExtDataProvider = processer.Moasic(mosaicExtFile.ToArray(), "LDF", outFileName, true, new string[] { "0" }, progressCallback);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                extension = "." + argStr + ".ldf";
                                                for (int j = 0; j < envFiles.Count; j++)
                                                {
                                                    extFileName = Path.ChangeExtension(envFiles[j], extension);
                                                    if (!File.Exists(extFileName))
                                                    {
                                                        isMoasic = false;
                                                        break;
                                                    }
                                                    IRasterDataProvider file = FileHelper.Open(extFileName);
                                                    mosaicExtFile.Add(file);
                                                    extFileList.Add(extFileName);
                                                }
                                                if (isMoasic)
                                                {
                                                    string outFileName = Path.ChangeExtension(mosaicFile, extension);
                                                    IRasterDataProvider drcExtDataProvider = processer.Moasic(mosaicExtFile.ToArray(), "LDF", outFileName, true, new string[] { "0" }, progressCallback);
                                                }
                                            }
                                        }
                                        finally
                                        {
                                            if (mosaicExtFile.Count > 0)
                                            {
                                                foreach (IRasterDataProvider file in mosaicExtFile)
                                                {
                                                    if (file != null)
                                                    {
                                                        file.Dispose();
                                                    }
                                                }
                                                mosaicExtFile.Clear();
                                            }
                                            if (extFileList.Count > 0)
                                            {
                                                foreach (string envfile in extFileList)
                                                {
                                                    TryDeleteRasterFile(envfile);
                                                }
                                                extFileList.Clear();
                                            }
                                        }
                                    }
                                }
                            }
                            retEnvFiles[i] = drcDataProvider;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        finally
                        {
                            foreach (IRasterDataProvider envfile in mosaicFiles)
                            {
                                if (envfile != null)
                                {
                                    envfile.Dispose();
                                }
                            }
                            mosaicFiles.Clear();
                            foreach (string envfile in envFiles)
                            {
                                TryDeleteRasterFile(envfile);
                            }
                        }
                    }
                    else if (envFiles.Count == 1)
                    {
                        if (!IsDir(prjArgs.OutDirOrFile) && !string.IsNullOrWhiteSpace(prjArgs.OutDirOrFile) && envFiles[0] != prjArgs.OutDirOrFile)
                        {
                            if (!Directory.Exists(Path.GetDirectoryName(prjArgs.OutDirOrFile)))
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(prjArgs.OutDirOrFile));
                            }
                            File.Copy(envFiles[0], prjArgs.OutDirOrFile);
                            TryDeleteRasterFile(envFiles[0]);
                            retEnvFiles[i] = FileHelper.Open(prjArgs.OutDirOrFile);
                        }
                        else
                        {
                            retEnvFiles[i] = FileHelper.Open(envFiles[0]);
                        }
                    }
                    else
                    {
                        retEnvFiles[i] = null;
                    }
                    //
                }
                else if (envFiles.Count != 0)
                {
                    List <IRasterDataProvider> mosaicFiles = new List <IRasterDataProvider>();
                    foreach (string envfile in envFiles)
                    {
                        IRasterDataProvider file = FileHelper.Open(envfile);
                        mosaicFiles.Add(file);
                    }
                    retEnvFilesNoMosaic.AddRange(mosaicFiles);
                }
            }
            //
            return(retEnvFilesNoMosaic.Count == 0 ? retEnvFiles : retEnvFilesNoMosaic.ToArray());
        }
Exemple #27
0
 /// <summary>
 /// 拼接
 /// 需要保证tFilename不存在。
 /// </summary>
 private void SpliceToFile()
 {
     using (IRasterDataProvider inputRaster = RasterDataDriver.Open(inArg.InputFilename) as IRasterDataProvider)
     {
         StringBuilder     str      = new StringBuilder();
         List <OutFileArg> outFiles = new List <OutFileArg>();
         string            logLevel = "info";
         foreach (PrjEnvelopeItem envItem in inArg.MosaicEnvelopes)
         {
             try
             {
                 if (!ProjectionFactory.HasInvildEnvelope(inputRaster, envItem.PrjEnvelope))
                 {
                     str.AppendLine("数据不在范围内:" + envItem.Name + envItem.PrjEnvelope.ToString());
                     continue;
                 }
                 string tFilename = GetSpliceFilename(inputRaster, inArg, envItem.Name);
                 tFilename = Path.Combine(inArg.OutputDir, tFilename);
                 if (!Directory.Exists(inArg.OutputDir))
                 {
                     Directory.CreateDirectory(inArg.OutputDir);
                 }
                 //文件不存在,直接复制当前文件为目标文件
                 if (!File.Exists(tFilename))
                 {
                     File.Copy(inArg.InputFilename, tFilename);
                     OutFileArg fileArg           = new OutFileArg();
                     string     tHdrFilename      = FilenameIdentify.HdrFileName(tFilename);
                     string     tOverviewFilename = FilenameIdentify.OverviewFileName(tFilename);
                     fileArg.Envelope       = new PrjEnvelopeItem(envItem.Name, CoordToEnvelope(inputRaster.CoordEnvelope));
                     fileArg.ResolutionX    = inputRaster.ResolutionX.ToString();
                     fileArg.ResolutionY    = inputRaster.ResolutionY.ToString();
                     fileArg.OutputFilename = tFilename;
                     fileArg.Length         = new FileInfo(tFilename).Length;
                     if (File.Exists(FilenameIdentify.HdrFileName(inArg.InputFilename)))
                     {
                         File.Copy(FilenameIdentify.HdrFileName(inArg.InputFilename), tHdrFilename);
                         fileArg.ExtendFiles = Path.GetFileName(tHdrFilename);
                     }
                     if (File.Exists(FilenameIdentify.OverviewFileName(inArg.InputFilename)))
                     {
                         File.Copy(FilenameIdentify.OverviewFileName(inArg.InputFilename), tOverviewFilename);
                         fileArg.Thumbnail = Path.GetFileName(tOverviewFilename);
                     }
                     else if (File.Exists(tFilename))
                     {
                         OnProgress(0, "生成缩略图");
                         tOverviewFilename = OverViewHelper.OverView(tFilename, _mosaicSize);
                         OnProgress(100, "完成缩略图");
                         fileArg.Thumbnail = Path.GetFileName(tOverviewFilename);
                     }
                     outFiles.Add(fileArg);
                 }
                 else
                 {
                     OutFileArg fileArg = SpliceToExistFile(inputRaster, tFilename);
                     fileArg.Envelope.Name = envItem.Name;
                     outFiles.Add(fileArg);
                 }
             }
             catch (Exception ex)
             {
                 logLevel = "error";
                 str.AppendLine("拼接区域失败:" + envItem.Name + envItem.PrjEnvelope.ToString());
                 str.AppendLine(" 输入文件:" + inArg.InputFilename);
                 str.AppendLine(" 详细信息:" + ex.Message);
                 GeoDo.Tools.LogFactory.WriteLine(ex);
             }
         }
         //写输出参数。
         MosaicOutputArg outArg = new MosaicOutputArg();
         outArg.InputFilename = Path.GetFileName(inArg.InputFilename);
         outArg.OutputFiles   = outFiles.ToArray();
         outArg.LogLevel      = logLevel;
         outArg.LogInfo       = str.ToString();
         string outXml = FilenameIdentify.OutPutXmlFilename(inArg.OutputDir, inArg.InputFilename);
         outArg.ToXml(outXml);
     }
 }
Exemple #28
0
 /// <summary>
 /// 镶嵌
 /// </summary>
 /// <returns></returns>
 private void MosaicToFile()
 {
     using (IRasterDataProvider inputRaster = RasterDataDriver.Open(inArg.InputFilename) as IRasterDataProvider)
     {
         StringBuilder     str      = new StringBuilder();
         List <OutFileArg> outFiles = new List <OutFileArg>();
         string            logLevel = "info";
         if (inArg.MosaicEnvelopes == null)
         {
             logLevel = "error";
             str.AppendLine("镶嵌(Mosaic)必须指定镶嵌输出范围");
             return;
         }
         else
         {
             for (int i = 0; i < inArg.MosaicEnvelopes.Length; i++)
             {
                 PrjEnvelopeItem envItem = inArg.MosaicEnvelopes[i];
                 try
                 {
                     if (envItem == null)
                     {
                         str.AppendLine("镶嵌(Mosaic)必须指定镶嵌输出范围");
                         continue;
                     }
                     if (!ProjectionFactory.HasInvildEnvelope(inputRaster, envItem.PrjEnvelope))
                     {
                         str.AppendLine("数据不在范围内:" + envItem.Name + envItem.PrjEnvelope.ToString());
                         continue;
                     }
                     string mosaicFilename = GetSpliceFilename(inputRaster, inArg, envItem.Name);
                     mosaicFilename = Path.Combine(inArg.OutputDir, mosaicFilename);
                     if (!Directory.Exists(inArg.OutputDir))
                     {
                         Directory.CreateDirectory(inArg.OutputDir);
                     }
                     //文件不存在,则需要先创建目标文件。
                     IRasterDataProvider mosaicRaster = null;
                     if (!File.Exists(mosaicFilename))
                     {
                         mosaicRaster = CreateMosaicFile(inputRaster, envItem.PrjEnvelope, mosaicFilename);
                     }
                     else
                     {
                         mosaicRaster = RasterDataDriver.Open(mosaicFilename, enumDataProviderAccess.Update, null) as IRasterDataProvider;
                     }
                     if (File.Exists(mosaicFilename))
                     {
                         OutFileArg fileArg = new OutFileArg();
                         try
                         {
                             Mosaic(inputRaster, mosaicRaster);
                             fileArg.Envelope       = new PrjEnvelopeItem(envItem.Name, envItem.PrjEnvelope);
                             fileArg.ResolutionX    = mosaicRaster.ResolutionX.ToString();
                             fileArg.ResolutionY    = mosaicRaster.ResolutionY.ToString();
                             fileArg.OutputFilename = mosaicFilename;
                             fileArg.Length         = new FileInfo(mosaicFilename).Length;
                         }
                         finally
                         {
                             if (mosaicRaster != null)
                             {
                                 mosaicRaster.Dispose();
                             }
                         }
                         try
                         {
                             string tHdrFilename      = FilenameIdentify.HdrFileName(mosaicFilename);
                             string tOverviewFilename = FilenameIdentify.OverviewFileName(mosaicFilename);
                             if (File.Exists(mosaicFilename))
                             {
                                 tOverviewFilename = OverViewHelper.OverView(mosaicFilename, _mosaicSize);
                                 fileArg.Thumbnail = Path.GetFileName(tOverviewFilename);
                             }
                             if (File.Exists(tHdrFilename))
                             {
                                 fileArg.ExtendFiles = Path.GetFileName(tHdrFilename);
                             }
                         }
                         catch (Exception ex)
                         {
                             str.AppendLine("拼接完成后,生成缩略图失败" + ex.Message);
                         }
                         outFiles.Add(fileArg);
                     }
                 }
                 catch (Exception ex)
                 {
                     logLevel = "error";
                     str.AppendLine("镶嵌区域失败:" + envItem.Name + envItem.PrjEnvelope.ToString());
                     str.AppendLine(" 输入文件:" + inArg.InputFilename);
                     str.AppendLine(" 详细信息:" + ex.Message);
                     GeoDo.Tools.LogFactory.WriteLine(ex);
                 }
                 finally
                 {
                 }
             }
         }
         //写输出参数。
         MosaicOutputArg outArg = new MosaicOutputArg();
         outArg.InputFilename = Path.GetFileName(inArg.InputFilename);
         outArg.OutputFiles   = outFiles.ToArray();
         outArg.LogLevel      = logLevel;
         outArg.LogInfo       = str.ToString();
         string outXml = FilenameIdentify.OutPutXmlFilename(inArg.OutputDir, inArg.InputFilename);
         outArg.ToXml(outXml);
     }
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="argument">
 /// 格式"*#*"冒号前面部分表示文件名称,冒号后面部分表示所选投影坐标的Wkt格式字符串
 /// </param>
 public override void Execute(string argument)
 {
     try
     {
         string            fileName  = "";
         string            prjString = "";
         ISpatialReference proj      = null;
         if (string.IsNullOrWhiteSpace(argument))
         {
             fileName = TryGetFileFromActiveView();
             proj     = SpatialReference.GetDefault();
         }
         else
         {
             MatchCollection matches = Regex.Matches(argument, @"(?<file>[^#]*)#(?<proj>.*)");
             fileName  = matches[0].Groups["file"].Value;
             prjString = matches[0].Groups["proj"].Value;
             if (string.IsNullOrWhiteSpace(fileName) || fileName.ToLower() == "null")
             {
                 fileName = TryGetFileFromActiveView();
             }
             if (string.IsNullOrWhiteSpace(prjString) || prjString.ToLower() == "null")
             {
                 proj = SpatialReference.GetDefault();
             }
             else
             {
                 proj = SpatialReference.FromWkt(prjString, enumWKTSource.EsriPrjFile);
             }
         }
         if (string.IsNullOrWhiteSpace(fileName))
         {
             throw new Exception("无法从参数中解析出文件名:" + argument);
         }
         PrjEnvelope envelope  = TryGetFirstAOI();
         PrjOutArg   prjOutArg = ProjectionFactory.GetDefaultArg(fileName);
         if (prjOutArg == null)
         {
             throw new Exception("暂未提供该支持");
         }
         if (envelope == null || envelope.IsEmpty)
         {
             envelope = prjOutArg.Envelopes[0] == null ? null : prjOutArg.Envelopes[0].PrjEnvelope;
         }
         if (envelope == null)
         {
             envelope = PrjEnvelope.CreateByCenter(105, 30, 10, 10);
         }
         //根据投影配置文件修改输出文件目录
         string outDir = null;
         if (TryGetOutDirFormConfig(out outDir))
         {
             prjOutArg.OutDirOrFile = outDir;
         }
         using (frmPrjEnvelopeSet frmPrjSetArgs = new frmPrjEnvelopeSet())
         {
             using (IRasterDataProvider file = FileHelper.Open(fileName))
             {
                 frmPrjSetArgs.SetDefault(file);
             }
             frmPrjSetArgs.SetArgs(proj, envelope, prjOutArg.ResolutionX, prjOutArg.ResolutionY, prjOutArg.OutDirOrFile);
             if (frmPrjSetArgs.ShowDialog() != DialogResult.OK)
             {
                 return;
             }
             prjOutArg = frmPrjSetArgs.PrjOutArg;
         }
         Project(fileName, proj, prjOutArg);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }