コード例 #1
1
        internal ActualCoordinateSystem(ICoordinateSystem coordinateSystem)
        {
            if (coordinateSystem == null)
                throw new ArgumentNullException("coordinateSystem"); //NOXLATE

            CoordinateTransformationFactory f = new CoordinateTransformationFactory();
            CoordinateSystemFactory cf = new CoordinateSystemFactory();

            m_transform = f.CreateFromCoordinateSystems(coordinateSystem, cf.CreateFromWkt(XY_M));
        }
コード例 #2
0
        /// <summary>
        /// Creates a transformation between two coordinate systems.
        /// </summary>
        /// <remarks>
        /// This method will examine the coordinate systems in order to construct
        /// a transformation between them. This method may fail if no path between 
        /// the coordinate systems is found, using the normal failing behavior of 
        /// the DCP (e.g. throwing an exception).</remarks>
        /// <param name="sourceCS">Source coordinate system</param>
        /// <param name="targetCS">Target coordinate system</param>
        /// <returns></returns>		
        public ICoordinateTransformation CreateFromCoordinateSystems(ICoordinateSystem sourceCS, ICoordinateSystem targetCS)
        {
            ICoordinateTransformation trans;
            if (sourceCS is IProjectedCoordinateSystem && targetCS is IGeographicCoordinateSystem) //Projected -> Geographic
                trans = Proj2Geog((IProjectedCoordinateSystem)sourceCS, (IGeographicCoordinateSystem)targetCS);
            else if (sourceCS is IGeographicCoordinateSystem && targetCS is IProjectedCoordinateSystem) //Geographic -> Projected
                trans = Geog2Proj((IGeographicCoordinateSystem)sourceCS, (IProjectedCoordinateSystem)targetCS);

            else if (sourceCS is IGeographicCoordinateSystem && targetCS is IGeocentricCoordinateSystem) //Geocentric -> Geographic
                trans = Geog2Geoc((IGeographicCoordinateSystem)sourceCS, (IGeocentricCoordinateSystem)targetCS);

            else if (sourceCS is IGeocentricCoordinateSystem && targetCS is IGeographicCoordinateSystem) //Geocentric -> Geographic
                trans = Geoc2Geog((IGeocentricCoordinateSystem)sourceCS, (IGeographicCoordinateSystem)targetCS);

            else if (sourceCS is IProjectedCoordinateSystem && targetCS is IProjectedCoordinateSystem) //Projected -> Projected
                trans = Proj2Proj((sourceCS as IProjectedCoordinateSystem), (targetCS as IProjectedCoordinateSystem));

            else if (sourceCS is IGeocentricCoordinateSystem && targetCS is IGeocentricCoordinateSystem) //Geocentric -> Geocentric
                trans = CreateGeoc2Geoc((IGeocentricCoordinateSystem)sourceCS, (IGeocentricCoordinateSystem)targetCS);

            else if (sourceCS is IGeographicCoordinateSystem && targetCS is IGeographicCoordinateSystem) //Geographic -> Geographic
                trans = CreateGeog2Geog(sourceCS as IGeographicCoordinateSystem, targetCS as IGeographicCoordinateSystem);
            else
                throw new NotSupportedException("No support for transforming between the two specified coordinate systems");

            //if (trans.MathTransform is ConcatenatedTransform) {
            //    List<ICoordinateTransformation> MTs = new List<ICoordinateTransformation>();
            //    SimplifyTrans(trans.MathTransform as ConcatenatedTransform, ref MTs);
            //    return new CoordinateTransformation(sourceCS,
            //        targetCS, TransformType.Transformation, new ConcatenatedTransform(MTs),
            //        String.Empty, String.Empty, -1, String.Empty, String.Empty);
            //}
            return trans;
        }
コード例 #3
0
        /// <summary>
        /// Creates a compound coordinate system.
        /// </summary>
        /// <param name="headCRS">The first coordinate system.</param>
        /// <param name="tailCRS">The second coordinate system.</param>
        /// <param name="remarks">Remarks about this object.</param>
        /// <param name="authority">The name of the authority.</param>
        /// <param name="authorityCode">The code the authority uses to identidy this object.</param>
        /// <param name="name">The name of the object.</param>
        /// <param name="alias">The alias of the object.</param>
        /// <param name="abbreviation">The abbreviated name of this object.</param>
        internal CompoundCoordinateSystem(ICoordinateSystem headCRS,
										ICoordinateSystem tailCRS,
										string remarks, string authority, string authorityCode, string name, string alias, string abbreviation)
            : base(remarks, authority, authorityCode, name, alias, abbreviation)
        {
            if (headCRS==null)
            {
                throw new ArgumentNullException("headCRS");
            }
            if (tailCRS==null)
            {
                throw new ArgumentNullException("tailCRS");
            }

            _headCRS = headCRS;
            _tailCRS = tailCRS;
            _axisInfo = new IAxisInfo[this.Dimension];

            // copy axis information
            for(int i=0;i<headCRS.Dimension;i++)
            {
                _axisInfo[i]=_headCRS.GetAxis(i);
            }
            int offset=headCRS.Dimension;
            for (int i=0;i<tailCRS.Dimension;i++)
            {
                _axisInfo[i+offset]=_tailCRS.GetAxis(i);
            }
        }
コード例 #4
0
 /// <summary>
 /// Creates a transformation between two coordinate systems.
 /// </summary>
 /// <remarks>
 /// This method will examine the coordinate systems in order to construct
 /// a transformation between them. This method may fail if no path between 
 /// the coordinate systems is found, using the normal failing behavior of 
 /// the DCP (e.g. throwing an exception).</remarks>
 /// <param name="sourceCS">Source coordinate system</param>
 /// <param name="targetCS">Target coordinate system</param>
 /// <returns></returns>
 public ICoordinateTransformation CreateFromCoordinateSystems(ICoordinateSystem sourceCS, ICoordinateSystem targetCS)
 {
     if ((sourceCS is IProjectedCoordinateSystem) && (targetCS is IGeographicCoordinateSystem))
     {
         return Proj2Geog((IProjectedCoordinateSystem) sourceCS, (IGeographicCoordinateSystem) targetCS);
     }
     if ((sourceCS is IGeographicCoordinateSystem) && (targetCS is IProjectedCoordinateSystem))
     {
         return Geog2Proj((IGeographicCoordinateSystem) sourceCS, (IProjectedCoordinateSystem) targetCS);
     }
     if ((sourceCS is IGeographicCoordinateSystem) && (targetCS is IGeocentricCoordinateSystem))
     {
         return Geog2Geoc((IGeographicCoordinateSystem) sourceCS, (IGeocentricCoordinateSystem) targetCS);
     }
     if ((sourceCS is IGeocentricCoordinateSystem) && (targetCS is IGeographicCoordinateSystem))
     {
         return Geoc2Geog((IGeocentricCoordinateSystem) sourceCS, (IGeographicCoordinateSystem) targetCS);
     }
     if ((sourceCS is IProjectedCoordinateSystem) && (targetCS is IProjectedCoordinateSystem))
     {
         return Proj2Proj(sourceCS as IProjectedCoordinateSystem, targetCS as IProjectedCoordinateSystem);
     }
     if ((sourceCS is IGeocentricCoordinateSystem) && (targetCS is IGeocentricCoordinateSystem))
     {
         return CreateGeoc2Geoc((IGeocentricCoordinateSystem) sourceCS, (IGeocentricCoordinateSystem) targetCS);
     }
     if (!(sourceCS is IGeographicCoordinateSystem) || !(targetCS is IGeographicCoordinateSystem))
     {
         throw new NotSupportedException("No support for transforming between the two specified coordinate systems");
     }
     return this.CreateGeog2Geog(sourceCS as IGeographicCoordinateSystem, targetCS as IGeographicCoordinateSystem);
 }
