コード例 #1
0
        /// <summary>
        /// Аппроксимация двумерного графика
        /// (необходимо, когда точки расположены очень близко друг к другу, т.е. человеческий глаз не отличит (5 пикселей))
        /// (это даёт увеличение производительности и сбережение памяти)
        /// </summary>
        /// <param name="geometryGraphic">исходный двумерный график</param>
        /// <param name="isAppearApproximation">флаг-признак наличия аппроксимации</param>
        /// /// <param name="accuracyApproximationPx">Коэффициент применения аппроксимации в px</param>
        /// <returns>аппроксимированный двумерный график</returns>
        public static GeometryGraphic Approximation(GeometryGraphic geometryGraphic, ref bool isAppearApproximation, double accuracyApproximationPx)
        {
            isAppearApproximation = false;
            GeometryGraphic resultGeometryGraphic = new GeometryGraphic();

            if (geometryGraphic.Points.Count < 30)
            {
                return(geometryGraphic);
            }
            resultGeometryGraphic.Points.Add(geometryGraphic.Points[0]);
            resultGeometryGraphic.Points.Add(geometryGraphic.Points[1]);
            GeometryPoint prevPt      = geometryGraphic.Points[1];
            int           countPoints = geometryGraphic.Points.Count;

            for (int i = 2; i < countPoints - 1; i++)
            {
                if ((geometryGraphic.Points[i].X - prevPt.X) < accuracyApproximationPx)
                {
                    isAppearApproximation = true;
                    continue;
                }
                else
                {
                    resultGeometryGraphic.Points.Add(geometryGraphic.Points[i]);
                    prevPt = geometryGraphic.Points[i];
                }
            }
            resultGeometryGraphic.Points.Add(geometryGraphic.Points[countPoints - 1]);
            return(resultGeometryGraphic);
        }
コード例 #2
0
        public void GeometryPointToGeometryShouldNotDoAnything()
        {
            var point  = GeometryPoint.Create(1, 2);
            var result = this.jsonConverter.ConvertPrimitiveValue(point, typeof(Geometry));

            result.Should().BeSameAs(point);
        }
コード例 #3
0
        public void UpdateNote(string username, int id, GeometryPoint geometryPoint, string body)
        {
            var user = dbContext.Users.FirstOrDefault(u => u.Username == username);

            if (user == null)
            {
                throw new UserNotFoundException($"{username} not found.");
            }
            var note = dbContext.Notes
                       .FirstOrDefault(n => n.Id == id);

            if (note == null)
            {
                throw new NoteNotFoundException($"Note with {id} not found.");
            }
            if (note.Owner.Id != user.Id)
            {
                throw new System.InvalidOperationException("Only note creator can change the note");
            }
            var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
            var point           = geometryPoint as GeometryPoint;
            var geoPoint        = geometryFactory.CreatePoint(new NetTopologySuite.Geometries.Coordinate(point.X, point.Y));

            note.Location = geoPoint;
            note.Body     = body;
            note.Modified = DateTime.UtcNow;
            dbContext.SaveChanges();
        }
コード例 #4
0
        public void StoringNoteForWrongUserId_shouldThrow()
        {
            var remarkService = new RemarkServices(landmarkRemarkContext);
            var location      = GeometryPoint.Create(-122.12, 47.67);

            remarkService.Invoking(rs => rs.CreateNote("testuser1", location, "Note A")).Should().Throw <UserNotFoundException>();
        }
コード例 #5
0
        public void BindLiteralShouldReturnQueryNode()
        {
            var          value  = GeometryPoint.Create(5, 2);
            ConstantNode result = LiteralBinder.BindLiteral(new LiteralToken(value)) as ConstantNode;

            result.Value.Should().Be(value);
        }
コード例 #6
0
    // Update is called once per frame
    void Update()
    {
        if (check_topic)
        {
            foreach (GameObject item in GameObject.FindGameObjectsWithTag("YoloName"))
            {
                Destroy(item);
            }

            foreach (var yolo_target in yolores.markers)
            {
                GeometryPoint obj_position = yolo_target.pose.position;
                GameObject    obj_label    = Instantiate(ObjectLabels) as GameObject;
                obj_label.transform.parent = Root.transform;

                string obj_name = yolo_target.text;

                obj_label.transform.localPosition =
                    new Vector3(-obj_position.y, obj_position.z, obj_position.x);


                obj_label.GetComponent <TextMesh>().text = obj_name;
            }

            Array.Clear(yolores.markers, 0, yolores.markers.Length);
            check_topic = false;
        }
    }
