Beispiel #1
0
        private bool HandleDiskOutput(IDatasource ds, OutputLayerInfo outputInfo)
        {
            string filename = outputInfo.Filename;

            if (File.Exists(filename) && !outputInfo.Overwrite)
            {
                return(HandleOverwriteFailure());
            }

            bool result = SaveDatasource(ds, filename);

            ds.Dispose();
            outputInfo.Result = null;

            if (!result)
            {
                return(false);
            }

            outputInfo.DatasourcePointer = new DatasourcePointer(filename);

            if (outputInfo.AddToMap)
            {
                // don't report error if layer isn't added to the map
                // user might cancel it because of projection mismatch
                _layerService.AddLayersFromFilename(filename);
            }

            return(true);
        }
Beispiel #2
0
        private static bool SaveToTempDatasource(ITempFileService tempFileService, IDatasource ds)
        {
            // We can't the resulting shapefile directly, because it was created by background thread
            // therefore is located in another apartment. This will cause creation of proxies and marshalling
            // for COM, which in turn no always supported by implementation of particular classes in MapWinGIS.
            // Therefore the best option we have is to save into temp file, open it, read into memory, delete the source.
            string filename = tempFileService.GetTempFilename(".shp");
            bool   saved    = SaveDatasource(ds, filename);

            ds.Dispose();

            if (!saved)
            {
                Logger.Current.Warn("Failed to save datasource to temp file.");
                return(false);
            }

            return(true);
        }