コード例 #5
0
        /// <summary>
        /// Creates a transformation between two coordinate systems.
        /// </summary>
        /// <remarks>
        /// This method will examine the coordinate systems in order to construct
        /// a transformation between them. This method may fail if no path between 
        /// the coordinate systems is found, using the normal failing behavior of 
        /// the DCP (e.g. throwing an exception).</remarks>
        /// <param name="sourceCS">Source coordinate system</param>
        /// <param name="targetCS">Target coordinate system</param>
        /// <returns></returns>		
        public ICoordinateTransformation CreateFromCoordinateSystems(ICoordinateSystem sourceCS, ICoordinateSystem targetCS)
        {
            if (sourceCS is IProjectedCoordinateSystem && targetCS is IGeographicCoordinateSystem) //Projected -> Geographic
                return Proj2Geog((IProjectedCoordinateSystem)sourceCS, (IGeographicCoordinateSystem)targetCS);

            else if (sourceCS is IGeographicCoordinateSystem && targetCS is IProjectedCoordinateSystem) //Geographic -> Projected
                return Geog2Proj((IGeographicCoordinateSystem)sourceCS, (IProjectedCoordinateSystem)targetCS);

            else if (sourceCS is IGeographicCoordinateSystem && targetCS is IGeocentricCoordinateSystem) //Geocentric -> Geographic
                return Geog2Geoc((IGeographicCoordinateSystem)sourceCS, (IGeocentricCoordinateSystem)targetCS);

            else if (sourceCS is IGeocentricCoordinateSystem && targetCS is IGeographicCoordinateSystem) //Geocentric -> Geographic
                return Geoc2Geog((IGeocentricCoordinateSystem)sourceCS, (IGeographicCoordinateSystem)targetCS);

            else if (sourceCS is IProjectedCoordinateSystem && targetCS is IProjectedCoordinateSystem) //Projected -> Projected
                return Proj2Proj((sourceCS as IProjectedCoordinateSystem),(targetCS as IProjectedCoordinateSystem));

            else if (sourceCS is IGeocentricCoordinateSystem && targetCS is IGeocentricCoordinateSystem) //Geocentric -> Geocentric
                return CreateGeoc2Geoc((IGeocentricCoordinateSystem)sourceCS, (IGeocentricCoordinateSystem)targetCS);

            else if (sourceCS is IGeographicCoordinateSystem && targetCS is IGeographicCoordinateSystem) //Geographic -> Geographic
                return CreateGeog2Geog(sourceCS as IGeographicCoordinateSystem, targetCS as IGeographicCoordinateSystem);

            throw new NotSupportedException("No support for transforming between the two specified coordinate systems");
        }
コード例 #6
0
        public void RenderFeatures(ICoordinateSystem coordsys, IEnumerable<IFeature> items)
        {
            if (items == null) return;

            m_sourceCoordsys = coordsys;

            foreach (IFeature g in items)
            {
                IGeometry geom = g.Geometry;
                if (ProjectionConverter != null)
                {
                    geom = ProjectionConverter(this, geom);
                    if (geom == null) continue;
                }

                if (Generalizer != null)
                {
                    geom = Generalizer(this, geom);
                    if (geom == null) continue;
                }

                if (CoordinateMapper != null)
                    geom = CoordinateMapper(this, geom);
                else
                    geom = PrimitiveCoordinateMapper(geom);

                if (geom == null) continue;

                Draw(geom, g.Style);
            }

            m_sourceCoordsys = null;
        }
コード例 #7
0
    public static ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation Transform2Lambert(ICoordinateSystem source)
    {
        if (source == null)
            throw new ArgumentException("Source coordinate system is null");
        if (!(source is IGeographicCoordinateSystem))
            throw new ArgumentException("Source coordinate system must be geographic");

        CoordinateSystemFactory cFac = new CoordinateSystemFactory();

        List<ProjectionParameter> parameters = new List<ProjectionParameter>();
        parameters.Add(new ProjectionParameter("latitude_of_origin", 50));
        parameters.Add(new ProjectionParameter("central_meridian", -95));
        parameters.Add(new ProjectionParameter("standard_parallel_1", 33));
        parameters.Add(new ProjectionParameter("standard_parallel_2", 45));
        parameters.Add(new ProjectionParameter("false_easting", 0));
        parameters.Add(new ProjectionParameter("false_northing", 0));
        IProjection projection = cFac.CreateProjection("Lambert Conformal Conic 2SP", "lambert_conformal_conic_2sp",
                                                       parameters);

        IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Lambert Conformal Conic 2SP",
                                                                                   source as IGeographicCoordinateSystem,
                                                                                   projection, ProjNet.CoordinateSystems.LinearUnit.Metre,
                                                                                   new AxisInfo("East",
                                                                                                AxisOrientationEnum.East),
                                                                                   new AxisInfo("North",
                                                                                                AxisOrientationEnum.
                                                                                                    North));

        return new CoordinateTransformationFactory().CreateFromCoordinateSystems(source, coordsys);
    }
コード例 #8
0
        public void Test(string title, ICoordinateSystem source, ICoordinateSystem target, 
                         double[] testPoint, double[] expectedPoint,
                         double tolerance, double reverseTolerance = double.NaN)
        {
            var ct = CoordinateTransformationFactory.CreateFromCoordinateSystems(source, target);

            var forwardResult = ct.MathTransform.Transform(testPoint);
            var reverseResult = Double.IsNaN(reverseTolerance)
                                    ? testPoint
                                    : ct.MathTransform.Inverse().Transform(forwardResult);

            var forward = ToleranceLessThan(forwardResult, expectedPoint, tolerance);

            var reverse = Double.IsNaN(reverseTolerance) || 
                          ToleranceLessThan(reverseResult, testPoint, reverseTolerance);

            if (!forward)
                TransformationError(title, expectedPoint, forwardResult);
            if (!reverse)
                TransformationError(title, testPoint, reverseResult, true);

            Assert.IsTrue(forward && reverse);


        }
