当前位置: 首页>>代码示例>>C#>>正文


C# Point2.Add方法代码示例

本文整理汇总了C#中Point2.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Point2.Add方法的具体用法?C# Point2.Add怎么用?C# Point2.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Point2的用法示例。


在下文中一共展示了Point2.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Draw

        public HttpResponseMessage Draw(double? minLon, double? maxLon, double? minLat, double? maxLat, int? maxImgWidth, int? maxImgHeight)
        {
            var shapefilePath = HostingEnvironment.MapPath("~/App_Data/builtupp_usa/builtupp_usa.shp");

            ITransformation<GeographicCoordinate, Point2> transformation = null;
            var targetCrs = EpsgMicroDatabase.Default.GetCrs(3005);
            LongitudeDegreeRange dataLongitudeRange;
            Range dataLatitudeRange;
            using (var shapeFile = Shapefile.Open(shapefilePath)) {
                dataLongitudeRange = new LongitudeDegreeRange(shapeFile.Extent.MinX, shapeFile.Extent.MaxX);
                dataLatitudeRange = new Range(shapeFile.Extent.MinY, shapeFile.Extent.MaxY);

                var dataCrs = EpsgMicroDatabase.Default.GetCrs(4326);
                var pathGenerator = new EpsgCrsCoordinateOperationPathGenerator();
                var paths = pathGenerator.Generate(dataCrs, targetCrs);
                var compiler = new StaticCoordinateOperationCompiler();
                var firstTransfom = paths.Select(p => {
                    return compiler.Compile(p);
                }).First(x => x != null);

                transformation = firstTransfom as ITransformation<GeographicCoordinate, Point2>;
                if (transformation == null && firstTransfom is IEnumerable<ITransformation>)
                    transformation = new CompiledConcatenatedTransformation<GeographicCoordinate, Point2>((IEnumerable<ITransformation>)firstTransfom);

            }

            var geoMbrMin = new GeographicCoordinate(minLat ?? dataLatitudeRange.Low, minLon ?? dataLongitudeRange.Start);
            var geoMbrMax = new GeographicCoordinate(maxLat ?? dataLatitudeRange.High, maxLon ?? dataLongitudeRange.End);
            var geoMbrTL = new GeographicCoordinate(geoMbrMax.Latitude, geoMbrMin.Longitude);
            var geoMbrTR = new GeographicCoordinate(geoMbrMin.Latitude, geoMbrMax.Longitude);

            var projectedMbrPoints = new[] {
                    geoMbrMin,
                    geoMbrMax,
                    geoMbrTL,
                    geoMbrTR,
                    new GeographicCoordinate(geoMbrMin.Latitude, Math.Abs(geoMbrMin.Longitude + geoMbrMax.Longitude) / 2.0)
                }
                .Select(transformation.TransformValue)
                .ToArray();

            var projectedExtent = new Mbr(
                new Point2(projectedMbrPoints.Min(x => x.X), projectedMbrPoints.Min(x => x.Y)),
                new Point2(projectedMbrPoints.Max(x => x.X), projectedMbrPoints.Max(x => x.Y))
            );

            var geogMapOrigin = new GeographicCoordinate(dataLatitudeRange.Mid, dataLongitudeRange.Mid);
            var mapOrigin = transformation.TransformValue(geogMapOrigin);

            var mapOffset = new Vector2(0/*-(mapOrigin.X - projectedExtent.X.Mid)*/, projectedExtent.Height / 2.0);

            var imageSizeLimits = new Vector2(maxImgWidth ?? 300, maxImgHeight ?? 300);
            if (imageSizeLimits.X > 4096 || imageSizeLimits.Y > 4096)
                throw new ArgumentException("Image size too large");

            var dataRatio = new Vector2(projectedExtent.Width / imageSizeLimits.X, projectedExtent.Height / imageSizeLimits.Y);
            var lowCorner = projectedExtent.Min;
            Vector2 desiredImageSize;
            double imageScaleFactor;
            if (dataRatio.Y < dataRatio.X) {
                imageScaleFactor = imageSizeLimits.X / projectedExtent.Width;
                desiredImageSize = new Vector2(imageSizeLimits.X, (int)(projectedExtent.Height * imageScaleFactor));
            }
            else {
                imageScaleFactor = imageSizeLimits.Y / projectedExtent.Height;
                desiredImageSize = new Vector2((int)(projectedExtent.Width * imageScaleFactor), imageSizeLimits.Y);
            }

            using (var image = new System.Drawing.Bitmap((int)desiredImageSize.X, (int)desiredImageSize.Y))
            using (var graphics = Graphics.FromImage(image)) {
                graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                var shapeSource = new PointShapefileShapeSource(shapefilePath);
                var shapeReader = new ShapeReader(shapeSource);
                using (var shapeEnumerator = shapeReader.GetEnumerator()) {
                    var sourceCoordinates = ReadPagesToGeographicCoordinate(shapeEnumerator).SelectMany(x => x);
                    var pointColor = Color.Black;
                    var circleFillBrush = new SolidBrush(Color.FromArgb(64,16,64,128));
                    var featureRadius = 3.0;
                    var featureDiameter = featureRadius * 2;
                    var featureDiameterFloat = (float)featureDiameter;
                    var topLeftOffset = new Vector2(-featureRadius,-featureRadius);

                    foreach (var transformedPoint in transformation.TransformValues(sourceCoordinates)) {
                        var offsetPoint = transformedPoint.Difference(lowCorner).Add(mapOffset);

                        var scaledPoint = offsetPoint.GetScaled(imageScaleFactor);
                        var screenPoint = new Point2(scaledPoint.X, image.Height - scaledPoint.Y);
                        var drawTopLeft = screenPoint.Add(topLeftOffset);

                        graphics.FillEllipse(circleFillBrush, (float)drawTopLeft.X, (float)drawTopLeft.Y, featureDiameterFloat, featureDiameterFloat);
                    }
                }
                var result = new HttpResponseMessage(HttpStatusCode.OK);
                byte[] imageBytes;
                using (var memoryStream = new MemoryStream()) {
                    image.Save(memoryStream, ImageFormat.Png);
                    imageBytes = memoryStream.ToArray();
                }
                result.Content = new ByteArrayContent(imageBytes);
                result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/png");
//.........这里部分代码省略.........
开发者ID:aarondandy,项目名称:pigeoid,代码行数:101,代码来源:PrettyPictureController.cs

示例2: add

        public void add() {
            var a = new Point2(1, 3);
            var v = new Vector2(2, 4);

            var sum = a.Add(v);

            Assert.Equal(a.X + v.X, sum.X);
            Assert.Equal(a.Y + v.Y, sum.Y);
        }
开发者ID:aarondandy,项目名称:vertesaur,代码行数:9,代码来源:Point2Facts.cs


注:本文中的Point2.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。