comparison Postarc/Postarc/Feature/FeatureLayer.cs @ 0:1aca3d413885 tip

Initial import of Postarc
author Christian Lins <christian.lins@intevation.de>
date Fri, 05 Oct 2012 23:55:06 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1aca3d413885
1 /*
2 * Postarc
3 *
4 * Author:
5 * Christian Lins <christian.lins@intevation.de>
6 *
7 * Copyright:
8 * Copyright (C) 2012 Intevation GmbH <http://www.intevation.de/>
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 using System;
25 using System.Collections.Generic;
26 using System.Linq;
27 using System.Text;
28 using ESRI.ArcGIS.Carto;
29 using ESRI.ArcGIS.Geodatabase;
30 using ESRI.ArcGIS.Geometry;
31 using ESRI.ArcGIS.esriSystem;
32 using ESRI.ArcGIS.Display;
33 using Postarc.Geodatabase;
34 using System.Diagnostics;
35
36 namespace Postarc.Feature
37 {
38 class FeatureLayer : IFeatureLayer, ITableFields, IGeoDataset, ILegendInfo
39 {
40 protected Postarc.Feature.FeatureClass featureClass = null;
41 protected string name = "Unamed FeatureLayer";
42 protected bool cached = false;
43 protected bool visible = true;
44 protected bool selectable = true;
45 protected bool showTips = false;
46 protected ISpatialReference spatialReference = new UnknownCoordinateSystemClass();
47
48 private IFeatureLayer parent;
49
50 public IEnvelope AreaOfInterest
51 {
52 get
53 {
54 EnvelopeClass env = new EnvelopeClass();
55 env.XMax = 100;
56 env.XMin = -100;
57 env.YMax = 100;
58 env.YMin = -100;
59 return env as IEnvelope;
60 }
61 }
62
63 public bool Cached
64 {
65 get
66 {
67 return this.cached;
68 }
69 set
70 {
71 this.cached = value;
72 }
73 }
74
75 public string DataSourceType
76 {
77 get
78 {
79 return "PostGIS Feature Class";
80 }
81 set
82 {
83 // TODO
84 }
85 }
86
87 public string DisplayField
88 {
89 get
90 {
91 return this.featureClass.ShapeFieldName;
92 }
93 set
94 {
95 // TODO
96 }
97 }
98
99 public FeatureLayer()
100 {
101 this.parent = new FeatureLayerClass();
102 }
103
104 ///<summary>Create a simple fill symbol by specifying a color, outline color and fill style.</summary>
105 ///
106 ///<param name="fillColor">An IRGBColor interface. The color for the inside of the fill symbol.</param>
107 ///<param name="fillStyle">An esriSimpleLineStyle enumeration for the inside fill symbol. Example: esriSFSSolid.</param>
108 ///<param name="borderColor">An IRGBColor interface. The color for the outside line border of the fill symbol.</param>
109 ///<param name="borderStyle">An esriSimpleLineStyle enumeration for the outside line border. Example: esriSLSSolid.</param>
110 ///<param name="borderWidth">A System.Double that is the width of the outside line border in points. Example: 2</param>
111 ///
112 ///<returns>An ISimpleFillSymbol interface.</returns>
113 ///
114 ///<remarks></remarks>
115 private ISimpleFillSymbol CreateSimpleFillSymbol(
116 IRgbColor fillColor,
117 esriSimpleFillStyle fillStyle,
118 IRgbColor borderColor,
119 esriSimpleLineStyle borderStyle,
120 System.Double borderWidth)
121 {
122 if (fillColor == null || fillStyle == null || borderColor == null || borderStyle == null)
123 {
124 return null;
125 }
126 ISimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
127 simpleLineSymbol.Width = borderWidth;
128 simpleLineSymbol.Color = borderColor;
129 simpleLineSymbol.Style = borderStyle;
130
131 ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
132 simpleFillSymbol.Outline = simpleLineSymbol;
133 simpleFillSymbol.Style = fillStyle;
134 simpleFillSymbol.Color = fillColor;
135
136 return simpleFillSymbol;
137 }
138
139 public void Draw(esriDrawPhase drawPhase, IDisplay display, ITrackCancel trackCancel)
140 {
141 Debug.WriteLine("PostGISFeatureLayer::Draw(" + drawPhase + ")");
142 // this.parent.Draw(drawPhase, display, trackCancel);
143
144 switch (drawPhase)
145 {
146 case esriDrawPhase.esriDPGeography:
147 display.SetSymbol(get_LegendGroup(0).get_Class(0).Symbol);
148
149 IFeatureCursor cur = featureClass.Search(null, true);
150 IFeature feat;
151 while ((feat = cur.NextFeature()) != null)
152 {
153 IPoint sp = feat.Shape as IPoint;
154 PointClass p = new PointClass();
155 p.PutCoords(sp.X, sp.Y);
156 p.SpatialReference = CreateGeographicSpatialReference();
157 p.Project(spatialReference);
158 //feat.Shape.Project(spatialReference);
159 display.DrawPoint(p);
160 }
161
162 break;
163 }
164 }
165
166 private double GetSymbolSize(IDisplay display, int symbolSizePixels)
167 {
168 if (display == null)
169 return 0;
170
171 double symbolSize;
172
173 // convert the symbol size from pixels to map units
174 ITransformation transform = display.DisplayTransformation as ITransformation;
175 if (transform == null)
176 return 0;
177
178 double[] symbolDimensions = new double[2];
179 symbolDimensions[0] = (double)symbolSizePixels;
180 symbolDimensions[1] = (double)symbolSizePixels;
181
182 double[] symbolDimensionsMap = new double[2];
183
184 transform.TransformMeasuresFF(
185 esriTransformDirection.esriTransformReverse, 1, ref symbolDimensionsMap[0], ref symbolDimensions[0]);
186 symbolSize = symbolDimensionsMap[0];
187
188 return symbolSize;
189 }
190
191
192 /// <summary>
193 /// create a WGS1984 geographic coordinate system.
194 /// In this case, the underlying data provided by the service is in WGS1984.
195 /// </summary>
196 /// <returns></returns>
197 public static ISpatialReference CreateGeographicSpatialReference()
198 {
199 ISpatialReferenceFactory spatialRefFatcory = new SpatialReferenceEnvironmentClass();
200 IGeographicCoordinateSystem geoCoordSys;
201 geoCoordSys = spatialRefFatcory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
202 //geoCoordSys.SetFalseOriginAndUnits(-180.0, -180.0, 5000000.0);
203 //geoCoordSys.SetZFalseOriginAndUnits(0.0, 100000.0);
204 //geoCoordSys.SetMFalseOriginAndUnits(0.0, 100000.0);
205
206 return geoCoordSys as ISpatialReference;
207 }
208
209 public IFeatureClass FeatureClass
210 {
211 get
212 {
213 return this.featureClass;
214 }
215 set
216 {
217 this.parent.FeatureClass = value;
218 this.featureClass = value as FeatureClass;
219 }
220 }
221
222 public double MaximumScale
223 {
224 get
225 {
226 return 100; // FIXME
227 }
228 set
229 {
230 // TODO: Not implemented
231 }
232 }
233
234 public double MinimumScale
235 {
236 get
237 {
238 return 0.01; // FIXME
239 }
240 set
241 {
242 // TODO: Not implemented
243 }
244 }
245
246 public string Name
247 {
248 get
249 {
250 return this.name;
251 }
252 set
253 {
254 this.name = value;
255 }
256 }
257
258 public bool ScaleSymbols
259 {
260 get
261 {
262 return false; // FIXME
263 }
264 set
265 {
266 // TODO: Not implemented
267 }
268 }
269
270 public IFeatureCursor Search(IQueryFilter queryFilter, bool recycling)
271 {
272 return FeatureClass.Search(queryFilter, recycling);
273 }
274
275 public bool Selectable
276 {
277 get
278 {
279 return selectable;
280 }
281 set
282 {
283 this.selectable = value;
284 }
285 }
286
287 public bool ShowTips
288 {
289 get
290 {
291 return this.showTips;
292 }
293 set
294 {
295 this.showTips = value;
296 }
297 }
298
299 public ISpatialReference SpatialReference
300 {
301 set
302 {
303 this.spatialReference = value;
304 }
305 }
306
307 public int SupportedDrawPhases
308 {
309 get
310 {
311 return 1;
312 }
313 }
314
315 public bool Valid
316 {
317 get
318 {
319 return true; // FIXME
320 }
321 }
322
323 public bool Visible
324 {
325 get
326 {
327 return this.visible;
328 }
329 set
330 {
331 this.visible = value;
332 }
333 }
334
335 public string get_TipText(double x, double y, double Tolerance)
336 {
337 return "tiptext";
338 }
339
340 public int FieldCount
341 {
342 get
343 {
344 return this.featureClass.Fields.FieldCount;
345 }
346 }
347
348 public IField get_Field(int index)
349 {
350 return this.featureClass.Fields.get_Field(index);
351 }
352
353 public IFieldInfo get_FieldInfo(int index)
354 {
355 return Postarc.Geodatabase.FieldInfo.Create(get_Field(index));
356 }
357
358 public int FindField(string fieldName)
359 {
360 return this.featureClass.FindField(fieldName);
361 }
362
363
364 public IEnvelope Extent
365 {
366 get
367 {
368 return featureClass.Extent;
369 }
370 }
371
372 ISpatialReference IGeoDataset.SpatialReference
373 {
374 get
375 {
376 return this.spatialReference;
377 }
378 }
379
380 public int LegendGroupCount
381 {
382 get
383 {
384 return 1;
385 }
386 }
387
388 public ILegendItem LegendItem
389 {
390 get
391 {
392 return null;
393 }
394 }
395
396 public bool SymbolsAreGraduated
397 {
398 get
399 {
400 return true;
401 }
402 set
403 {
404 throw new NotImplementedException();
405 }
406 }
407
408 public ILegendGroup get_LegendGroup(int index)
409 {
410 if (index == 0)
411 {
412 RgbColorClass fillColor = new RgbColorClass();
413 fillColor.Blue = 255;
414 fillColor.Red = 0;
415 fillColor.Green = 0;
416
417 ISimpleMarkerSymbol simpleMarkerSymbol = new ESRI.ArcGIS.Display.SimpleMarkerSymbolClass();
418 simpleMarkerSymbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle;
419 simpleMarkerSymbol.Size = 5;
420 simpleMarkerSymbol.Color = fillColor;
421
422 LegendGroupClass legGrp = new LegendGroupClass();
423 legGrp.Editable = true;
424 legGrp.Visible = true;
425
426 LegendClassClass legClass = new LegendClassClass();
427 legClass.Description = "Point Description";
428 legClass.Label = "Points";
429 legClass.Symbol = (ISymbol)simpleMarkerSymbol;
430 legGrp.AddClass(legClass);
431 return legGrp;
432 }
433 return null;
434 }
435 }
436 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)