コード例 #9
0
ファイル: SqlGeography.cs プロジェクト: mcartoixa/GeoSIK
        internal SqlGeography(SqlTypes.SqlGeography sg, ICoordinateSystem coordinateSystem)
        {
            Debug.Assert(sg!=null);
            if (sg==null)
                throw new ArgumentNullException("sg");

            _Geography=sg;
            _CoordinateSystem=coordinateSystem;
        }
コード例 #10
0
ファイル: SpatialGeometry.cs プロジェクト: mcartoixa/GeoSIK
        internal SpatialGeometry(DbGeometry g, ICoordinateSystem coordinateSystem)
        {
            Debug.Assert(g!=null);
            if (g==null)
                throw new ArgumentNullException("g");

            _Geometry=g;
            _CoordinateSystem=coordinateSystem;
        }
コード例 #11
0
        /// <summary>Parses the geometry defined by the specified WKT representation, in the specified coordinate system.</summary>
        /// <param name="text">The WKT representation of the geometry.</param>
        /// <param name="system">The coordinate system of the WKT representation.</param>
        public void Parse(string text, ICoordinateSystem system)
        {
            Debug.Assert(system!=null);
            if (system==null)
                throw new ArgumentNullException("system");

            _Builder=new Gml.GmlGeometryBuilder(system);
            _Builder.Parse(text, system);
        }
コード例 #12
0
ファイル: CoordinateSystem.cs プロジェクト: mcartoixa/GeoSIK
        /// <summary>Indicates whether the current coordinate system is equivalent to the specified one.</summary>
        /// <param name="other">The coordinate system to compare the current one against.</param>
        /// <returns><c>true</c> if the coordinate systems are equivalent; or else <c>false</c>.</returns>
        public bool IsEquivalentTo(ICoordinateSystem other)
        {
            if (other==null)
                return false;

            if (Equals(other))
                return true;

            return false;
        }
コード例 #13
0
ファイル: CoordinateSystem.cs プロジェクト: mcartoixa/GeoSIK
        /// <summary>Indicates whether the current coordinate system is equal to the specified one.</summary>
        /// <param name="other">The coordinate system to compare the current one against.</param>
        /// <returns><c>true</c> if the coordinate systems are equal; or else <c>false</c>.</returns>
        public bool Equals(ICoordinateSystem other)
        {
            if (other==null)
                return false;

            var cs=other as CoordinateSystem;
            if (cs!=null)
                return _System.Equals(cs._System) || _System.EqualParams(cs._System);

            return false;
        }
コード例 #14
0
 public ProjNetSpatialReference(ICoordinateSystem cs)
 {
     var authorityCode = cs.AuthorityCode;
     if (authorityCode <= 0)
     {
         authorityCode = ++_newId;
     }
     _oid = cs.Authority ?? "SM" + ":" + authorityCode;
     Definition = cs.WKT;
     CoordinateSystem = cs;
 }
コード例 #15
0
ファイル: CoordinateSystem.cs プロジェクト: mcartoixa/GeoSIK
        /// <summary>Indicates whether the current coordinate system is equal to the specified one.</summary>
        /// <param name="other">The coordinate system to compare the current one against.</param>
        /// <returns><c>true</c> if the coordinate systems are equal; or else <c>false</c>.</returns>
        public bool Equals(ICoordinateSystem other)
        {
            if (other==null)
                return false;

            var cs=other as CoordinateSystem;
            if (cs!=null)
                return _Projection.Equals(cs._Projection);

            return false;
        }
コード例 #16
0
        public static DsProjections.ProjectionInfo Convert(ICoordinateSystem system)
        {
            if (system==null)
                return null;

            var cs=system as CoordinateSystem;
            if (cs==null)
                return DsProjections.ProjectionInfo.FromEsriString(system.ToString());

            return cs.Projection;
        }
コード例 #17
0
ファイル: FdoGeometry.cs プロジェクト: mcartoixa/GeoSIK
        /// <summary>Creates a new instance of the <see cref="FdoGeometry" /> class that encapsulates
        /// a copy of the specified FDO geometry, in the specified coordinate system.</summary>
        /// <param name="geometry">The FDO geometry for which a copy will be encapsulated.</param>
        /// <param name="coordinateSystem">The coordinate system of the encapsulated FDO geometry.</param>
        /// <remarks>
        ///   <para>This instance encapsulates a copy of the specified <paramref name="geometry" />. It is thus
        /// the responsibility of the caller to <see cref="IDisposable.Dispose()" /> the specified <paramref name="geometry" />.</para>
        /// </remarks>
        public FdoGeometry(FGeometry.IGeometry geometry, ICoordinateSystem coordinateSystem)
        {
            Debug.Assert(geometry!=null);
            if (geometry==null)
                throw new ArgumentNullException("geometry");
            Debug.Assert(coordinateSystem!=null);
            if (coordinateSystem==null)
                throw new ArgumentNullException("coordinateSystem");

            _Geometry=FdoGeometryBuilder.Factory.CreateGeometry(geometry);
            _CoordinateSystem=coordinateSystem;
        }
コード例 #18
0
 public GeometryFactory(ICoordinateFactory coordFactory, ICoordinateSequenceFactory sequenceFactory, Int32? srid, ICoordinateSystem spatialReference)
 {
     _coordFactory = coordFactory;
     _sequenceFactory = sequenceFactory;
     _srid = srid;
     _spatialReference = spatialReference;
     _spatialOps = new BoundingBoxSpatialOperations(this);
     _wktEncoder = new WktWriter();
     _wktDecoder = new WktReader(this, null);
     _wkbEncoder = new WkbWriter();
     _wkbDecoder = new WkbReader(this);
 }
コード例 #19
0
ファイル: FdoEnvelope.cs プロジェクト: mcartoixa/GeoSIK
        /// <summary>Creates a new instance of the <see cref="FdoGeometry" /> class that encapsulates
        /// a copy of the specified FDO envelope, in the specified coordinate system.</summary>
        /// <param name="envelope">The FDO envelope for which a copy will be encapsulated.</param>
        /// <param name="coordinateSystem">The coordinate system of the encapsulated FDO geometry.</param>
        /// <remarks>
        ///   <para>This instance encapsulates a copy of the specified <paramref name="envelope" />. It is thus
        /// the responsibility of the caller to <see cref="IDisposable.Dispose()" /> the specified <paramref name="envelope" />.</para>
        /// </remarks>
        public FdoEnvelope(FGeometry.IEnvelope envelope, ICoordinateSystem coordinateSystem)
        {
            Debug.Assert(envelope!=null);
            if (envelope==null)
                throw new ArgumentNullException("envelope");
            Debug.Assert(coordinateSystem!=null);
            if (coordinateSystem==null)
                throw new ArgumentNullException("coordinateSystem");

            _Envelope=FdoGeometryBuilder.Factory.CreateEnvelope(envelope);
            _CoordinateSystem=coordinateSystem;
        }
