private void FillFormatList() { PlugInManager compMan = new PlugInManager(); foreach (var dsType in compMan.GetPlugins(Plugins.Type.IDataset)) { IRasterFileDataset rds = compMan.CreateInstance <IDataset>(dsType) as IRasterFileDataset; if (rds == null) { continue; } foreach (string format in rds.SupportedFileFilter.Split('|')) { if (format == String.Empty) { continue; } int priority = rds.SupportsFormat(format.Replace("*", "")); //FormatListItem item = FindFormatItem(format); //if (item != null) //{ // if (item.Priority < priority) // { // item.Provider = rds.ToString(); // item.Priority = priority; // } //} //else //{ // lstFormats.Items.Add(new FormatListItem(format, rds.ToString(), priority)); //} lstFormats.Items.Add(new FormatListItem(format, rds.ToString(), priority, PlugInManager.PlugInID(rds))); } } }
async public Task <IRasterLayer> NextRasterLayer() { if (_cursor == null || _layer == null) { return(null); } try { while (true) { IFeature feature = await _cursor.NextFeature(); if (feature == null) { return(null); } IRasterLayer rLayer = null; double cell = Math.Max((double)feature["CELLX"], (double)feature["CELLY"]); int levels = (int)feature["LEVELS"], level = 0; if ((bool)feature["MANAGED"] && _layer._imageSpaceType == SqlFDBImageCatalogClass.ImageSpaceType.Database) { for (int l = 0; l < levels; l++) { if (cell * Math.Pow(2, l) < _pix) { level = l + 1; } else { break; } } if (level == 0 && levels > 0) { level = 1; } DataTable tab = await _layer._fdb.Select("ID,SHAPE", _layer._dsname + "_IMAGE_DATA", "IMAGE_ID=" + feature.OID + " AND LEV=" + level); if (tab == null) { continue; } foreach (DataRow row in tab.Rows) { byte[] obj = (byte[])row["SHAPE"]; BinaryReader r = new BinaryReader(new MemoryStream()); r.BaseStream.Write((byte[])obj, 0, ((byte[])obj).Length); r.BaseStream.Position = 0; Polygon polygon = new Polygon(); polygon.Deserialize(r, new GeometryDef(geometryType.Polygon, null, true)); r.Close(); if (gView.Framework.SpatialAlgorithms.Algorithm.IntersectBox(polygon, _dispEnvelope)) { SqlFDBImageDatasetImageClass rClass = new SqlFDBImageDatasetImageClass(_layer._fdb, _layer._dsname, (int)row["ID"], polygon); rLayer = new RasterLayer(rClass); rLayer.InterpolationMethod = _layer.InterpolationMethod; if (rClass.SpatialReference == null) { rClass.SpatialReference = _layer._sRef; } } } } else if (!(bool)feature["MANAGED"]) { if (feature["RF_PROVIDER"] == null || feature["RF_PROVIDER"] == DBNull.Value) { gView.DataSources.Raster.File.RasterFileDataset rDataset = new gView.DataSources.Raster.File.RasterFileDataset(); rLayer = rDataset.AddRasterFile((string)feature["PATH"], feature.Shape as IPolygon); } else { IRasterFileDataset rDataset = _layer._compMan.CreateInstance(new Guid(feature["RF_PROVIDER"].ToString())) as IRasterFileDataset; if (rDataset == null) { continue; } rLayer = rDataset.AddRasterFile((string)feature["PATH"], feature.Shape as IPolygon); } if (rLayer != null && rLayer.RasterClass != null) { rLayer.InterpolationMethod = _layer.InterpolationMethod; if (rLayer.RasterClass.SpatialReference == null) { rLayer.RasterClass.SpatialReference = _layer._sRef; } } } if (rLayer != null) { if (rLayer.Class is IGridClass) { IGridClass gridClass = (IGridClass)rLayer.Class; gridClass.ColorClasses = _layer.ColorClasses; gridClass.UseHillShade = _layer.UseHillShade; gridClass.HillShadeVector = _layer.HillShadeVector; gridClass.UseIgnoreDataValue = _layer.UseIgnoreDataValue; gridClass.IgnoreDataValue = _layer.IgnoreDataValue; gridClass.RenderRawGridValues = _layer.RenderRawGridValues; } return(rLayer); } } } catch { } return(null); }
private bool InsertImage(IFeatureUpdater fdb, IFeatureClass rasterFC, FileInfo fi, Dictionary <string, Guid> providers) { if (!_cancelTracker.Continue) { _errMsg = "Canceled by user..."; return(false); } if (ReportAction != null) { ReportAction(this, "Insert Image: " + fi.FullName); } if (ReportProgress != null) { ReportProgress(this, 1); } System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Jpeg; switch (fi.Extension.ToLower()) { case ".png": format = System.Drawing.Imaging.ImageFormat.Png; break; case ".tif": case ".tiff": format = System.Drawing.Imaging.ImageFormat.Tiff; break; } #region RasterFileDataset bestimmen List <IRasterFileDataset> rFileDatasets = new List <IRasterFileDataset>(); IRasterFileDataset rFileDataset = null; IRasterLayer rasterLayer = null; PlugInManager compMan = new PlugInManager(); foreach (XmlNode ds in compMan.GetPluginNodes(Plugins.Type.IDataset)) { IRasterFileDataset rds = compMan.CreateInstance(ds) as IRasterFileDataset; if (rds == null) { continue; } if (rds.SupportsFormat(fi.Extension) < 0) { continue; } if (providers != null && providers.ContainsKey(fi.Extension.ToLower())) { if (!providers[fi.Extension.ToLower()].Equals(PlugInManager.PlugInID(rds))) { continue; } } rFileDatasets.Add(rds); } if (rFileDatasets.Count == 0) { _errMsg = "No Rasterfile Provider for " + fi.Extension; return(false); } // RasterFileDataset nach priorität sortieren rFileDatasets.Sort(new RasterFileDatasetComparer(fi.Extension)); // RasterFileDataset suchen, mit dem sich Bild öffnen läßt foreach (IRasterFileDataset rfd in rFileDatasets) { rfd.AddRasterFile(fi.FullName); if (rfd.Elements.Count == 0) { //Console.WriteLine(_errMsg = fi.FullName + " is not a valid Raster File..."); continue; } IDatasetElement element = rfd.Elements[0]; if (!(element is IRasterLayer)) { //Console.WriteLine(_errMsg = fi.FullName + " is not a valid Raster Layer..."); rFileDataset.Dispose(); continue; } // gefunden... rasterLayer = (IRasterLayer)element; rFileDataset = rfd; break; } if (rasterLayer == null || rFileDataset == null) { Console.WriteLine(_errMsg = fi.FullName + " is not a valid Raster Layer..."); return(false); } #endregion FileInfo fiWorld = null; double cellX = 1; double cellY = 1; IRasterFile rasterFile = null; if (rasterLayer is IRasterFile) { rasterFile = (IRasterFile)rasterLayer; } if (rasterLayer.RasterClass != null) { if (rasterLayer.RasterClass is IRasterFile && ((IRasterFile)rasterLayer.RasterClass).WorldFile != null) { rasterFile = (IRasterFile)rasterLayer.RasterClass; } else { IRasterClass c = (IRasterClass)rasterLayer.RasterClass; cellX = Math.Sqrt(c.dx1 * c.dx1 + c.dx2 * c.dx2); cellY = Math.Sqrt(c.dy1 * c.dy1 + c.dy2 * c.dy2); } } if (rasterFile != null) { try { IRasterWorldFile world = rasterFile.WorldFile; if (world != null) { if (!world.isGeoReferenced) { if (handleNonGeorefAsError) { _errMsg = "Can't add non georeferenced images: " + fi.FullName; return(false); } else { return(true); } } cellX = Math.Sqrt(world.dx_X * world.dx_X + world.dx_Y * world.dx_Y); cellY = Math.Sqrt(world.dy_X * world.dy_X + world.dy_Y * world.dy_Y); fiWorld = new FileInfo(rasterFile.WorldFile.Filename); if (!fiWorld.Exists) { fiWorld = null; } } } catch { fiWorld = null; } } #region Check if already Exits // // Suchen, ob Image mit gleichen Pfad schon vorhanden ist, wenn ja // nur weitermachen, wenn sich das änderungsdatum unterscheidet... // QueryFilter filter = new QueryFilter(); filter.AddField("FDB_OID"); filter.AddField("PATH"); filter.AddField("LAST_MODIFIED"); filter.AddField("PATH2"); filter.AddField("LAST_MODIFIED2"); string fullName = fi.FullName.Replace(@"\", @"\\"); if (_fdb is AccessFDB) { filter.WhereClause = ((AccessFDB)_fdb).DbColName("PATH") + "='" + fullName + "'"; } else { filter.WhereClause = "PATH='" + fullName + "'"; } int deleteOID = -1; using (IFeatureCursor cursor = rasterFC.GetFeatures(filter)) { IFeature existingFeature = cursor.NextFeature; if (existingFeature != null) { DateTime dt1 = (DateTime)existingFeature["LAST_MODIFIED"]; if (Math.Abs(((TimeSpan)(dt1 - fi.LastWriteTimeUtc)).TotalSeconds) > 1.0) { deleteOID = existingFeature.OID; } else if (fiWorld != null && existingFeature["PATH2"] != System.DBNull.Value && existingFeature["PATH2"].ToString() != String.Empty) { DateTime dt2 = (DateTime)existingFeature["LAST_MODIFIED2"]; if (existingFeature["PATH2"].ToString().ToLower() != fiWorld.FullName.ToLower() || Math.Abs(((TimeSpan)(dt2 - fiWorld.LastWriteTimeUtc)).TotalSeconds) > 1.0) { deleteOID = existingFeature.OID; } } if (deleteOID == -1) { Console.Write("."); //Console.WriteLine(fi.FullName + " already exists..."); return(true); } } } if (deleteOID != -1) { if (!fdb.Delete(rasterFC, deleteOID)) { Console.WriteLine(_errMsg = "Can't delete old record " + fi.FullName + "\n" + fdb.lastErrorMsg); return(false); } } // /////////////////////////////////////////////////////////////////// // #endregion Feature feature = new Feature(); feature.Shape = rasterLayer.RasterClass.Polygon; feature.Fields.Add(new FieldValue("PATH", fi.FullName)); feature.Fields.Add(new FieldValue("LAST_MODIFIED", fi.LastWriteTimeUtc)); if (fiWorld != null) { feature.Fields.Add(new FieldValue("PATH2", fiWorld.FullName)); feature.Fields.Add(new FieldValue("LAST_MODIFIED2", fiWorld.LastWriteTimeUtc)); } else { feature.Fields.Add(new FieldValue("PATH2", "")); } feature.Fields.Add(new FieldValue("RF_PROVIDER", PlugInManager.PlugInID(rFileDataset).ToString())); feature.Fields.Add(new FieldValue("MANAGED", _managed && (rasterLayer is IBitmap))); feature.Fields.Add(new FieldValue("FORMAT", fi.Extension.Replace(".", ""))); feature.Fields.Add(new FieldValue("CELLX", cellX)); feature.Fields.Add(new FieldValue("CELLY", cellY)); feature.Fields.Add(new FieldValue("LEVELS", (_managed) ? Math.Max(_levels, 1) : 0)); if (!fdb.Insert(rasterFC, feature)) { Console.WriteLine("\nERROR@" + fi.FullName + ": " + fdb.lastErrorMsg); } else { if (_managed && (rasterLayer is IBitmap) && (fdb is SqlFDB)) { QueryFilter qfilter = new QueryFilter(); qfilter.SubFields = "FDB_OID"; if (_fdb is AccessFDB) { filter.WhereClause = ((AccessFDB)_fdb).DbColName("PATH") + "='" + fi.FullName + "'"; } else { qfilter.WhereClause = "PATH='" + fi.FullName + "'"; } IFeatureCursor cursor = ((SqlFDB)fdb).Query(rasterFC, qfilter); if (cursor != null) { IFeature feat = cursor.NextFeature; if (feat != null) { InsertImageDatasetBitmap(feat.OID, rasterLayer, _levels, format); } cursor.Dispose(); } } Console.WriteLine(">" + fi.FullName + " added..."); } rFileDataset.Dispose(); return(true); }
async public Task <IRasterLayer> NextRasterLayer() { if (_cursor == null || _layer == null) { return(null); } try { while (true) { IFeature feature = await _cursor.NextFeature(); if (feature == null) { return(null); } IRasterLayer rLayer = null; double cell = Math.Max((double)feature["CELLX"], (double)feature["CELLY"]); int levels = Convert.ToInt32(feature["LEVELS"]); if ((bool)feature["MANAGED"] && _layer._imageSpaceType == SQLiteFDBImageCatalogClass.ImageSpaceType.FileSystem) { //gView.DataSources.Raster.File.PyramidFileClass rasterClass = new gView.DataSources.Raster.File.PyramidFileClass(_layer._dataset, _layer._imageSpace + @"/" + (string)feature["MANAGED_FILE"], feature.Shape as IPolygon); //if (rasterClass.isValid) //{ // rLayer = LayerFactory.Create(rasterClass) as IRasterLayer; // if (rLayer != null) // { // rLayer.InterpolationMethod = _layer.InterpolationMethod; // if (rasterClass.SpatialReference == null) rasterClass.SpatialReference = _layer._sRef; // } //} } else if (!(bool)feature["MANAGED"]) { if (feature["RF_PROVIDER"] == null || feature["RF_PROVIDER"] == DBNull.Value) { gView.DataSources.Raster.File.RasterFileDataset rDataset = new gView.DataSources.Raster.File.RasterFileDataset(); rLayer = rDataset.AddRasterFile((string)feature["PATH"], feature.Shape as IPolygon); } else { IRasterFileDataset rDataset = _layer._compMan.CreateInstance(new Guid(feature["RF_PROVIDER"].ToString())) as IRasterFileDataset; if (rDataset == null) { continue; } rLayer = rDataset.AddRasterFile((string)feature["PATH"], feature.Shape as IPolygon); } if (rLayer != null && rLayer.RasterClass != null) { rLayer.InterpolationMethod = _layer.InterpolationMethod; if (rLayer.RasterClass.SpatialReference == null) { rLayer.RasterClass.SpatialReference = _layer._sRef; } } } if (rLayer != null) { if (rLayer.Class is IGridClass) { IGridClass gridClass = (IGridClass)rLayer.Class; gridClass.ColorClasses = _layer.ColorClasses; gridClass.UseHillShade = _layer.UseHillShade; gridClass.HillShadeVector = _layer.HillShadeVector; gridClass.UseIgnoreDataValue = _layer.UseIgnoreDataValue; gridClass.IgnoreDataValue = _layer.IgnoreDataValue; gridClass.RenderRawGridValues = _layer.RenderRawGridValues; } return(rLayer); } } } catch { } return(null); }
static void Main(string[] args) { #region Parse Parameters for (int i = 0; i < args.Length; i++) { switch (args[i]) { case "-add": if (job != jobs.unknown) { Console.WriteLine("Can't do more than one job. Run programm twice..."); return; } job = jobs.add; break; case "-clean": if (job != jobs.unknown) { Console.WriteLine("Can't do more than one job. Run programm twice..."); return; } job = jobs.removeUnexisting; break; case "-truncate": if (job != jobs.unknown) { Usage(); Console.WriteLine("Can't do more than one job. Run programm twice..."); return; } job = jobs.truncate; break; case "-s": connectinString = args[++i]; break; case "-db": dbType = args[++i].ToLower(); break; case "-provider": provider = args[++i].ToLower(); break; case "-fn": if (rootPath != String.Empty) { Usage(); Console.WriteLine("Filename OR Rootdirectory..."); return; } fileName = args[++i]; break; case "-rd": if (fileName != String.Empty) { Usage(); Console.WriteLine("Filename OR Rootdirectory..."); return; } rootPath = args[++i]; break; case "-f": Filters = args[++i]; break; } } #endregion #region Check Parameters if (connectinString == String.Empty) { Usage(); Console.WriteLine("No connection string..."); return; } switch (job) { case jobs.removeUnexisting: case jobs.truncate: break; case jobs.add: if (fileName == String.Empty && (rootPath == String.Empty || Filters == String.Empty)) { Usage(); Console.WriteLine("No file or rootdirectory and filter defined..."); return; } break; case jobs.unknown: Usage(); Console.WriteLine("No job defined..."); return; } #endregion DateTime dt = DateTime.Now; string mdb = ConfigTextStream.ExtractValue(connectinString, "mdb"); string dsname = ConfigTextStream.ExtractValue(connectinString, "dsname"); string connStr = ConfigTextStream.RemoveValue(connectinString, "dsname"); IFeatureDataset ds = null; if (mdb != String.Empty) { AccessFDB fdb = new AccessFDB(); fdb.Open(connStr); IFeatureDataset dataset = fdb[dsname]; if (dataset == null) { Console.WriteLine("Error opening dataset: " + fdb.lastErrorMsg); return; } //dataset.ConnectionString = connectinString; if (!dataset.Open()) { Console.WriteLine("Error opening dataset: " + dataset.lastErrorMsg); return; } ds = dataset; } else if (dbType == "sql") { SqlFDB fdb = new SqlFDB(); fdb.Open(connStr); IFeatureDataset dataset = fdb[dsname]; if (dataset == null) { Console.WriteLine("Error opening dataset: " + fdb.lastErrorMsg); return; } //dataset.ConnectionString = connectinString; if (!dataset.Open()) { Console.WriteLine("Error opening dataset: " + dataset.lastErrorMsg); return; } ds = dataset; } else if (dbType == "postgres") { pgFDB fdb = new pgFDB(); fdb.Open(connStr); IFeatureDataset dataset = fdb[dsname]; if (dataset == null) { Console.WriteLine("Error opening dataset: " + fdb.lastErrorMsg); return; } //dataset.ConnectionString = connectinString; if (!dataset.Open()) { Console.WriteLine("Error opening dataset: " + dataset.lastErrorMsg); return; } ds = dataset; } else if (dbType == "sqlite") { SQLiteFDB fdb = new SQLiteFDB(); fdb.Open(connStr); IFeatureDataset dataset = fdb[dsname]; if (dataset == null) { Console.WriteLine("Error opening dataset: " + fdb.lastErrorMsg); return; } //dataset.ConnectionString = connectinString; if (!dataset.Open()) { Console.WriteLine("Error opening dataset: " + dataset.lastErrorMsg); return; } ds = dataset; } IRasterFileDataset rds = null; if (provider == "gdal") { rds = PlugInManager.Create(new Guid("43DFABF1-3D19-438c-84DA-F8BA0B266592")) as IRasterFileDataset; } else if (provider == "raster") { rds = PlugInManager.Create(new Guid("D4812641-3F53-48eb-A66C-FC0203980C79")) as IRasterFileDataset; } Dictionary <string, Guid> providers = new Dictionary <string, Guid>(); if (rds != null) { foreach (string format in rds.SupportedFileFilter.Split('|')) { string extension = format; int pos = format.LastIndexOf("."); if (pos > 0) { extension = format.Substring(pos, format.Length - pos); } providers.Add(extension, PlugInManager.PlugInID(rds)); Console.WriteLine("Provider " + extension + ": " + rds.ToString() + " {" + PlugInManager.PlugInID(rds).ToString() + "}"); } } if (providers.Count == 0) { providers = null; } switch (job) { case jobs.truncate: Truncate(ds, dsname + "_IMAGE_POLYGONS"); break; case jobs.removeUnexisting: RemoveUnexisting(ds); CalculateExtent(ds); break; case jobs.add: if (fileName != String.Empty) { if (!ImportFiles(ds, fileName.Split(';'), providers)) { if (!continueOnError) { return; } } } else if (rootPath != String.Empty && Filters != String.Empty) { if (!ImportDirectory(ds, new DirectoryInfo(rootPath), Filters.Split(';'), providers)) { if (!continueOnError) { return; } } } CalculateExtent(ds); break; } Console.WriteLine("\n" + ((TimeSpan)(DateTime.Now - dt)).TotalSeconds + "s"); Console.WriteLine("done..."); }
public void LoadMapDocument(string filename) { if (_doc == null || filename == "") { return; } _docFilename = filename; System.IO.FileInfo fi = new System.IO.FileInfo(filename); if (!fi.Exists) { return; } if (fi.Extension.ToLower() != ".axl") { RemoveAllDataViews(); if (_appWindow != null) { _appWindow.RemoveAllToolbars(); } _activeDataView = null; } XmlStream stream = new XmlStream(""); if (fi.Extension.ToLower() == ".rdm") { StreamReader sr = new StreamReader(filename); byte[] bytes = new byte[fi.Length]; BinaryReader br = new BinaryReader(sr.BaseStream); br.Read(bytes, 0, bytes.Length); sr.Close(); bytes = Crypto.Decrypt(bytes, _cryptoKey); MemoryStream ms = new MemoryStream(bytes); stream.ReadStream(ms); ms.Close(); } else if (fi.Extension.ToLower() == ".axl") { IMap map = _doc.Maps[0]; PlugInManager pman = new PlugInManager(); #region AXL XmlDocument axl = new XmlDocument(); axl.Load(fi.FullName); #region Extent XmlNode envNode = axl.SelectSingleNode("ARCXML/CONFIG/MAP/PROPERTIES/ENVELOPE[@minx and @maxx and @miny and @miny]"); if (envNode != null) { Envelope env = new Envelope(envNode); map.Display.Limit = new Envelope(env); map.Display.ZoomTo(env); } #endregion #region Workspaces Dictionary <string, IDataset> _workspaces = new Dictionary <string, IDataset>(); foreach (XmlNode workspaceNode in axl.SelectNodes("ARCXML/CONFIG/MAP/WORKSPACES/*")) { switch (workspaceNode.Name) { case "SDEWORKSPACE": string connectionString = "server=" + workspaceNode.Attributes["server"].Value; if (workspaceNode.Attributes["instance"] != null) { connectionString += ";instance=" + workspaceNode.Attributes["instance"].Value; } if (workspaceNode.Attributes["database"] != null) { connectionString += ";database=" + workspaceNode.Attributes["database"].Value; } if (workspaceNode.Attributes["user"] != null) { connectionString += ";user="******"user"].Value; } if (workspaceNode.Attributes["password"] != null) { connectionString += ";password="******"password"].Value; } IDataset sdeDataset = pman.CreateInstance(new Guid("CE42218B-6962-48c9-9BAC-39E4C5003AE5")) as IDataset; if (sdeDataset == null) { continue; } sdeDataset.ConnectionString = connectionString; if (!sdeDataset.Open()) { continue; } _workspaces.Add(workspaceNode.Attributes["name"].Value, sdeDataset); break; case "SHAPEWORKSPACE": IDataset shapeDataset = pman.CreateInstance(new Guid("80F48262-D412-41fb-BF43-2D611A2ABF42")) as IDataset; if (shapeDataset == null) { continue; } shapeDataset.ConnectionString = workspaceNode.Attributes["directory"].Value; if (!shapeDataset.Open()) { continue; } _workspaces.Add(workspaceNode.Attributes["name"].Value, shapeDataset); break; case "IMAGEWORKSPACE": IDataset rasterDataset = pman.CreateInstance(new Guid("43DFABF1-3D19-438c-84DA-F8BA0B266592")) as IDataset; _workspaces.Add(workspaceNode.Attributes["name"].Value, rasterDataset); break; } } #endregion #region Layers XmlNodeList layerNodes = axl.SelectNodes("ARCXML/CONFIG/MAP/LAYER[@name and @id and @type]"); if (layerNodes == null) { return; } for (int i = layerNodes.Count - 1; i >= 0; i--) { XmlNode layerNode = layerNodes[i]; if (layerNode.Attributes["type"].Value == "featureclass") { XmlNode datasetNode = layerNode.SelectSingleNode("DATASET[@name and @workspace]"); if (datasetNode == null) { continue; } if (!_workspaces.ContainsKey(datasetNode.Attributes["workspace"].Value)) { continue; } IDataset dataset = _workspaces[datasetNode.Attributes["workspace"].Value]; IDatasetElement dsElement = dataset[datasetNode.Attributes["name"].Value]; if (dsElement == null || dsElement.Class == null) { continue; } IFeatureLayer layer = (IFeatureLayer)LayerFactory.Create(dsElement.Class); if (layerNode.Attributes["visible"] != null) { layer.Visible = layerNode.Attributes["visible"].Value == "true"; } layer.SID = layerNode.Attributes["id"].Value; map.AddLayer(layer); SetLayernameAndScales(layerNode, layer); SetRenderers(layerNode, layer); XmlNode queryNode = layerNode.SelectSingleNode("QUERY[@where]"); if (queryNode != null) { layer.FilterQuery = new QueryFilter(); layer.FilterQuery.WhereClause = queryNode.Attributes["where"].Value; } } else if (layerNode.Attributes["type"].Value == "image") { XmlNode datasetNode = layerNode.SelectSingleNode("DATASET[@name and @workspace]"); if (datasetNode == null) { continue; } if (!_workspaces.ContainsKey(datasetNode.Attributes["workspace"].Value)) { continue; } IRasterFileDataset dataset = _workspaces[datasetNode.Attributes["workspace"].Value] as IRasterFileDataset; if (dataset == null) { continue; } XmlNode workspaceNode = axl.SelectSingleNode("ARCXML/CONFIG/MAP/WORKSPACES/IMAGEWORKSPACE[@name='" + datasetNode.Attributes["workspace"].Value + "' and @directory]"); if (workspaceNode == null) { continue; } IRasterLayer rLayer = dataset.AddRasterFile(workspaceNode.Attributes["directory"].Value + @"\" + datasetNode.Attributes["name"].Value); if (rLayer == null) { continue; } if (layerNode.Attributes["visible"] != null) { rLayer.Visible = layerNode.Attributes["visible"].Value == "true"; } rLayer.SID = layerNode.Attributes["id"].Value; map.AddLayer(rLayer); SetLayernameAndScales(layerNode, rLayer); } } #endregion ValidateUI(); IsDirty = false; _appWindow.Title = "gView.Carto " + fi.Name; if (AfterLoadMapDocument != null) { AfterLoadMapDocument(_doc); } return; #endregion } else { stream.ReadStream(filename); } while (_doc.Maps.Count > 0) { _doc.RemoveMap(_doc.Maps[0]); } _dataViews.Clear(); stream.Load("MapDocument", null, _doc); // Load DataViews... DataView dv; while ((dv = (DataView)stream.Load("DataView", null, new DataView(_doc.Maps))) != null) { if (!(dv.Map is Map)) { continue; } DataView dataView = _appWindow.AddDataView((Map)dv.Map); if (dataView == null) { continue; } dataView.Envelope = dv.Envelope; dataView.TOC = dv.TOC; dataView.DisplayRotation = dv.DisplayRotation; if (_activeDataView == null) { _activeDataView = dataView; } } if (_dataViews.Count == 0 && _doc.Maps.Count > 0) { //_appWindow.AddDataView((Map)_doc.Maps[0]); _activeDataView = _dataViews[0]; } if (_activeDataView != null && _activeDataView.MapView != null) { _activeDataView.MapView.Tool = this.ActiveTool; } ValidateUI(); IsDirty = false; _appWindow.Title = "gView.Carto " + fi.Name; _readonly = (fi.Extension.ToLower() == ".rdm"); if (AfterLoadMapDocument != null) { AfterLoadMapDocument(_doc); } }
async public Task <IRasterLayer> NextRasterLayer() { if (_cursor == null || _layer == null) { return(null); } try { while (true) { IFeature feature = await _cursor.NextFeature(); if (feature == null) { return(null); } IRasterLayer rLayer = null; double cell = Math.Max((double)feature["CELLX"], (double)feature["CELLY"]); int levels = (int)feature["LEVELS"]; if (!(bool)feature["MANAGED"]) { if (feature["RF_PROVIDER"] == null || feature["RF_PROVIDER"] == DBNull.Value) { gView.DataSources.Raster.File.RasterFileDataset rDataset = new gView.DataSources.Raster.File.RasterFileDataset(); rLayer = rDataset.AddRasterFile((string)feature["PATH"], feature.Shape as IPolygon); } else { IRasterFileDataset rDataset = _layer._compMan.CreateInstance(new Guid(feature["RF_PROVIDER"].ToString())) as IRasterFileDataset; if (rDataset == null) { continue; } rLayer = rDataset.AddRasterFile((string)feature["PATH"], feature.Shape as IPolygon); } if (rLayer != null && rLayer.RasterClass != null) { rLayer.InterpolationMethod = _layer.InterpolationMethod; if (rLayer.RasterClass.SpatialReference == null) { rLayer.RasterClass.SpatialReference = _layer._sRef; } } } if (rLayer != null) { if (rLayer.Class is IGridClass) { IGridClass gridClass = (IGridClass)rLayer.Class; gridClass.ColorClasses = _layer.ColorClasses; gridClass.UseHillShade = _layer.UseHillShade; gridClass.HillShadeVector = _layer.HillShadeVector; gridClass.UseIgnoreDataValue = _layer.UseIgnoreDataValue; gridClass.IgnoreDataValue = _layer.IgnoreDataValue; gridClass.RenderRawGridValues = _layer.RenderRawGridValues; } return(rLayer); } } } catch { } return(null); }