コード例 #7
0
ファイル: SpatialTestUtils.cs プロジェクト: sivethe/odata.net
 private static void VerifyPosition(PositionData expected, GeometryPoint actual)
 {
     Assert.Equal(expected.Latitude, actual.X);
     Assert.Equal(expected.Longitude, actual.Y);
     Assert.Equal(expected.Z, actual.Z);
     Assert.Equal(expected.M, actual.M);
 }
コード例 #8
0
        static GeometryPoint GetGeometryPointFrom(SourcePoint srcPt, double val, Rect rect, double timeInPoint, TimeSpan leftTime, TimeSpan time)
        {
            Point         curPosPoint = new Point(rect.Location.X + ToolFunctions.GetDxByTime(time, timeInPoint, leftTime), val);
            GeometryPoint curPoint    = new GeometryPoint(curPosPoint, srcPt);

            return(curPoint);
        }
コード例 #9
0
 public void WriteRawValueWritesGeometryValue()
 {
     RawValueWriter target = new RawValueWriter(this.settings, this.stream, new UTF32Encoding());
     var value2 = GeometryPoint.Create(1.2, 3.16);
     target.WriteRawValue(value2);
     this.StreamAsString(target).Should().Be("SRID=0;POINT (1.2 3.16)");
 }
コード例 #10
0
        public void GeometryWorksWithTwoDimensions()
        {
            GeometryPoint geometryPoint = LiteralUtils.ParseGeometry("POINT(10 30)") as GeometryPoint;

            geometryPoint.X.ShouldBe(10.0);
            geometryPoint.Y.ShouldBe(30.0);
        }
コード例 #11
0
        public void BuildPoint()
        {
            GeometryPoint p = GeometryFactory.Point(NonDefaultGeometricCoords, 10, 20, 30, 40);

            Assert.AreEqual(NonDefaultGeometricCoords, p.CoordinateSystem);
            p.VerifyAsPoint(new PositionData(10, 20, 30, 40));

            p = GeometryFactory.Point(NonDefaultGeometricCoords, 10, 20);
            Assert.AreEqual(NonDefaultGeometricCoords, p.CoordinateSystem);
            p.VerifyAsPoint(new PositionData(10, 20));

            p = GeometryFactory.Point(10, 20, 30, 40);
            Assert.AreEqual(CoordinateSystem.DefaultGeometry, p.CoordinateSystem);
            p.VerifyAsPoint(new PositionData(10, 20, 30, 40));

            p = GeometryFactory.Point(10, 20);
            Assert.AreEqual(CoordinateSystem.DefaultGeometry, p.CoordinateSystem);
            p.VerifyAsPoint(new PositionData(10, 20));

            p = GeometryFactory.Point();
            Assert.AreEqual(CoordinateSystem.DefaultGeometry, p.CoordinateSystem);
            p.VerifyAsPoint(null);

            p = GeometryFactory.Point(NonDefaultGeometricCoords);
            Assert.AreEqual(NonDefaultGeometricCoords, p.CoordinateSystem);
            p.VerifyAsPoint(null);

            p = GeometryFactory.Point().LineTo(10, 20);
            Assert.AreEqual(CoordinateSystem.DefaultGeometry, p.CoordinateSystem);
            p.VerifyAsPoint(new PositionData(10, 20));
        }
コード例 #12
0
        public IActionResult UpdateNote(Model.Note note)
        {
            var username = HttpContext.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Upn).Value;

            remarkService.UpdateNote(username, note.Id, GeometryPoint.Create(note.X, note.Y), note.Body);
            return(Ok());
        }