コード例 #20
0
        internal CoordinatesTransformer(ICoordinateSystem source, ICoordinateSystem target)
        {
            Debug.Assert(source!=null);
            if (source==null)
                throw new ArgumentNullException("source");
            Debug.Assert(target!=null);
            if (target==null)
                throw new ArgumentNullException("target");

            _Source=CoordinateSystemUtils.Convert(source);
            _Target=CoordinateSystemUtils.Convert(target);
        }
コード例 #21
0
 /// <summary>
 /// Initializes an instance of a CoordinateTransformation
 /// </summary>
 /// <param name="sourceCS">Source coordinate system</param>
 /// <param name="targetCS">Target coordinate system</param>
 /// <param name="transformType">Transformation type</param>
 /// <param name="mathTransform">Math transform</param>
 /// <param name="name">Name of transform</param>
 /// <param name="authority">Authority</param>
 /// <param name="authorityCode">Authority code</param>
 /// <param name="areaOfUse">Area of use</param>
 /// <param name="remarks">Remarks</param>
 internal CoordinateTransformation(ICoordinateSystem sourceCS, ICoordinateSystem targetCS, Topology.CoordinateSystems.Transformations.TransformType transformType, IMathTransform mathTransform, string name, string authority, long authorityCode, string areaOfUse, string remarks)
 {
     this._TargetCS = targetCS;
     this._SourceCS = sourceCS;
     this._TransformType = transformType;
     this._MathTransform = mathTransform;
     this._Name = name;
     this._Authority = authority;
     this._AuthorityCode = authorityCode;
     this._AreaOfUse = areaOfUse;
     this._Remarks = remarks;
 }
コード例 #22
0
		/// <summary>
		/// Creates an instance of FittedCoordinateSystem using the specified parameters
		/// </summary>
        /// <param name="baseSystem">Underlying coordinate system.</param>
        /// <param name="transform">Transformation from fitted coordinate system to the base one</param>
		/// <param name="name">Name</param>
		/// <param name="authority">Authority name</param>
		/// <param name="code">Authority-specific identification code.</param>
		/// <param name="alias">Alias</param>
		/// <param name="abbreviation">Abbreviation</param>
		/// <param name="remarks">Provider-supplied remarks</param>
        protected internal FittedCoordinateSystem (ICoordinateSystem baseSystem, IMathTransform transform,
            string name, string authority, long code, string alias, string remarks, string abbreviation)
			: base(name, authority, code, alias, abbreviation, remarks)
		{
            _BaseCoordinateSystem = baseSystem;
            _ToBaseTransform = transform;
            //get axis infos from the source
            base.AxisInfo = new List<AxisInfo> (baseSystem.Dimension);
            for (int dim = 0; dim < baseSystem.Dimension; dim++)
            {
                base.AxisInfo.Add (baseSystem.GetAxis (dim));
            }
		}
コード例 #23
0
 /// <summary>
 /// Combines two coorindate system.
 /// </summary>
 /// <param name="name">The name of the new coordinate system.</param>
 /// <param name="headCS">The first coordinate system.</param>
 /// <param name="tailCS">The second coordinate system.</param>
 /// <returns>An object that implements the ICompoundCoordinateSystem interface.</returns>
 public ICompoundCoordinateSystem CreateCompoundCoordinateSystem(string name, ICoordinateSystem headCS, ICoordinateSystem tailCS)
 {
     if (headCS==null)
     {
         throw new ArgumentNullException("headCS");
     }
     if (tailCS==null)
     {
         throw new ArgumentNullException("tailCS");
     }
     CompoundCoordinateSystem compoundsCS = new CompoundCoordinateSystem(headCS,tailCS,"","","",name,"","");
     return compoundsCS;
 }
コード例 #24
0
        public static ProjNet.CoordinateSystems.ICoordinateSystem Convert(ICoordinateSystem system)
        {
            if (system==null)
                return null;

            var ret=system as ProjNet.CoordinateSystems.ICoordinateSystem;
            if (ret==null)
            {
                var factory=new ProjNet.CoordinateSystems.CoordinateSystemFactory();
                ret=factory.CreateFromWkt(system.ToString());
            }

            return ret;
        }
コード例 #25
0
 /// <summary>
 /// Initializes an instance of a CoordinateTransformation
 /// </summary>
 /// <param name="sourceCS">Source coordinate system</param>
 /// <param name="targetCS">Target coordinate system</param>
 /// <param name="transformType">Transformation type</param>
 /// <param name="mathTransform">Math transform</param>
 /// <param name="name">Name of transform</param>
 /// <param name="authority">Authority</param>
 /// <param name="authorityCode">Authority code</param>
 /// <param name="areaOfUse">Area of use</param>
 /// <param name="remarks">Remarks</param>
 internal CoordinateTransformation(ICoordinateSystem sourceCS, ICoordinateSystem targetCS, TransformType transformType, IMathTransform mathTransform, 
     string name, string authority, long authorityCode, string areaOfUse, string remarks)
     : base()
 {
     _TargetCS = targetCS;
     _SourceCS = sourceCS;
     _TransformType = transformType;
     _MathTransform = mathTransform;
     _Name = name;
     _Authority = authority;
     _AuthorityCode = authorityCode;
     _AreaOfUse = areaOfUse;
     _Remarks = remarks;
 }
コード例 #26
0
        public static ProjNetCS.ICoordinateSystem Convert(ICoordinateSystem system)
        {
            if (system==null)
                return null;

            var cs=system as CoordinateSystem;
            if (cs==null)
            {
                var factory=new ProjNetCS.CoordinateSystemFactory();
                return factory.CreateFromWkt(system.ToString());
            }

            return cs.System;
        }
コード例 #27
0
        /// <summary>Parses the geometry defined by the specified WKT representation, in the specified coordinate system.</summary>
        /// <param name="text">The WKT representation of the geometry.</param>
        /// <param name="system">The coordinate system of the WKT representation.</param>
        public void Parse(string text, ICoordinateSystem system)
        {
            Debug.Assert(system!=null);
            if (system==null)
                throw new ArgumentNullException("system");

            IGeometryBuilder builder=CreateBuilder(system);
            builder.Parse(text, system);
            IGeometry g=(IGeometry)builder.ConstructedGeometry;

            if ((TargetSystem!=null) && !system.IsEquivalentTo(TargetSystem))
                g.Populate(this);
            else
                _Geometry=g;
        }
コード例 #28
0
        /// <summary>Defines the coordinate system of the geometry source.</summary>
        /// <param name="sourceSystem">The coordinate system of the geometry source.</param>
        /// <remarks>
        ///   <para>If <paramref name="sourceSystem" /> is the same coordinate system as the target coordinate system,
        /// no transformation will occur.</para>
        /// </remarks>
        public void SetCoordinateSystem(ICoordinateSystem sourceSystem)
        {
            Debug.Assert(sourceSystem!=null);
            if (sourceSystem==null)
                throw new ArgumentNullException("sourceSystem");

            if (_TargetSystem==null)
                _TargetSystem=sourceSystem;

            DoSetCoordinateSystem(_TargetSystem);
            _SourceSystem=sourceSystem;

            if (!_TargetSystem.IsEquivalentTo(_SourceSystem))
                _Converter=CommonServiceLocator.GetCoordinateSystemProvider().CreateTransformer(_SourceSystem, _TargetSystem);
        }
