Example #1
0
        /// <summary>
        /// Transforms from world coordinate system (WCS) to image coordinates
        /// NOTE: This method DOES NOT take the MapTransform property into account (use <see cref="Map.WorldToImage(GeoAPI.Geometries.Coordinate,bool)"/> instead)
        /// </summary>
        /// <param name="p">Point in WCS</param>
        /// <param name="map">Map reference</param>
        /// <returns>Point in image coordinates</returns>
        public static ScreenPointF WorldtoMap(Coordinate p, Map map)
        {
            //if (map.MapTransform != null && !map.MapTransform.IsIdentity)
            //	map.MapTransform.TransformPoints(new System.Drawing.PointF[] { p });
            if (GeoAPIEx.IsEmpty(p))
                return ScreenPointF.Empty;

            var result = new ScreenPointF();

            var height = (map.Zoom * map.Size.Height) / map.Size.Width;
            var left = map.Center.X - map.Zoom * 0.5;
            var top = map.Center.Y + height * 0.5 * map.PixelAspectRatio;
            result.X = (float)((p.X - left) / map.PixelWidth);
            result.Y = (float)((top - p.Y) / map.PixelHeight);
            if (double.IsNaN(result.X) || double.IsNaN(result.Y))
                result = ScreenPointF.Empty;
            return result;
        }
Example #2
0
 /// <summary>
 /// Transforms an array of <see cref="Coordinate"/>s to an array of <see cref="PointF"/>s.
 /// </summary>
 /// <param name="vertices">The array of coordinates</param>
 /// <param name="map">The map that defines the affine coordinate transformation</param>
 /// <returns>The array of <see cref="PointF"/>s</returns>
 private static ScreenPointF[] TransformToImage(Coordinate[] vertices, Map map)
 {
     var v = new ScreenPointF[vertices.Length];
     for (var i = 0; i < vertices.Length; i++)
         v[i] = Transform.WorldtoMap(vertices[i], map);
     return v;
 }