Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldBeAbleToParseWeirdlyFormattedPoints()
        internal virtual void ShouldBeAbleToParseWeirdlyFormattedPoints()
        {
            assertEqual(pointValue(WGS84, 1.0, 2.0), PointValue.Parse(" \t\n { latitude : 2.0  ,longitude :1.0  } \t"));
            // TODO: Should some/all of these fail?
            assertEqual(pointValue(WGS84, 1.0, 2.0), PointValue.Parse(" \t\n { latitude : 2.0  ,longitude :1.0 , } \t"));
            assertEqual(pointValue(Cartesian, 2.0E-8, -1.0E7), PointValue.Parse(" \t\n { x :+.2e-7,y: -1.0E07 , } \t"));
            assertEqual(pointValue(Cartesian, 2.0E-8, -1.0E7), PointValue.Parse(" \t\n { x :+.2e-7,y: -1.0E07 , garbage} \t"));
            assertEqual(pointValue(Cartesian, 2.0E-8, -1.0E7), PointValue.Parse(" \t\n { gar ba ge,x :+.2e-7,y: -1.0E07} \t"));
        }
Beispiel #2
0
 public static PointArray PointArray(Point[] points)
 {
     PointValue[] values = new PointValue[points.Length];
     for (int i = 0; i < points.Length; i++)
     {
         values[i] = Values.Point(points[i]);
     }
     return(new PointArray(values));
 }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldBeAbleToParseIncompletePointWithHeaderInformation()
        internal virtual void ShouldBeAbleToParseIncompletePointWithHeaderInformation()
        {
            string headerInformation = "{latitude: 40.7128}";
            string data = "{longitude: -74.0060, height: 567.8, crs:wgs-84-3D}";

            assertThrows(typeof(InvalidValuesArgumentException), () => PointValue.Parse(data));

            // this should work
            PointValue.Parse(data, PointValue.ParseHeaderInformation(headerInformation));
        }