コード例 #29
0
 private static string PrintResultTable(ICoordinateSystem fromCoordSys, ICoordinateSystem toCoordSys, Coordinate fromPnt,
                                 Coordinate toPnt, Coordinate refPnt, Coordinate backPnt, string header)
 {
     string table = "<table style=\"border: 1px solid #000; margin: 10px;\">";
     table += "<tr><td colspan=\"2\"><h3>" + header + "</h3></td></tr>";
     table += "<tr><td width=\"130px\" valign=\"top\">Input coordsys:</td><td>" + fromCoordSys.WKT + "</td></tr>";
     table += "<tr><td valign=\"top\">Output coordsys:</td><td>" + toCoordSys.WKT + "</td></tr>";
     table += "<tr><td>Input coordinate:</td><td>" + fromPnt + "</td></tr>";
     table += "<tr><td>Ouput coordinate:</td><td>" + toPnt + "</td></tr>";
     table += "<tr><td>Expected coordinate:</td><td>" + refPnt + "</td></tr>";
     table += "<tr><td>Difference:</td><td>" + (refPnt.Subtract(toPnt)) + "</td></tr>";
     table += "<tr><td>Reverse transform:</td><td>" + backPnt + "</td></tr>";
     table += "<tr><td>Difference:</td><td>" + (backPnt.Subtract(fromPnt)) + "</td></tr>";
     table += "</table>";
     return table;
 }
