christian@0: /* christian@0: * Postarc christian@0: * christian@0: * Author: christian@0: * Christian Lins christian@0: * christian@0: * Copyright: christian@0: * Copyright (C) 2012 Intevation GmbH christian@0: * christian@0: * This program is free software: you can redistribute it and/or modify christian@0: * it under the terms of the GNU Lesser General Public License as published by christian@0: * the Free Software Foundation, either version 3 of the License, or christian@0: * (at your option) any later version. christian@0: * christian@0: * This program is distributed in the hope that it will be useful, christian@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of christian@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the christian@0: * GNU General Public License for more details. christian@0: * christian@0: * You should have received a copy of the GNU Lesser General Public License christian@0: * along with this program. If not, see . christian@0: */ christian@0: christian@0: using System; christian@0: using System.Collections.Generic; christian@0: using System.Linq; christian@0: using System.Text; christian@0: using ESRI.ArcGIS.Carto; christian@0: using ESRI.ArcGIS.Geodatabase; christian@0: using ESRI.ArcGIS.Geometry; christian@0: using ESRI.ArcGIS.esriSystem; christian@0: using ESRI.ArcGIS.Display; christian@0: using Postarc.Geodatabase; christian@0: using System.Diagnostics; christian@0: christian@0: namespace Postarc.Feature christian@0: { christian@0: class FeatureLayer : IFeatureLayer, ITableFields, IGeoDataset, ILegendInfo christian@0: { christian@0: protected Postarc.Feature.FeatureClass featureClass = null; christian@0: protected string name = "Unamed FeatureLayer"; christian@0: protected bool cached = false; christian@0: protected bool visible = true; christian@0: protected bool selectable = true; christian@0: protected bool showTips = false; christian@0: protected ISpatialReference spatialReference = new UnknownCoordinateSystemClass(); christian@0: christian@0: private IFeatureLayer parent; christian@0: christian@0: public IEnvelope AreaOfInterest christian@0: { christian@0: get christian@0: { christian@0: EnvelopeClass env = new EnvelopeClass(); christian@0: env.XMax = 100; christian@0: env.XMin = -100; christian@0: env.YMax = 100; christian@0: env.YMin = -100; christian@0: return env as IEnvelope; christian@0: } christian@0: } christian@0: christian@0: public bool Cached christian@0: { christian@0: get christian@0: { christian@0: return this.cached; christian@0: } christian@0: set christian@0: { christian@0: this.cached = value; christian@0: } christian@0: } christian@0: christian@0: public string DataSourceType christian@0: { christian@0: get christian@0: { christian@0: return "PostGIS Feature Class"; christian@0: } christian@0: set christian@0: { christian@0: // TODO christian@0: } christian@0: } christian@0: christian@0: public string DisplayField christian@0: { christian@0: get christian@0: { christian@0: return this.featureClass.ShapeFieldName; christian@0: } christian@0: set christian@0: { christian@0: // TODO christian@0: } christian@0: } christian@0: christian@0: public FeatureLayer() christian@0: { christian@0: this.parent = new FeatureLayerClass(); christian@0: } christian@0: christian@0: ///Create a simple fill symbol by specifying a color, outline color and fill style. christian@0: /// christian@0: ///An IRGBColor interface. The color for the inside of the fill symbol. christian@0: ///An esriSimpleLineStyle enumeration for the inside fill symbol. Example: esriSFSSolid. christian@0: ///An IRGBColor interface. The color for the outside line border of the fill symbol. christian@0: ///An esriSimpleLineStyle enumeration for the outside line border. Example: esriSLSSolid. christian@0: ///A System.Double that is the width of the outside line border in points. Example: 2 christian@0: /// christian@0: ///An ISimpleFillSymbol interface. christian@0: /// christian@0: /// christian@0: private ISimpleFillSymbol CreateSimpleFillSymbol( christian@0: IRgbColor fillColor, christian@0: esriSimpleFillStyle fillStyle, christian@0: IRgbColor borderColor, christian@0: esriSimpleLineStyle borderStyle, christian@0: System.Double borderWidth) christian@0: { christian@0: if (fillColor == null || fillStyle == null || borderColor == null || borderStyle == null) christian@0: { christian@0: return null; christian@0: } christian@0: ISimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbolClass(); christian@0: simpleLineSymbol.Width = borderWidth; christian@0: simpleLineSymbol.Color = borderColor; christian@0: simpleLineSymbol.Style = borderStyle; christian@0: christian@0: ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbolClass(); christian@0: simpleFillSymbol.Outline = simpleLineSymbol; christian@0: simpleFillSymbol.Style = fillStyle; christian@0: simpleFillSymbol.Color = fillColor; christian@0: christian@0: return simpleFillSymbol; christian@0: } christian@0: christian@0: public void Draw(esriDrawPhase drawPhase, IDisplay display, ITrackCancel trackCancel) christian@0: { christian@0: Debug.WriteLine("PostGISFeatureLayer::Draw(" + drawPhase + ")"); christian@0: // this.parent.Draw(drawPhase, display, trackCancel); christian@0: christian@0: switch (drawPhase) christian@0: { christian@0: case esriDrawPhase.esriDPGeography: christian@0: display.SetSymbol(get_LegendGroup(0).get_Class(0).Symbol); christian@0: christian@0: IFeatureCursor cur = featureClass.Search(null, true); christian@0: IFeature feat; christian@0: while ((feat = cur.NextFeature()) != null) christian@0: { christian@0: IPoint sp = feat.Shape as IPoint; christian@0: PointClass p = new PointClass(); christian@0: p.PutCoords(sp.X, sp.Y); christian@0: p.SpatialReference = CreateGeographicSpatialReference(); christian@0: p.Project(spatialReference); christian@0: //feat.Shape.Project(spatialReference); christian@0: display.DrawPoint(p); christian@0: } christian@0: christian@0: break; christian@0: } christian@0: } christian@0: christian@0: private double GetSymbolSize(IDisplay display, int symbolSizePixels) christian@0: { christian@0: if (display == null) christian@0: return 0; christian@0: christian@0: double symbolSize; christian@0: christian@0: // convert the symbol size from pixels to map units christian@0: ITransformation transform = display.DisplayTransformation as ITransformation; christian@0: if (transform == null) christian@0: return 0; christian@0: christian@0: double[] symbolDimensions = new double[2]; christian@0: symbolDimensions[0] = (double)symbolSizePixels; christian@0: symbolDimensions[1] = (double)symbolSizePixels; christian@0: christian@0: double[] symbolDimensionsMap = new double[2]; christian@0: christian@0: transform.TransformMeasuresFF( christian@0: esriTransformDirection.esriTransformReverse, 1, ref symbolDimensionsMap[0], ref symbolDimensions[0]); christian@0: symbolSize = symbolDimensionsMap[0]; christian@0: christian@0: return symbolSize; christian@0: } christian@0: christian@0: christian@0: /// christian@0: /// create a WGS1984 geographic coordinate system. christian@0: /// In this case, the underlying data provided by the service is in WGS1984. christian@0: /// christian@0: /// christian@0: public static ISpatialReference CreateGeographicSpatialReference() christian@0: { christian@0: ISpatialReferenceFactory spatialRefFatcory = new SpatialReferenceEnvironmentClass(); christian@0: IGeographicCoordinateSystem geoCoordSys; christian@0: geoCoordSys = spatialRefFatcory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); christian@0: //geoCoordSys.SetFalseOriginAndUnits(-180.0, -180.0, 5000000.0); christian@0: //geoCoordSys.SetZFalseOriginAndUnits(0.0, 100000.0); christian@0: //geoCoordSys.SetMFalseOriginAndUnits(0.0, 100000.0); christian@0: christian@0: return geoCoordSys as ISpatialReference; christian@0: } christian@0: christian@0: public IFeatureClass FeatureClass christian@0: { christian@0: get christian@0: { christian@0: return this.featureClass; christian@0: } christian@0: set christian@0: { christian@0: this.parent.FeatureClass = value; christian@0: this.featureClass = value as FeatureClass; christian@0: } christian@0: } christian@0: christian@0: public double MaximumScale christian@0: { christian@0: get christian@0: { christian@0: return 100; // FIXME christian@0: } christian@0: set christian@0: { christian@0: // TODO: Not implemented christian@0: } christian@0: } christian@0: christian@0: public double MinimumScale christian@0: { christian@0: get christian@0: { christian@0: return 0.01; // FIXME christian@0: } christian@0: set christian@0: { christian@0: // TODO: Not implemented christian@0: } christian@0: } christian@0: christian@0: public string Name christian@0: { christian@0: get christian@0: { christian@0: return this.name; christian@0: } christian@0: set christian@0: { christian@0: this.name = value; christian@0: } christian@0: } christian@0: christian@0: public bool ScaleSymbols christian@0: { christian@0: get christian@0: { christian@0: return false; // FIXME christian@0: } christian@0: set christian@0: { christian@0: // TODO: Not implemented christian@0: } christian@0: } christian@0: christian@0: public IFeatureCursor Search(IQueryFilter queryFilter, bool recycling) christian@0: { christian@0: return FeatureClass.Search(queryFilter, recycling); christian@0: } christian@0: christian@0: public bool Selectable christian@0: { christian@0: get christian@0: { christian@0: return selectable; christian@0: } christian@0: set christian@0: { christian@0: this.selectable = value; christian@0: } christian@0: } christian@0: christian@0: public bool ShowTips christian@0: { christian@0: get christian@0: { christian@0: return this.showTips; christian@0: } christian@0: set christian@0: { christian@0: this.showTips = value; christian@0: } christian@0: } christian@0: christian@0: public ISpatialReference SpatialReference christian@0: { christian@0: set christian@0: { christian@0: this.spatialReference = value; christian@0: } christian@0: } christian@0: christian@0: public int SupportedDrawPhases christian@0: { christian@0: get christian@0: { christian@0: return 1; christian@0: } christian@0: } christian@0: christian@0: public bool Valid christian@0: { christian@0: get christian@0: { christian@0: return true; // FIXME christian@0: } christian@0: } christian@0: christian@0: public bool Visible christian@0: { christian@0: get christian@0: { christian@0: return this.visible; christian@0: } christian@0: set christian@0: { christian@0: this.visible = value; christian@0: } christian@0: } christian@0: christian@0: public string get_TipText(double x, double y, double Tolerance) christian@0: { christian@0: return "tiptext"; christian@0: } christian@0: christian@0: public int FieldCount christian@0: { christian@0: get christian@0: { christian@0: return this.featureClass.Fields.FieldCount; christian@0: } christian@0: } christian@0: christian@0: public IField get_Field(int index) christian@0: { christian@0: return this.featureClass.Fields.get_Field(index); christian@0: } christian@0: christian@0: public IFieldInfo get_FieldInfo(int index) christian@0: { christian@0: return Postarc.Geodatabase.FieldInfo.Create(get_Field(index)); christian@0: } christian@0: christian@0: public int FindField(string fieldName) christian@0: { christian@0: return this.featureClass.FindField(fieldName); christian@0: } christian@0: christian@0: christian@0: public IEnvelope Extent christian@0: { christian@0: get christian@0: { christian@0: return featureClass.Extent; christian@0: } christian@0: } christian@0: christian@0: ISpatialReference IGeoDataset.SpatialReference christian@0: { christian@0: get christian@0: { christian@0: return this.spatialReference; christian@0: } christian@0: } christian@0: christian@0: public int LegendGroupCount christian@0: { christian@0: get christian@0: { christian@0: return 1; christian@0: } christian@0: } christian@0: christian@0: public ILegendItem LegendItem christian@0: { christian@0: get christian@0: { christian@0: return null; christian@0: } christian@0: } christian@0: christian@0: public bool SymbolsAreGraduated christian@0: { christian@0: get christian@0: { christian@0: return true; christian@0: } christian@0: set christian@0: { christian@0: throw new NotImplementedException(); christian@0: } christian@0: } christian@0: christian@0: public ILegendGroup get_LegendGroup(int index) christian@0: { christian@0: if (index == 0) christian@0: { christian@0: RgbColorClass fillColor = new RgbColorClass(); christian@0: fillColor.Blue = 255; christian@0: fillColor.Red = 0; christian@0: fillColor.Green = 0; christian@0: christian@0: ISimpleMarkerSymbol simpleMarkerSymbol = new ESRI.ArcGIS.Display.SimpleMarkerSymbolClass(); christian@0: simpleMarkerSymbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle; christian@0: simpleMarkerSymbol.Size = 5; christian@0: simpleMarkerSymbol.Color = fillColor; christian@0: christian@0: LegendGroupClass legGrp = new LegendGroupClass(); christian@0: legGrp.Editable = true; christian@0: legGrp.Visible = true; christian@0: christian@0: LegendClassClass legClass = new LegendClassClass(); christian@0: legClass.Description = "Point Description"; christian@0: legClass.Label = "Points"; christian@0: legClass.Symbol = (ISymbol)simpleMarkerSymbol; christian@0: legGrp.AddClass(legClass); christian@0: return legGrp; christian@0: } christian@0: return null; christian@0: } christian@0: } christian@0: }