-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathLayerInput.cs
More file actions
147 lines (127 loc) · 4.11 KB
/
Copy pathLayerInput.cs
File metadata and controls
147 lines (127 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// -------------------------------------------------------------------------------------------
// <copyright file="InputSource.cs" company="MapWindow OSS Team - www.mapwindow.org">
// MapWindow OSS Team - 2015
// </copyright>
// -------------------------------------------------------------------------------------------
using System;
using System.Linq;
using MW5.Api.Concrete;
using MW5.Api.Helpers;
using MW5.Api.Interfaces;
using MW5.Api.Static;
using MW5.Tools.Enums;
namespace MW5.Tools.Model.Layers
{
/// <summary>
/// Represents a layer added to the map which serves as an input to a certain GIS tool.
/// </summary>
internal class LayerInput : IRasterInput, IVectorInput
{
private string _filename = string.Empty;
private string _name = string.Empty;
private ILayer _layer;
public LayerInput(ILayer layer)
{
if (layer == null) throw new ArgumentNullException("layer");
_layer = layer;
}
public IFeatureSet FeatureSet
{
get { return Datasource as IFeatureSet; }
}
public IRasterSource Raster
{
get { return Datasource as IRasterSource; }
}
public ILayerSource Datasource
{
get { return _layer != null ? _layer.LayerSource : null; }
set { throw new NotSupportedException(""); }
}
IRasterSource IRasterInput.Datasource
{
get { return Raster; }
set { throw new NotSupportedException(""); }
}
IFeatureSet IVectorInput.Datasource
{
get { return FeatureSet; }
set { throw new NotSupportedException(""); }
}
public bool CloseAfterRun
{
get { return false; }
}
public string Filename
{
get { return _layer != null ? _layer.Filename : _filename; }
}
public string Name
{
get { return _layer != null ? _layer.Name : _name; }
}
/// <summary>
/// A pointer to datasource holding either identity or layer handler, sufficient to reopen
/// the datasource in the future.
/// </summary>
public DatasourcePointer Pointer
{
get
{
if (_layer == null)
{
return null;
}
if (_layer.LayerType == Api.Enums.LayerType.Shapefile)
{
var fs = _layer.FeatureSet;
if (fs.SourceType == Api.Enums.FeatureSourceType.InMemory)
{
// for in-memory layer we can only save the handle
return new DatasourcePointer(_layer.Handle, _layer.Name);
}
}
return new DatasourcePointer(_layer.Filename);
}
}
/// <summary>
/// Gets the type of the input.
/// </summary>
public InputType InputType
{
get { return InputType.Layer; }
}
/// <summary>
/// Closes the input layer if CloseAfterRun flag was set.
/// </summary>
public void Close()
{
// nothing else is needed, it's not our responsibility to cose the layer
if (_layer != null)
{
_filename = _layer.Filename;
_name = _layer.Name;
_layer = null;
}
}
/// <summary>
/// Gets the layer handle of the input datasource. If datasource isn't added to the map -1 will be returned.
/// </summary>
public int LayerHandle
{
get { return _layer.Handle; }
}
public bool SelectedOnly { get; set; }
public ILayer Layer
{
get { return _layer; }
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Close();
}
}
}