コード例 #30
0
        public SpatialReference(KinectReader kinectReader, PositionReader positionReader)
        {
            this.kinectReader = kinectReader;
            this.positionReader = positionReader;

            string wkt = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]";
            this.wgs84 = (ICoordinateSystem)ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt);

            //hardcoded UTM 55S - should parameterize
            string toWKT = "PROJCS[\"WGS 72BE / UTM zone 55S\",GEOGCS[\"WGS 72BE\",DATUM[\"WGS_1972_Transit_Broadcast_Ephemeris\",SPHEROID[\"WGS 72\",6378135,298.26,AUTHORITY[\"EPSG\",\"7043\"]],TOWGS84[0,0,1.9,0,0,0.814,-0.38],AUTHORITY[\"EPSG\",\"6324\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4324\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",147],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",10000000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"32555\"]]";

            this.toCs = (ICoordinateSystem)ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(toWKT);

            CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();

            this.toGridtrans = ctfac.CreateFromCoordinateSystems(wgs84, toCs);
        }
        /// <summary>
        /// Creates the search criteria based on filter settings.
        /// </summary>
        /// <param name="mySettings">
        /// The my settings object.
        /// </param>
        /// <returns>
        /// The <see cref="SpeciesObservationSearchCriteria"/>.
        /// </returns>
        public SpeciesObservationSearchCriteria CreateSearchCriteria(
            MySettings.MySettings mySettings,
            ICoordinateSystem coordinateSystem)
        {
            var searchCriteria = new SpeciesObservationSearchCriteria();

            // Default settings
            searchCriteria.IncludePositiveObservations = true;

            // Taxa filter
            if (mySettings.Filter.Taxa.IsActive && mySettings.Filter.Taxa.HasSettings)
            {
                searchCriteria.TaxonIds = mySettings.Filter.Taxa.TaxonIds.ToList();
            }

            // Temporal filter
            if (mySettings.Filter.Temporal.IsActive)
            {
                // Observation date
                if (mySettings.Filter.Temporal.ObservationDate.UseSetting)
                {
                    searchCriteria.ObservationDateTime          = new DateTimeSearchCriteria();
                    searchCriteria.ObservationDateTime.Operator = CompareOperator.Excluding;
                    if (mySettings.Filter.Temporal.ObservationDate.Annually)
                    {
                        searchCriteria.ObservationDateTime.Begin      = new DateTime(1800, 1, 1);
                        searchCriteria.ObservationDateTime.End        = DateTime.Now.AddDays(1);
                        searchCriteria.ObservationDateTime.PartOfYear = new List <IDateTimeInterval>();
                        IDateTimeInterval dateTimeInterval = new DateTimeInterval();
                        dateTimeInterval.Begin = mySettings.Filter.Temporal.ObservationDate.StartDate;
                        dateTimeInterval.End   = mySettings.Filter.Temporal.ObservationDate.EndDate;
                        searchCriteria.ObservationDateTime.PartOfYear.Add(dateTimeInterval);
                    }
                    else
                    {
                        searchCriteria.ObservationDateTime.Begin = mySettings.Filter.Temporal.ObservationDate.StartDate;
                        searchCriteria.ObservationDateTime.End   = mySettings.Filter.Temporal.ObservationDate.EndDate;
                    }
                }

                // Registration date
                if (mySettings.Filter.Temporal.RegistrationDate.UseSetting)
                {
                    searchCriteria.ReportedDateTime          = new DateTimeSearchCriteria();
                    searchCriteria.ReportedDateTime.Operator = CompareOperator.Excluding;
                    if (mySettings.Filter.Temporal.RegistrationDate.Annually)
                    {
                        searchCriteria.ReportedDateTime.Begin      = new DateTime(1800, 1, 1);
                        searchCriteria.ReportedDateTime.End        = DateTime.Now.AddDays(1);
                        searchCriteria.ReportedDateTime.PartOfYear = new List <IDateTimeInterval>();
                        IDateTimeInterval dateTimeInterval = new DateTimeInterval();
                        dateTimeInterval.Begin = mySettings.Filter.Temporal.RegistrationDate.StartDate;
                        dateTimeInterval.End   = mySettings.Filter.Temporal.RegistrationDate.EndDate;
                        searchCriteria.ReportedDateTime.PartOfYear.Add(dateTimeInterval);
                    }
                    else
                    {
                        searchCriteria.ReportedDateTime.Begin = mySettings.Filter.Temporal.RegistrationDate.StartDate;
                        searchCriteria.ReportedDateTime.End   = mySettings.Filter.Temporal.RegistrationDate.EndDate;
                    }
                }

                // Change date
                if (mySettings.Filter.Temporal.ChangeDate.UseSetting)
                {
                    searchCriteria.ChangeDateTime          = new DateTimeSearchCriteria();
                    searchCriteria.ChangeDateTime.Operator = CompareOperator.Excluding;
                    if (mySettings.Filter.Temporal.ChangeDate.Annually)
                    {
                        searchCriteria.ChangeDateTime.Begin      = new DateTime(1800, 1, 1);
                        searchCriteria.ChangeDateTime.End        = DateTime.Now.AddDays(1);
                        searchCriteria.ChangeDateTime.PartOfYear = new List <IDateTimeInterval>();
                        IDateTimeInterval dateTimeInterval = new DateTimeInterval();
                        dateTimeInterval.Begin = mySettings.Filter.Temporal.ChangeDate.StartDate;
                        dateTimeInterval.End   = mySettings.Filter.Temporal.ChangeDate.EndDate;
                        searchCriteria.ChangeDateTime.PartOfYear.Add(dateTimeInterval);
                    }
                    else
                    {
                        searchCriteria.ChangeDateTime.Begin = mySettings.Filter.Temporal.ChangeDate.StartDate;
                        searchCriteria.ChangeDateTime.End   = mySettings.Filter.Temporal.ChangeDate.EndDate;
                    }
                }
            }

            // Accuracy filter
            if (mySettings.Filter.Accuracy.IsActive)
            {
                if (mySettings.Filter.Accuracy.IsCoordinateAccuracyActive)
                {
                    searchCriteria.Accuracy             = mySettings.Filter.Accuracy.MaxCoordinateAccuracy;
                    searchCriteria.IsAccuracyConsidered = mySettings.Filter.Accuracy.Inclusive;
                }
                else
                {
                    searchCriteria.Accuracy             = null;
                    searchCriteria.IsAccuracyConsidered = false;
                }
            }

            // Spatial filter
            if (mySettings.Filter.Spatial.IsActive)
            {
                if (mySettings.Filter.Spatial.Polygons.Count > 0)
                {
                    var dataContext = new DataContext(_userContext);
                    ICoordinateSystem fromCoordinateSystem = mySettings.Filter.Spatial.PolygonsCoordinateSystem;
                    //ICoordinateSystem toCoordinateSystem = mySettings.Presentation.Map.DisplayCoordinateSystem;
                    ICoordinateSystem toCoordinateSystem = coordinateSystem;
                    List <IPolygon>   polygons           = mySettings.Filter.Spatial.Polygons.ToList().ToPolygons(dataContext);
                    polygons = GisTools.CoordinateConversionManager.GetConvertedPolygons(polygons, fromCoordinateSystem, toCoordinateSystem);

                    GeometryTools geometryTools = new GeometryTools();
                    foreach (IPolygon polygon in polygons)
                    {
                        var polygonStatus = geometryTools.ValidateGeometry(polygon);
                        if (!polygonStatus.IsValid)
                        {
                            throw new Exception(string.Format("Polygon error! {0}", polygonStatus.Description));
                        }
                    }

                    searchCriteria.Polygons = polygons;
                }

                if (mySettings.Filter.Spatial.RegionIds.Count > 0)
                {
                    searchCriteria.RegionGuids = new List <string>();
                    RegionList regions = CoreData.RegionManager.GetRegionsByIds(_userContext, mySettings.Filter.Spatial.RegionIds.ToList());
                    foreach (IRegion region in regions)
                    {
                        searchCriteria.RegionGuids.Add(region.GUID);
                    }
                }

                // Locality name search
                if (!string.IsNullOrEmpty(mySettings.Filter.Spatial.Locality.LocalityName))
                {
                    searchCriteria.LocalityNameSearchString = new StringSearchCriteria();
                    searchCriteria.LocalityNameSearchString.SearchString     = mySettings.Filter.Spatial.Locality.LocalityName;
                    searchCriteria.LocalityNameSearchString.CompareOperators = new List <StringCompareOperator>();
                    searchCriteria.LocalityNameSearchString.CompareOperators.Add(mySettings.Filter.Spatial.Locality.CompareOperator);
                }
            }

            // Occurrence filter
            if (mySettings.Filter.Occurrence.IsActive)
            {
                searchCriteria.IncludeNeverFoundObservations      = mySettings.Filter.Occurrence.IncludeNeverFoundObservations;
                searchCriteria.IncludeNotRediscoveredObservations = mySettings.Filter.Occurrence.IncludeNotRediscoveredObservations;
                searchCriteria.IncludePositiveObservations        = mySettings.Filter.Occurrence.IncludePositiveObservations;

                if (mySettings.Filter.Occurrence.IsNaturalOccurrence ==
                    mySettings.Filter.Occurrence.IsNotNaturalOccurrence)
                {
                    // TODO: Set ignore IsNaturalOccurence
                }
                else
                {
                    searchCriteria.IsNaturalOccurrence = mySettings.Filter.Occurrence.IsNaturalOccurrence;
                }
            }

            // Data providers
            if (mySettings.DataProvider.DataProviders.IsActive && mySettings.DataProvider.DataProviders.HasSettings)
            {
                //Get all data providers
                bool providersWithObservationDisabled;
                var  dataProviders = DataProviderManager.GetAllDataProviders(_userContext, out providersWithObservationDisabled);

                //If all providers are selected and we don't have any providers with observation disabled, we don't set data source guids since it will decrease performance
                //All existing providers will be used if the property is not set and the performance is better compared to setting all providers explicit
                if (providersWithObservationDisabled || dataProviders.Count != mySettings.DataProvider.DataProviders.DataProvidersGuids.Count)
                {
                    searchCriteria.DataSourceGuids = new List <string>();
                    foreach (var guid in mySettings.DataProvider.DataProviders.DataProvidersGuids)
                    {
                        searchCriteria.DataSourceGuids.Add(guid);
                    }
                }
            }

            // Field filter
            if (mySettings.Filter.Field.IsActive && mySettings.Filter.Field.HasSettings)
            {
                searchCriteria.FieldSearchCriteria = new SpeciesObservationFieldSearchCriteriaList();

                foreach (var fieldFilterExpression in mySettings.Filter.Field.FieldFilterExpressions)
                {
                    searchCriteria.FieldSearchCriteria.Add(fieldFilterExpression);
                }

                searchCriteria.FieldLogicalOperator = mySettings.Filter.Field.FieldLogicalOperator;
            }

            return(searchCriteria);
        }
