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