コード例 #13
0
        public static GeometryPoint[] ConvertToLine(this GeometryPoint point, double heading, double lineLength)
        {
            double distance = lineLength / 2;
            List <GeometryPoint> linePoints = new List <GeometryPoint>();

            if (heading == 0 || heading == 180 || heading == 360)
            {
                linePoints.Add(GeometryPoint.Create(point.X + distance, point.Y));
                linePoints.Add(GeometryPoint.Create(point.X - distance, point.Y));
            }
            else if (heading == 90 || heading == 270)
            {
                linePoints.Add(GeometryPoint.Create(point.X, point.Y + distance));
                linePoints.Add(GeometryPoint.Create(point.X, point.Y - distance));
            }
            else
            {
                double m = Math.Tan(heading);
                double c = point.Y - (m * point.X);

                double positiveX = point.X + (distance / (Math.Sqrt(1 + (m * m))));
                double positiveY = (m * positiveX) + c;
                linePoints.Add(GeometryPoint.Create(positiveX, positiveY, null, m));

                double negativeX = point.X + ((-distance) / (Math.Sqrt(1 + (m * m))));
                double negativeY = (m * positiveX) + c;
                linePoints.Add(GeometryPoint.Create(negativeX, negativeY, null, m));

                //double xDifference = point.X - x;
                //double yDifference = point.Y - (m * x + c);
                //double d = Math.Sqrt(((point.X - x) * (point.X - x)) + ((point.Y - (m * x + c)) * (point.Y - (m * x + c))));
            }

            return(linePoints.ToArray());
        }
コード例 #14
0
        /// <summary>
        /// Построение геометрической информации
        /// </summary>
        /// <param name="srcGraphic">исходный двумерный график</param>
        /// <param name="rect">область вывода на экране</param>
        /// <returns>геометрическиая информация</returns>
        public static PathGeometry ConstructGeometry(GeometryGraphic srcGraphic, Rect rect, TimeSpan leftTimeBorder, TimeSpan rightTimeBorder)
        {
            PathGeometry PtColl = new PathGeometry();

            if (srcGraphic.Points.Count == 0)
            {
                return(PtColl);
            }
            GeometryPoint prevPt = srcGraphic.Points[0];

            if ((prevPt.SourcePoint.Time.CompareTo(leftTimeBorder) >= 0) && (prevPt.SourcePoint.Time.CompareTo(rightTimeBorder) <= 0))
            {
                PtColl.AddGeometry(new EllipseGeometry(prevPt.Position, 1, 1));
            }
            foreach (GeometryPoint item in srcGraphic.Points)
            {
                if (prevPt.Y != item.Y)
                {
                    if ((prevPt.SourcePoint.Time.CompareTo(leftTimeBorder) >= 0) && (prevPt.SourcePoint.Time.CompareTo(rightTimeBorder) <= 0))
                    {
                        PtColl.AddGeometry(new EllipseGeometry(item.Position, 1, 1));
                    }
                    prevPt = item;
                }
            }
            return(PtColl);
        }
コード例 #15
0
        public IEnumerable <Note> GetNotesByLocation(Geometry location, int userId = 0)
        {
            var point           = location as GeometryPoint;
            var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
            var geoPoint        = geometryFactory.CreatePoint(new NetTopologySuite.Geometries.Coordinate(point.X, point.Y));

            var x = dbContext.Notes.Select(n => n.Location.Distance(geoPoint));

            return(dbContext.Notes
                   //.Where(n => n.Location.IsWithinDistance(geoPoint, 0.01))
                   .Join(dbContext.Users, n => n.Owner.Id, u => u.Id, (n, u) => new { n, u })
                   .OrderBy(n => n.n.Location.Distance(geoPoint))
                   .Take(100)
                   .Select(nu => new Note
            {
                Id = nu.n.Id,
                Owner = new UserInfo
                {
                    Username = nu.u.Username,
                    Firstname = nu.u.Firstname,
                    Lastname = nu.u.Lastname
                },
                Body = nu.n.Body,
                Location = GeometryPoint.Create(nu.n.Location.Coordinate.X, nu.n.Location.Coordinate.Y)
            }));
        }
コード例 #16
0
ファイル: PathBuilderTests.cs プロジェクト: zew1me/odata.net
        public void GeometryAndNullParameterValuesShouldWorkInPath()
        {
            var point     = GeometryPoint.Create(1, 2);
            Uri queryUri  = new Uri("Paintings(0)/Fully.Qualified.Namespace.GetColorAtPosition(position=geometry'" + SpatialHelpers.WriteSpatial(point) + "',includeAlpha=null)", UriKind.Relative);
            Uri actualUri = UriBuilder(queryUri, ODataUrlKeyDelimiter.Parentheses, settings);

            Assert.Equal(new Uri("http://gobbledygook/Paintings(0)/Fully.Qualified.Namespace.GetColorAtPosition(position=geometry'" + SpatialHelpers.WriteSpatial(point) + "',includeAlpha=null)"), actualUri);
        }