コード例 #32
0
        /// <summary>
        /// Get the extents for a MapTubeD geometry.
        /// This needs to be WGS84 extents when the database has Mercator!
        /// </summary>
        /// <param name="GeometryName"></param>
        /// <param name="minlat"></param>
        /// <param name="minlon"></param>
        /// <param name="maxlat"></param>
        /// <param name="maxlon"></param>
        /// <returns></returns>
        public bool GetExtentsForGeometry(string GeometryName, out float minlat, out float minlon, out float maxlat, out float maxlon)
        {
            //According to sharpgis, this is the official webmercator one with EPSG 3785
            //It's also the one used by the latest GMapCreator
            const string GoogleProj =
                "PROJCS[\"Popular Visualisation CRS / Mercator\","
                + "GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\","
                + "SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]],"
                + "TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],"
                + "PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]],"
                + "UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]],"
                + "AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"],"
                + "PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0],"
                + "PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]],"
                + "AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3785\"]]";

            const string WGS84Proj =
                "GEOGCS[\"GCS_WGS_1984\","
                + "DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],"
                + "PRIMEM[\"Greenwich\",0],"
                + "UNIT[\"Degree\",0.0174532925199433]"
                + "]";

            minlat = 0; minlon = 0; maxlat = 0; maxlon = 0;

            string sql = "SELECT {0}.STEnvelope() as [envelope],{1} as [areakey] FROM {2}";

            MapTubeD.GeoDataSources geodb = MapTubeD.GeoDataSources.GetInstance(configFilename);

            string ConnectionString, TableName, GeomFieldName, AreaFieldName;
            //MapScale=0 means get the most detailed boundary we have
            bool Success = geodb.GetInfo(GeometryName, 0, out ConnectionString, out TableName, out GeomFieldName, out AreaFieldName);

            if (!Success)
            {
                return(false);
            }

            Envelope MercEnv = new Envelope();

            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(string.Format(sql, GeomFieldName, AreaFieldName, TableName), conn);
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        SqlGeometry sqlgeom = reader["envelope"] as SqlGeometry;
                        //TODO: removed bit that determines whether an area key is present before expanding the box - this gets bounds for ALL geometry, not joined geometry
                        //get data value from hash to make sure it exists
                        //String areakey = reader["areakey"] as string;
                        //if (areakey == null) continue;
                        //areakey = areakey.Trim();
                        //Object ob = (MapDescriptor.Data as DBJoin).Data[areakey];
                        //if (ob != null)
                        //{
                        //expand bounds to include data geometry box
                        MercEnv.ExpandToInclude(sqlgeom.STPointN(1).STX.Value, sqlgeom.STPointN(1).STY.Value);
                        MercEnv.ExpandToInclude(sqlgeom.STPointN(3).STX.Value, sqlgeom.STPointN(3).STY.Value);
                        //}
                    }
                }
            }
            //now env contains the bounds in Mercator, we need to convert back to WGS84
            //setup coordinate transformations
            CoordinateSystemFactory         CSFactory = new CoordinateSystemFactory();
            ICoordinateSystem               CSMerc    = CSFactory.CreateFromWkt(GoogleProj);
            ICoordinateSystem               CSWGS84   = CSFactory.CreateFromWkt(WGS84Proj);
            CoordinateTransformationFactory ctf       = new CoordinateTransformationFactory();
            ICoordinateTransformation       trans     = ctf.CreateFromCoordinateSystems(CSMerc, CSWGS84);
            Envelope env = NetTopologySuite.CoordinateSystems.Transformations.GeometryTransform.TransformBox(MercEnv, trans.MathTransform);

            double EnvWidth = env.Width;

            //program out error when minx==maxx==-180 for world maps (it wraps wrongly)
            //added a delta minimum for the width, min and max
            if ((EnvWidth <= 0.0000001) && (Math.Abs(env.MinX + 180.0) <= 0.0000001) && (Math.Abs(env.MaxX + 180.0) <= 0.0000001))
            {
                EnvWidth = 360.0;
            }
            minlat = (float)env.MinY;
            minlon = (float)env.MinX;
            maxlat = (float)env.MaxY;
            maxlon = (float)env.MaxX;
            return(true);
        }
コード例 #33
0
        /// <summary>
        /// Creates a transformation between two coordinate systems.
        /// </summary>
        /// <remarks>
        /// This method will examine the coordinate systems in order to construct
        /// a transformation between them. This method may fail if no path between
        /// the coordinate systems is found, using the normal failing behavior of
        /// the DCP (e.g. throwing an exception).</remarks>
        /// <param name="sourceCS">Source coordinate system</param>
        /// <param name="targetCS">Target coordinate system</param>
        /// <returns></returns>
        public ICoordinateTransformation CreateFromCoordinateSystems(ICoordinateSystem sourceCS, ICoordinateSystem targetCS)
        {
            ICoordinateTransformation trans;

            if (sourceCS is IProjectedCoordinateSystem && targetCS is IGeographicCoordinateSystem) //Projected -> Geographic
            {
                trans = Proj2Geog((IProjectedCoordinateSystem)sourceCS, (IGeographicCoordinateSystem)targetCS);
            }
            else if (sourceCS is IGeographicCoordinateSystem && targetCS is IProjectedCoordinateSystem) //Geographic -> Projected
            {
                trans = Geog2Proj((IGeographicCoordinateSystem)sourceCS, (IProjectedCoordinateSystem)targetCS);
            }

            else if (sourceCS is IGeographicCoordinateSystem && targetCS is IGeocentricCoordinateSystem) //Geocentric -> Geographic
            {
                trans = Geog2Geoc((IGeographicCoordinateSystem)sourceCS, (IGeocentricCoordinateSystem)targetCS);
            }

            else if (sourceCS is IGeocentricCoordinateSystem && targetCS is IGeographicCoordinateSystem) //Geocentric -> Geographic
            {
                trans = Geoc2Geog((IGeocentricCoordinateSystem)sourceCS, (IGeographicCoordinateSystem)targetCS);
            }

            else if (sourceCS is IProjectedCoordinateSystem && targetCS is IProjectedCoordinateSystem) //Projected -> Projected
            {
                trans = Proj2Proj((sourceCS as IProjectedCoordinateSystem), (targetCS as IProjectedCoordinateSystem));
            }

            else if (sourceCS is IGeocentricCoordinateSystem && targetCS is IGeocentricCoordinateSystem) //Geocentric -> Geocentric
            {
                trans = CreateGeoc2Geoc((IGeocentricCoordinateSystem)sourceCS, (IGeocentricCoordinateSystem)targetCS);
            }

            else if (sourceCS is IGeographicCoordinateSystem && targetCS is IGeographicCoordinateSystem) //Geographic -> Geographic
            {
                trans = CreateGeog2Geog(sourceCS as IGeographicCoordinateSystem, targetCS as IGeographicCoordinateSystem);
            }
            else
            {
                throw new NotSupportedException("No support for transforming between the two specified coordinate systems");
            }

            //if (trans.MathTransform is ConcatenatedTransform) {
            //    List<ICoordinateTransformation> MTs = new List<ICoordinateTransformation>();
            //    SimplifyTrans(trans.MathTransform as ConcatenatedTransform, ref MTs);
            //    return new CoordinateTransformation(sourceCS,
            //        targetCS, TransformType.Transformation, new ConcatenatedTransform(MTs),
            //        String.Empty, String.Empty, -1, String.Empty, String.Empty);
            //}
            return(trans);
        }
コード例 #34
0
 /// <summary>Creates a new instance of the <see cref="SqlGeometryBuilder" /> class.</summary>
 /// <param name="targetSystem">The target coordinate system. If different from the source, transformations will occur.</param>
 public SqlGeometryBuilder(ICoordinateSystem targetSystem) :
     base(targetSystem)
 {
 }
コード例 #35
0
 public ICoordinateTransformation CreateTransformation(ICoordinateSystem src, ICoordinateSystem tgt)
 {
     return(_ctFactory.CreateFromCoordinateSystems(src, tgt));
 }