Beispiel #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static <E extends Exception> void writeTo(ValueWriter<E> writer, org.neo4j.graphdb.spatial.Point[] values) throws E
        public static void WriteTo <E>(ValueWriter <E> writer, Point[] values) where E : Exception
        {
            writer.BeginArray(values.Length, ValueWriter_ArrayType.Point);
            foreach (Point x in values)
            {
                PointValue value = Values.Point(x);
                writer.WritePoint(value.CoordinateReferenceSystem, value.Coordinate());
            }
            writer.EndArray();
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldBeAbleToParsePointThatOverridesHeaderInformation()
        internal virtual void ShouldBeAbleToParsePointThatOverridesHeaderInformation()
        {
            string headerInformation = "{crs:wgs-84}";
            string data = "{latitude: 40.7128, longitude: -74.0060, height: 567.8, crs:wgs-84-3D}";

            PointValue expected = PointValue.Parse(data);
            PointValue actual   = PointValue.Parse(data, PointValue.ParseHeaderInformation(headerInformation));

            assertEqual(expected, actual);
            assertEquals("wgs-84-3d", actual.CoordinateReferenceSystem.Name.ToLower());
        }
Beispiel #6
0
        //-------------------------------------------------------------
        // Parser tests

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldBeAbleToParsePoints()
        internal virtual void ShouldBeAbleToParsePoints()
        {
            assertEqual(pointValue(WGS84, 13.2, 56.7), PointValue.Parse("{latitude: 56.7, longitude: 13.2}"));
            assertEqual(pointValue(WGS84, -74.0060, 40.7128), PointValue.Parse("{latitude: 40.7128, longitude: -74.0060, crs: 'wgs-84'}"));                             // - explicitly WGS84
            assertEqual(pointValue(Cartesian, -21, -45.3), PointValue.Parse("{x: -21, y: -45.3}"));                                                                     // - default to cartesian 2D
            assertEqual(pointValue(WGS84, -21, -45.3), PointValue.Parse("{x: -21, y: -45.3, srid: 4326}"));                                                             // - explicitly set WGS84 by SRID
            assertEqual(pointValue(Cartesian, 17, -52.8), PointValue.Parse("{x: 17, y: -52.8, crs: 'cartesian'}"));                                                     // - explicit cartesian 2D
            assertEqual(pointValue(WGS84_3D, 13.2, 56.7, 123.4), PointValue.Parse("{latitude: 56.7, longitude: 13.2, height: 123.4}"));                                 // - defaults to WGS84-3D
            assertEqual(pointValue(WGS84_3D, 13.2, 56.7, 123.4), PointValue.Parse("{latitude: 56.7, longitude: 13.2, z: 123.4}"));                                      // - defaults to WGS84-3D
            assertEqual(pointValue(WGS84_3D, -74.0060, 40.7128, 567.8), PointValue.Parse("{latitude: 40.7128, longitude: -74.0060, height: 567.8, crs: 'wgs-84-3D'}")); // - explicitly WGS84-3D
            assertEqual(pointValue(Cartesian_3D, -21, -45.3, 7.2), PointValue.Parse("{x: -21, y: -45.3, z: 7.2}"));                                                     // - default to cartesian 3D
            assertEqual(pointValue(Cartesian_3D, 17, -52.8, -83.1), PointValue.Parse("{x: 17, y: -52.8, z: -83.1, crs: 'cartesian-3D'}"));                              // - explicit cartesian 3D
        }
Beispiel #7
0
        public static PointArray PointArray(Value[] maybePoints)
        {
            PointValue[] values = new PointValue[maybePoints.Length];
            for (int i = 0; i < maybePoints.Length; i++)
            {
                Value maybePoint = maybePoints[i];
                if (!(maybePoint is PointValue))
                {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                    throw new System.ArgumentException(format("[%s:%s] is not a supported point value", maybePoint, maybePoint.GetType().FullName));
                }
                values[i] = Values.Point(( PointValue )maybePoint);
            }
            return(PointArray(values));
        }
Beispiel #8
0
            public override IList <Pair <PointValue, PointValue> > BoundingBox(PointValue center, double distance)
            {
                Debug.Assert(center.CoordinateReferenceSystem.Dimension == Dimension);
                double[] coordinates = center.Coordinate();
                double[] min         = new double[Dimension];
                double[] max         = new double[Dimension];
                for (int i = 0; i < Dimension; i++)
                {
                    min[i] = coordinates[i] - distance;
                    max[i] = coordinates[i] + distance;
                }
                CoordinateReferenceSystem crs = center.CoordinateReferenceSystem;

                return(Collections.singletonList(Pair.of(Values.PointValue(crs, min), Values.PointValue(crs, max))));
            }
Beispiel #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldCalculateGeographicDistance3D()
        internal virtual void ShouldCalculateGeographicDistance3D()
        {
            CoordinateReferenceSystem crs = CoordinateReferenceSystem.Wgs84_3d;
            //"distance function should measure distance from Copenhagen train station to Neo4j in Malmö"
            PointValue cph          = Geo(12.564590, 55.672874, 0.0);
            PointValue cphHigh      = Geo(12.564590, 55.672874, 1000.0);
            PointValue malmo        = Geo(12.994341, 55.611784, 0.0);
            PointValue malmoHigh    = Geo(12.994341, 55.611784, 1000.0);
            double     expected     = 27842.0;
            double     expectedHigh = 27862.0;

            assertThat("3D distance should match", crs.Calculator.distance(cph, malmo), closeTo(expected, 0.1));
            assertThat("3D distance should match", crs.Calculator.distance(cph, malmoHigh), closeTo(expectedHigh, 0.2));
            assertThat("3D distance should match", crs.Calculator.distance(cphHigh, malmo), closeTo(expectedHigh, 0.2));
        }
Beispiel #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldCalculateGeographicDistance()
        internal virtual void ShouldCalculateGeographicDistance()
        {
            CoordinateReferenceSystem crs = CoordinateReferenceSystem.Wgs84;

            assertThat("2D distance should match", crs.Calculator.distance(Geo(0.0, 0.0), Geo(0.0, 90.0)), closeTo(10000000.0, 20000.0));
            assertThat("2D distance should match", crs.Calculator.distance(Geo(0.0, 0.0), Geo(0.0, -90.0)), closeTo(10000000.0, 20000.0));
            assertThat("2D distance should match", crs.Calculator.distance(Geo(0.0, -45.0), Geo(0.0, 45.0)), closeTo(10000000.0, 20000.0));
            assertThat("2D distance should match", crs.Calculator.distance(Geo(-45.0, 0.0), Geo(45.0, 0.0)), closeTo(10000000.0, 20000.0));
            assertThat("2D distance should match", crs.Calculator.distance(Geo(-45.0, 0.0), Geo(45.0, 0.0)), closeTo(10000000.0, 20000.0));
            //"distance function should measure distance from Copenhagen train station to Neo4j in Malmö"
            PointValue cph      = Geo(12.564590, 55.672874);
            PointValue malmo    = Geo(12.994341, 55.611784);
            double     expected = 27842.0;

            assertThat("2D distance should match", crs.Calculator.distance(cph, malmo), closeTo(expected, 0.1));
        }
Beispiel #11
0
            public override double Distance(PointValue p1, PointValue p2)
            {
                Debug.Assert(p1.CoordinateReferenceSystem.Dimension == Dimension);
                Debug.Assert(p2.CoordinateReferenceSystem.Dimension == Dimension);
                double[] c1Coord             = p1.Coordinate();
                double[] c2Coord             = p2.Coordinate();
                double[] c1                  = new double[] { toRadians(c1Coord[0]), toRadians(c1Coord[1]) };
                double[] c2                  = new double[] { toRadians(c2Coord[0]), toRadians(c2Coord[1]) };
                double   dx                  = c2[0] - c1[0];
                double   dy                  = c2[1] - c1[1];
                double   alpha               = pow(sin(dy / 2), 2.0) + cos(c1[1]) * cos(c2[1]) * pow(sin(dx / 2.0), 2.0);
                double   greatCircleDistance = 2.0 * atan2(sqrt(alpha), sqrt(1 - alpha));

                if (Dimension == 2)
                {
                    return(EARTH_RADIUS_METERS * greatCircleDistance);
                }
                else if (Dimension == 3)
                {
                    // get average height
                    double avgHeight  = (p1.Coordinate()[2] + p2.Coordinate()[2]) / 2;
                    double distance2D = (EARTH_RADIUS_METERS + avgHeight) * greatCircleDistance;

                    double[] a = new double[Dimension - 1];
                    double[] b = new double[Dimension - 1];
                    a[0] = distance2D;
                    b[0] = 0.0;
                    for (int i = 1; i < Dimension - 1; i++)
                    {
                        a[i] = 0.0;
                        b[i] = c1Coord[i + 1] - c2Coord[i + 1];
                    }
                    return(Pythagoras(a, b));
                }
                else
                {
                    // The above calculation works for more than 3D if all higher dimensions are orthogonal to the 3rd dimension.
                    // This might not be true in the general case, and so until we genuinely support higher dimensions fullstack
                    // we will explicitly disabled them here for now.
                    throw new System.NotSupportedException("More than 3 dimensions are not supported for distance calculations.");
                }
            }
Beispiel #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldComparePointWithinTwoBoundsExhaustive()
        public virtual void ShouldComparePointWithinTwoBoundsExhaustive()
        {
            for (int minx = -5; minx < 5; minx++)
            {
                for (int maxx = -5; maxx < 5; maxx++)
                {
                    for (int miny = -5; miny < 5; miny++)
                    {
                        for (int maxy = -5; maxy < 5; maxy++)
                        {
                            PointValue min = pointValue(Cartesian, minx, miny);
                            PointValue max = pointValue(Cartesian, maxx, maxy);
                            for (int x = -5; x < 5; x++)
                            {
                                for (int y = -5; y < 5; y++)
                                {
                                    PointValue point = pointValue(Cartesian, x, y);
                                    bool       invalidRange = minx > maxx || miny > maxy;
                                    bool       undefinedMin = x > minx && y <miny || y> miny && x < minx;
                                    bool       undefinedMax = x <maxx && y> maxy || y <maxy && x> maxx;
                                    bool?      ii = (invalidRange || undefinedMin || undefinedMax) ? null : x >= minx && y >= miny && x <= maxx && y <= maxy;
                                    bool?      ix = (invalidRange || undefinedMin || undefinedMax) ? null : x >= minx && y >= miny && x < maxx && y < maxy;
                                    bool?      xi = (invalidRange || undefinedMin || undefinedMax) ? null : x > minx && y > miny && x <= maxx && y <= maxy;
                                    bool?      xx = (invalidRange || undefinedMin || undefinedMax) ? null : x > minx && y > miny && x < maxx && y < maxy;
                                    // inclusive:inclusive
                                    assertThat("{" + x + "," + y + "}.withinRange({" + minx + "," + miny + "}, true, {" + maxx + "," + maxy + "}, true", point.WithinRange(min, true, max, true), equalTo(ii));
                                    // inclusive:exclusive
                                    assertThat("{" + x + "," + y + "}.withinRange({" + minx + "," + miny + "}, true, {" + maxx + "," + maxy + "}, false", point.WithinRange(min, true, max, false), equalTo(ix));
                                    // exclusive:inclusive
                                    assertThat("{" + x + "," + y + "}.withinRange({" + minx + "," + miny + "}, false, {" + maxx + "," + maxy + "}, true", point.WithinRange(min, false, max, true), equalTo(xi));
                                    // exclusive:exclusive
                                    assertThat("{" + x + "," + y + "}.withinRange({" + minx + "," + miny + "}, false, {" + maxx + "," + maxy + "}, false", point.WithinRange(min, false, max, false), equalTo(xx));
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldBeAbleToParsePointWithUnquotedCrs()
        internal virtual void ShouldBeAbleToParsePointWithUnquotedCrs()
        {
            assertEqual(pointValue(WGS84_3D, -74.0060, 40.7128, 567.8), PointValue.Parse("{latitude: 40.7128, longitude: -74.0060, height: 567.8, crs:wgs-84-3D}"));                     // - explicitly WGS84-3D, without quotes
        }
Beispiel #14
0
 internal abstract Value get(PointValue value);
Beispiel #15
0
 public static PointValue MaxPointValue(PointValue reference)
 {
     double[] coordinates = new double[reference.Coordinate().Length];
     Arrays.fill(coordinates, double.MaxValue);
     return(PointValue(reference.CoordinateReferenceSystem, coordinates));
 }
Beispiel #16
0
 private InvalidValuesArgumentException AssertCannotParse(string text)
 {
     return(assertThrows(typeof(InvalidValuesArgumentException), () => PointValue.Parse(text)));
 }
Beispiel #17
0
 public override double Distance(PointValue p1, PointValue p2)
 {
     Debug.Assert(p1.CoordinateReferenceSystem.Dimension == Dimension);
     Debug.Assert(p2.CoordinateReferenceSystem.Dimension == Dimension);
     return(Pythagoras(p1.Coordinate(), p2.Coordinate()));
 }
Beispiel #18
0
 public abstract IList <Pair <PointValue, PointValue> > BoundingBox(PointValue center, double distance);
Beispiel #19
0
 public abstract double Distance(PointValue p1, PointValue p2);
Beispiel #20
0
            internal virtual Pair <PointValue, PointValue> BoundingBoxOf(double minLon, double maxLon, double minLat, double maxLat, PointValue center, double distance)
            {
                CoordinateReferenceSystem crs = center.CoordinateReferenceSystem;
                int dimension = center.CoordinateReferenceSystem.Dimension;

                double[] min = new double[dimension];
                double[] max = new double[dimension];
                min[0] = minLon;
                min[1] = minLat;
                max[0] = maxLon;
                max[1] = maxLat;
                if (dimension > 2)
                {
                    double[] coordinates = center.Coordinate();
                    for (int i = 2; i < dimension; i++)
                    {
                        min[i] = coordinates[i] - distance;
                        max[i] = coordinates[i] + distance;
                    }
                }
                return(Pair.of(Values.PointValue(crs, min), Values.PointValue(crs, max)));
            }
Beispiel #21
0
            public override IList <Pair <PointValue, PointValue> > BoundingBox(PointValue center, double distance)
            {
                if (distance == 0.0)
                {
                    return(Collections.singletonList(Pair.of(center, center)));
                }

                // Extend the distance slightly to assure that all relevant points lies inside the bounding box,
                // with rounding errors taken into account
                double extendedDistance = distance * EXTENSION_FACTOR;

                CoordinateReferenceSystem crs = center.CoordinateReferenceSystem;
                double lat = center.Coordinate()[1];
                double lon = center.Coordinate()[0];

                double r = extendedDistance / EARTH_RADIUS_METERS;

                double latMin = lat - toDegrees(r);
                double latMax = lat + toDegrees(r);

                // If your query circle includes one of the poles
                if (latMax >= 90)
                {
                    return(Collections.singletonList(BoundingBoxOf(-180, 180, latMin, 90, center, distance)));
                }
                else if (latMin <= -90)
                {
                    return(Collections.singletonList(BoundingBoxOf(-180, 180, -90, latMax, center, distance)));
                }
                else
                {
                    double deltaLon = toDegrees(asin(sin(r) / cos(toRadians(lat))));
                    double lonMin   = lon - deltaLon;
                    double lonMax   = lon + deltaLon;

                    // If you query circle wraps around the dateline
                    if (lonMin < -180 && lonMax > 180)
                    {
                        // Large rectangle covering all longitudes
                        return(Collections.singletonList(BoundingBoxOf(-180, 180, latMin, latMax, center, distance)));
                    }
                    else if (lonMin < -180)
                    {
                        // two small rectangles east and west of dateline
                        Pair <PointValue, PointValue> box1 = BoundingBoxOf(lonMin + 360, 180, latMin, latMax, center, distance);
                        Pair <PointValue, PointValue> box2 = BoundingBoxOf(-180, lonMax, latMin, latMax, center, distance);
                        return(Arrays.asList(box1, box2));
                    }
                    else if (lonMax > 180)
                    {
                        // two small rectangles east and west of dateline
                        Pair <PointValue, PointValue> box1 = BoundingBoxOf(lonMin, 180, latMin, latMax, center, distance);
                        Pair <PointValue, PointValue> box2 = BoundingBoxOf(-180, lonMax - 360, latMin, latMax, center, distance);
                        return(Arrays.asList(box1, box2));
                    }
                    else
                    {
                        return(Collections.singletonList(BoundingBoxOf(lonMin, lonMax, latMin, latMax, center, distance)));
                    }
                }
            }