Ejemplo n.º 1
0
        public Image CropReceiptSection(Image source, Models.BoundingBox section)
        {
            var bitmap       = new Bitmap(source);
            var rectangle    = ConvertToRectangle(section, source.Width, source.Height);
            var croppedImage = bitmap.Clone(rectangle, bitmap.PixelFormat);

            return(croppedImage);
        }
Ejemplo n.º 2
0
 private Rectangle ConvertToRectangle(Models.BoundingBox source, int imageWidth, int imageHeight)
 {
     return(new Rectangle
     {
         X = (int)(source.Left * imageWidth),
         Y = (int)(source.Top * imageHeight),
         Width = (int)(source.Width * imageWidth),
         Height = (int)(source.Height * imageHeight)
     });
 }
Ejemplo n.º 3
0
        public FeatureCollection GetStates(Models.BoundingBox bbox, int zoom)
        {
            var features = new List <Feature>();

            // HACK! limit West to date line
            var inbox = bbox;

            if (bbox.West > bbox.East)
            {
                inbox = new BoundingBox()
                {
                    North = bbox.North,
                    South = bbox.South,
                    West  = -179.999,
                    East  = bbox.East
                };
            }
            var box = GeoJsonConvert.GeometryFromBoundingBox(inbox);

            using (var conn = GetOpenConnection())
            {
                using (var cmd = new SqlCommand(@"GetStatesWithinBox", conn))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@Bounds", System.Data.SqlDbType.Udt)
                    {
                        UdtTypeName = "geometry",
                        Value       = box
                    });
                    cmd.Parameters.AddWithValue("@Zoom", zoom);
                    using (var rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            var border     = (SqlGeometry)rdr["Border"];
                            var properties = new Dictionary <string, string>();
                            properties.Add("name", (String)rdr["Name"]);
                            features.Add(new Feature()
                            {
                                geometry   = GeoJsonConvert.GeoJsonMultiPolygonFromGeometry(border),
                                properties = properties
                            });
                        }
                    }
                }
            }
            var fc = new FeatureCollection()
            {
                features = features.ToArray()
            };

            return(fc);
        }
Ejemplo n.º 4
0
        public static Models.BoundingBox ConvertBingBoundingBox(BoundingBoxRequest.BoundingBox bbox)
        {
            var bb = new Models.BoundingBox()
            {
                North = bbox.center.latitude + (bbox.height / 2),
                South = bbox.center.latitude - (bbox.height / 2),
                West  = bbox.center.longitude - (bbox.width / 2),
                East  = bbox.center.longitude + (bbox.width / 2)
            };

            return(bb);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Build an SqlGeometry Polygon from a bounding box.
        /// </summary>
        /// <param name="box">Bounding Box</param>
        /// <returns>SqlGeometry Polygon</returns>
        public static SqlGeometry GeometryFromBoundingBox(Models.BoundingBox box, int srid = 4326)
        {
            var geob = new SqlGeometryBuilder();

            geob.SetSrid(srid);
            geob.BeginGeometry(OpenGisGeometryType.Polygon);
            geob.BeginFigure(box.minX, box.maxY);
            geob.AddLine(box.minX, box.minY);
            geob.AddLine(box.maxX, box.minY);
            geob.AddLine(box.maxX, box.maxY);
            geob.AddLine(box.minX, box.maxY);
            geob.EndFigure();
            geob.EndGeometry();
            var geom = geob.ConstructedGeometry;

            //Debug.WriteLine(geog.AsGml().Value);
            return(geom);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Build an SqlGeography Polygon from a bounding box.
        /// </summary>
        /// <param name="box">Bounding Box</param>
        /// <returns>SqlGeography Polygon</returns>
        public static SqlGeography GeographyFromBoundingBox(Models.BoundingBox box)
        {
            var geob = new SqlGeographyBuilder();

            geob.SetSrid(SRID);
            geob.BeginGeography(OpenGisGeographyType.Polygon);
            geob.BeginFigure(box.South, box.West);
            geob.AddLine(box.South, box.East);
            geob.AddLine(box.North, box.East);
            geob.AddLine(box.North, box.West);
            geob.AddLine(box.South, box.West);
            geob.EndFigure();
            geob.EndGeography();
            var geog = geob.ConstructedGeography;

            //Trace.WriteLine("GeographyFromBoundingBox : " + geog.AsGml().Value);
            return(geog);
        }