コード例 #36
0
        /// <summary>
        /// Creates a transformation between two coordinate systems.
        /// </summary>
        /// <remarks>
        /// This method will examine the coordinate systems in order to construct
        /// a transformation between them. This method may fail if no path between
        /// the coordinate systems is found, using the normal failing behavior of
        /// the DCP (e.g. throwing an exception).</remarks>
        /// <param name="sourceCS">Source coordinate system</param>
        /// <param name="targetCS">Target coordinate system</param>
        /// <returns>A coordinate transformation object</returns>
        /// <remarks>
        /// For this method to work properly, the input coordinate systems must either be
        /// <see cref="DotSpatialCoordinateSystem"/>s or return valid <see cref="ICoordinateSystem.WKT"/> values.
        /// </remarks>
        public ICoordinateTransformation CreateFromCoordinateSystems(ICoordinateSystem sourceCS, ICoordinateSystem targetCS)
        {
            var source = sourceCS as DotSpatialCoordinateSystem ??
                         new DotSpatialCoordinateSystem(ProjectionInfo.FromEsriString(sourceCS.WKT));

            var target = targetCS as DotSpatialCoordinateSystem ??
                         new DotSpatialCoordinateSystem(ProjectionInfo.FromEsriString(targetCS.WKT));

            return(new DotSpatialCoordinateTransformation(source, target));
        }
コード例 #37
0
        //=============================================================================
        public void Draw(ICoordinateSystem cs, DrawingContext dc)
        {
            if (cs != null && dc != null && m_bFirstPnt_IsSetted)
            {
                Pen _pen = new Pen(new SolidColorBrush(m_Color), m_Thickness);

                PathFigure pf = new PathFigure();
                if (!m_bInvalidData && m_bSecondPnt_IsSetted)
                {
                    double scaledRadius = m_rRadius * cs.Get_Scale();

                    double rFirstAngle = Math.Atan2(m_FirstPnt.Y - m_CenterPnt.Y, m_FirstPnt.X - m_CenterPnt.X);
                    // Atan2 return result in [-pi, pi]. Convert it to [0, 2pi].
                    if (rFirstAngle < 0)
                    {
                        rFirstAngle += 2 * Math.PI;
                    }
                    double rSecondAngle = Math.Atan2(m_SecondPnt.Y - m_CenterPnt.Y, m_SecondPnt.X - m_CenterPnt.X);
                    if (rSecondAngle < 0)
                    {
                        rSecondAngle += 2 * Math.PI;
                    }
                    double rThirdAngle = Math.Atan2(m_ThirdPnt.Y - m_CenterPnt.Y, m_ThirdPnt.X - m_CenterPnt.X);
                    if (rThirdAngle < 0)
                    {
                        rThirdAngle += 2 * Math.PI;
                    }

                    Point          startPnt    = m_FirstPnt;
                    Point          endPnt      = new Point(0, 0);
                    SweepDirection sd          = SweepDirection.Clockwise;
                    bool           bIsLargeArc = false;
                    if (rFirstAngle > rSecondAngle)
                    {
                        if (rFirstAngle > rThirdAngle)
                        {
                            if (rSecondAngle > rThirdAngle)
                            {
                                endPnt = m_ThirdPnt;
                                sd     = SweepDirection.Clockwise;
                                //sd = SweepDirection.Counterclockwise;
                                bIsLargeArc = (rFirstAngle - rThirdAngle) >= Math.PI;
                            }
                            else
                            {
                                endPnt = m_ThirdPnt;
                                sd     = SweepDirection.Counterclockwise;
                                //sd = SweepDirection.Clockwise;
                                bIsLargeArc = (2 * Math.PI - (rFirstAngle - rThirdAngle)) >= Math.PI;
                            }
                        }
                        else
                        {
                            endPnt = m_ThirdPnt;
                            sd     = SweepDirection.Clockwise;
                            //sd = SweepDirection.Counterclockwise;

                            double rDiff = rFirstAngle - rThirdAngle;
                            rDiff      += 2 * Math.PI;
                            bIsLargeArc = rDiff >= Math.PI;
                        }
                    }
                    else
                    {
                        if (rFirstAngle > rThirdAngle)
                        {
                            endPnt = m_ThirdPnt;
                            sd     = SweepDirection.Counterclockwise;
                            //sd = SweepDirection.Clockwise;

                            double rDiff = rFirstAngle - rThirdAngle;
                            rDiff      -= 2 * Math.PI;
                            bIsLargeArc = Math.Abs(rDiff) >= Math.PI;
                        }
                        else
                        {
                            if (rSecondAngle > rThirdAngle)
                            {
                                endPnt = m_ThirdPnt;
                                sd     = SweepDirection.Clockwise;
                                //sd = SweepDirection.Counterclockwise;

                                double rDiff = rFirstAngle - rThirdAngle;
                                rDiff      += 2 * Math.PI;
                                bIsLargeArc = Math.Abs(rDiff) >= Math.PI;
                            }
                            else
                            {
                                endPnt = m_ThirdPnt;
                                sd     = SweepDirection.Counterclockwise;
                                //sd = SweepDirection.Clockwise;

                                double rDiff = rFirstAngle - rThirdAngle;
                                //if (true || rDiff > 0)
                                //	rDiff += 2 * Math.PI;
                                bIsLargeArc = Math.Abs(rDiff) >= Math.PI;
                            }
                        }
                    }
                    pf.StartPoint = cs.GetLocalPoint(startPnt);
                    // draw arc
                    pf.Segments.Add(new ArcSegment(cs.GetLocalPoint(endPnt), new Size(scaledRadius, scaledRadius), 0, bIsLargeArc, sd, true));

                    // DEBUG INFO
                    if (false)
                    {
                        string str = string.Format("{0:F2}, {1:F2}, {2:F2}", rFirstAngle, rSecondAngle, rThirdAngle);
                        Debug.WriteLine(str);

                        Vector vec  = new Vector(4.0, 4.0);
                        Point  pnt  = cs.GetLocalPoint(m_SecondPnt);
                        Point  pnt1 = pnt - vec;
                        Point  pnt2 = pnt + vec;
                        Rect   rect = new Rect(pnt1, pnt2);
                        dc.DrawRectangle(Brushes.Aqua, _pen, rect);

                        pnt  = cs.GetLocalPoint(m_CenterPnt);
                        pnt1 = pnt - vec;
                        pnt2 = pnt + vec;
                        rect = new Rect(pnt1, pnt2);
                        dc.DrawRectangle(Brushes.Red, _pen, rect);

                        dc.DrawEllipse(null, new Pen(new SolidColorBrush(Colors.Red), 3), cs.GetLocalPoint(m_CenterPnt), scaledRadius, scaledRadius);
                    }
                }
                else
                {
                    pf.StartPoint = cs.GetLocalPoint(m_FirstPnt);
                    // draw line
                    pf.Segments.Add(new LineSegment(cs.GetLocalPoint(m_SecondPnt), true));
                }

                PathGeometry pg = new PathGeometry(new[] { pf });

                dc.DrawGeometry(null, _pen, pg);
            }
        }