コード例 #17
0
        public void WriteRawValueWritesGeometryValue()
        {
            RawValueWriter target = new RawValueWriter(this.settings, this.stream, new UTF32Encoding());
            var            value  = GeometryPoint.Create(1.2, 3.16);

            target.WriteRawValue(value);
            Assert.Equal(@"{""type"":""Point"",""coordinates"":[1.2,3.16],""crs"":{""type"":""name"",""properties"":{""name"":""EPSG:0""}}}", this.StreamAsString(target));
        }
コード例 #18
0
 public void BuildPropertyContextUriForSpatialPropertyValue()
 {
     foreach (ODataVersion version in Versions)
     {
         var contextUri = this.CreatePropertyContextUri(GeometryPoint.Create(1, 2), version);
         contextUri.OriginalString.Should().Be(BuildExpectedContextUri("#Edm.GeometryPoint"));
     }
 }
コード例 #19
0
        public InventorOrdinateDimension AddMember(GeometryPoint point)
        {
            var newMember = new InventorOrdinateDimension(_ordinateDimensionSet.AddMember(point.CreateIntent()));

            Add(newMember);

            return(newMember);
        }
コード例 #20
0
        public void GeometryToGeographyInJson()
        {
            var point  = GeometryPoint.Create(1, 2);
            var result = this.jsonConverter.ConvertPrimitiveValue(point, typeof(GeographyPoint));

            result.Should().BeAssignableTo <GeographyPoint>();
            result.As <GeographyPoint>().Latitude.Should().BeInRange(2, 2);
            result.As <GeographyPoint>().Longitude.Should().BeInRange(1, 1);
        }
コード例 #21
0
        public void GeometryWorksWithTwoDimensions()
        {
            GeometryPoint geometryPoint = LiteralUtils.ParseGeometry("POINT(10 30)") as GeometryPoint;

            Assert.Equal(10.0, geometryPoint.X);
            Assert.Equal(30.0, geometryPoint.Y);
            Assert.Null(geometryPoint.Z);
            Assert.Null(geometryPoint.M);
        }
コード例 #22
0
        public void GeometryParameterShouldParseCorrectly()
        {
            var point = GeometryPoint.Create(1.0, 2.0);
            ICollection <OperationSegmentParameter> parsedParameters;

            TryParseOperationParameters("GetColorAtPosition", "position=geometry'" + SpatialHelpers.WriteSpatial(point) + "',includeAlpha=true", null, HardCodedTestModel.GetColorAtPositionFunction(), out parsedParameters).Should().BeTrue();
            parsedParameters.Should().HaveCount(2);
            parsedParameters.First().ShouldBeConstantParameterWithValueType("position", point);
        }
コード例 #23
0
ファイル: SpatialLibTest.cs プロジェクト: zhonli/odata.net
        public void BasicTest()
        {
            GeometryPoint point1 = GeometryPoint.Create(1, 1);

            double expectedValue = 1.0;

            Assert.True(expectedValue.Equals(point1.X));
            Assert.True(expectedValue.Equals(point1.Y));
            Console.WriteLine(point1.CoordinateSystem);
        }
コード例 #24
0
        public void TestCreateMethodAll4DimensionsDefaultCoords()
        {
            GeometryPoint point = GeometryPoint.Create(10, 20, 30, 40);

            Assert.AreEqual(10, point.X);
            Assert.AreEqual(20, point.Y);
            Assert.AreEqual(30, point.Z);
            Assert.AreEqual(40, point.M);
            Assert.AreEqual(CoordinateSystem.DefaultGeometry, point.CoordinateSystem);
        }
コード例 #25
0
        public void TestCreateMethod2DimensionsDefaultCoords()
        {
            GeometryPoint point = GeometryPoint.Create(15, 25);

            Assert.AreEqual(15, point.X);
            Assert.AreEqual(25, point.Y);
            Assert.IsFalse(point.Z.HasValue);
            Assert.IsFalse(point.M.HasValue);
            Assert.AreEqual(CoordinateSystem.DefaultGeometry, point.CoordinateSystem);
        }
コード例 #26
0
        public void TranslatorSpatialLiteralTest()
        {
            var point = GeometryPoint.Create(1, 2);

            this.TestConstant(point, c =>
            {
                c.Value.Should().BeSameAs(point);
                c.Type.Should().Be(typeof(GeometryPoint));
            });
        }
コード例 #27
0
        public void GetNotesTakenOnLocation()
        {
            CreateNotes();
            var remarkService = new RemarkServices(landmarkRemarkContext);
            var notes         = remarkService.GetNotesByLocation(GeometryPoint.Create(-122.13, 47.68));

            notes.Should().HaveCount(3);
            notes.First().Body.Should().Be("Note C");
            notes.First().Owner.Username.Should().Be("testuser2");
        }
コード例 #28
0
ファイル: TypeConverters.cs プロジェクト: GGZORR/OdataSample
 public static GeometryPoint CreateGeometryPoint(IDictionary <string, object> source)
 {
     return(GeometryPoint.Create(
                CoordinateSystem.Geometry(source.ContainsKey("CoordinateSystem")
             ? source.GetValueOrDefault <CoordinateSystem>("CoordinateSystem").EpsgId
             : null),
                source.GetValueOrDefault <double>("Latitude"),
                source.GetValueOrDefault <double>("Longitude"),
                source.GetValueOrDefault <double?>("Z"),
                source.GetValueOrDefault <double?>("M")));
 }
コード例 #29
0
        public async Task WriteRawGeometryValuesync()
        {
            var value = GeometryPoint.Create(1.2, 3.16);

            var result = await SetupRawValueWriterAndRunTestAsync(
                (rawValueWriter) => rawValueWriter.WriteRawValueAsync(value));

            Assert.Equal(
                "{\"type\":\"Point\",\"coordinates\":[1.2,3.16],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:0\"}}}",
                result);
        }
コード例 #30
0
        public void TestCreateMethod3DimensionsCustomCoords()
        {
            CoordinateSystem coords = CoordinateSystem.Geometry(12);
            GeometryPoint    point  = GeometryPoint.Create(coords, 10, 20, 30, 40);

            Assert.AreEqual(10, point.X);
            Assert.AreEqual(20, point.Y);
            Assert.AreEqual(30, point.Z);
            Assert.AreEqual(40, point.M);
            Assert.AreEqual(coords, point.CoordinateSystem);
        }
コード例 #31
0
 public void Initialize(int size, double minX, double maxX, double minY, double maxY)
 {
     if (size <= 0) throw new ArgumentOutOfRangeException();
     geometrypoints = new GeometryPoint[size];
     Random rnd = new Random(DateTime.Now.Millisecond);
     double xRange = maxX - minX;
     double yRange = maxY - minY;
     int MaxXPointIndex = 0;//选取x坐标最大的点
     for (int i = 0; i < size; i++)
     {
         GeometryPoint gp = new GeometryPoint(minX + xRange * rnd.NextDouble(), minY + yRange * rnd.NextDouble());
         geometrypoints[i] = gp;
         if (geometrypoints[MaxXPointIndex].X < gp.X)////选取x坐标最大的点
         {
             MaxXPointIndex = i;
         }
         else if (geometrypoints[MaxXPointIndex].X < gp.X && geometrypoints[MaxXPointIndex].Y > gp.Y)//选取x坐标最大的点,如果最大x坐标点有多个,去y最小者
         {
             MaxXPointIndex = i;
         }
     }
     //计算斜率
     for (int i = 0; i < size; i++)
     {
         if (i == MaxXPointIndex)
         {
             geometrypoints[MaxXPointIndex].SLOPE = double.MaxValue;
         }
         else
         {
             if (geometrypoints[i].X == geometrypoints[MaxXPointIndex].X)//与最大x坐标的x相同的点,因为x坐标之差为零,所以取SLOPE最大值
             {
                 geometrypoints[i].SLOPE = double.MaxValue;
             }
             else//计算斜率,注意正切函数在-0.5Pi和0.5Pi之间是单调递增的
             {
                 geometrypoints[i].SLOPE = (geometrypoints[i].Y - geometrypoints[MaxXPointIndex].Y) / (geometrypoints[MaxXPointIndex].X - geometrypoints[i].X);
             }
         }
     }
     //按照斜率slope排序,取稳定排序方法的堆排序。
     HeapSort<GeometryPoint> heapsort = new HeapSort<GeometryPoint>();
     heapsort.Sort(this.geometrypoints,0,size-1);
 }
コード例 #32
0
ファイル: GeometryPoint.cs プロジェクト: larsenjo/odata.net
 public bool Equals(GeometryPoint other)
 {
     return this.BaseEquals(other) ?? this.X == other.X && this.Y == other.Y && this.Z == other.Z && this.M == other.M;
 }