//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldFindByTableAndCode() internal virtual void ShouldFindByTableAndCode() { assertThat(CoordinateReferenceSystem.Get(1, 4326), equalTo(CoordinateReferenceSystem.Wgs84)); assertThat(CoordinateReferenceSystem.Get(1, 4979), equalTo(CoordinateReferenceSystem.Wgs84_3d)); assertThat(CoordinateReferenceSystem.Get(2, 7203), equalTo(CoordinateReferenceSystem.Cartesian)); assertThat(CoordinateReferenceSystem.Get(2, 9157), equalTo(CoordinateReferenceSystem.Cartesian_3D)); }
/// <summary> /// Creates a PointValue, and enforces consistency between the CRS and coordinate dimensions. /// </summary> public static PointValue PointValue(CoordinateReferenceSystem crs, params double[] coordinate) { if (crs.Dimension != coordinate.Length) { throw new System.ArgumentException(format("Cannot create point, CRS %s expects %d dimensions, but got coordinates %s", crs, crs.Dimension, Arrays.ToString(coordinate))); } return(new PointValue(crs, coordinate)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldCalculateCartesianDistance3D() internal virtual void ShouldCalculateCartesianDistance3D() { CoordinateReferenceSystem crs = CoordinateReferenceSystem.Cartesian_3D; assertThat("", crs.Calculator.distance(Cart(0.0, 0.0, 0.0), Cart(1.0, 0.0, 0.0)), equalTo(1.0)); assertThat("", crs.Calculator.distance(Cart(0.0, 0.0, 0.0), Cart(0.0, 1.0, 0.0)), equalTo(1.0)); assertThat("", crs.Calculator.distance(Cart(0.0, 0.0, 0.0), Cart(0.0, 0.0, 1.0)), equalTo(1.0)); assertThat("", crs.Calculator.distance(Cart(0.0, 0.0, 0.0), Cart(0.0, 1.0, 1.0)), closeTo(1.41, 0.01)); assertThat("", crs.Calculator.distance(Cart(0.0, 0.0, 0.0), Cart(1.0, 1.0, 1.0)), closeTo(1.73, 0.01)); assertThat("", crs.Calculator.distance(Cart(-1000000.0, -1000000.0, -1000000.0), Cart(1000000.0, 1000000.0, 1000000.0)), closeTo(3464102.0, 1.0)); }
internal PointValue(CoordinateReferenceSystem crs, params double[] coordinate) { this._crs = crs; this._coordinate = coordinate; foreach (double c in coordinate) { if (!Double.isFinite(c)) { throw new InvalidValuesArgumentException("Cannot create a point with non-finite coordinate values: " + Arrays.ToString(coordinate)); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldCalculateCartesianDistance() internal virtual void ShouldCalculateCartesianDistance() { CoordinateReferenceSystem crs = CoordinateReferenceSystem.Cartesian; assertThat("", crs.Calculator.distance(Cart(0.0, 0.0), Cart(0.0, 1.0)), equalTo(1.0)); assertThat("", crs.Calculator.distance(Cart(0.0, 0.0), Cart(1.0, 0.0)), equalTo(1.0)); assertThat("", crs.Calculator.distance(Cart(0.0, 0.0), Cart(1.0, 1.0)), closeTo(1.4, 0.02)); assertThat("", crs.Calculator.distance(Cart(0.0, 0.0), Cart(0.0, -1.0)), equalTo(1.0)); assertThat("", crs.Calculator.distance(Cart(0.0, 0.0), Cart(-1.0, 0.0)), equalTo(1.0)); assertThat("", crs.Calculator.distance(Cart(0.0, 0.0), Cart(-1.0, -1.0)), closeTo(1.4, 0.02)); assertThat("", crs.Calculator.distance(Cart(1.0, 0.0), Cart(0.0, -1.0)), closeTo(1.4, 0.02)); assertThat("", crs.Calculator.distance(Cart(1.0, 0.0), Cart(-1.0, 0.0)), equalTo(2.0)); assertThat("", crs.Calculator.distance(Cart(1.0, 0.0), Cart(-1.0, -1.0)), closeTo(2.24, 0.01)); assertThat("", crs.Calculator.distance(Cart(-1000000.0, -1000000.0), Cart(1000000.0, 1000000.0)), closeTo(2828427.0, 1.0)); }
public override bool Equals(object o) { if (this == o) { return(true); } if (o == null || this.GetType() != o.GetType()) { return(false); } CoordinateReferenceSystem that = ( CoordinateReferenceSystem )o; return(_href.Equals(that._href)); }
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)))); }
//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)); }
//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)); }
private static CoordinateReferenceSystem FindSpecifiedCRS(PointBuilder fields) { string crsValue = fields.Crs; int sridValue = fields.Srid; if (!string.ReferenceEquals(crsValue, null) && sridValue != -1) { throw new InvalidValuesArgumentException("Cannot specify both CRS and SRID"); } else if (!string.ReferenceEquals(crsValue, null)) { return(CoordinateReferenceSystem.ByName(crsValue)); } else if (sridValue != -1) { return(CoordinateReferenceSystem.Get(sridValue)); } else { return(null); } }
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))); }
public static CoordinateReferenceSystem Crs(CRS crs) { return(CoordinateReferenceSystem.Get(crs)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldFailToGetWithIncorrectCode() internal virtual void ShouldFailToGetWithIncorrectCode() { InvalidValuesArgumentException exception = assertThrows(typeof(InvalidValuesArgumentException), () => CoordinateReferenceSystem.Get(42)); assertEquals("Unknown coordinate reference system code: 42", exception.Message); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldGetCrsByCode() internal virtual void ShouldGetCrsByCode() { assertEquals(Cartesian, CoordinateReferenceSystem.get(Cartesian.Code)); assertEquals(WGS84, CoordinateReferenceSystem.get(WGS84.Code)); }
private PointValue Geo(params double[] coords) { CoordinateReferenceSystem crs = coords.Length == 3 ? CoordinateReferenceSystem.Cartesian_3D : CoordinateReferenceSystem.Cartesian; return(Values.PointValue(crs, coords)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void writePoint(CoordinateReferenceSystem crs, double[] coordinate) throws E public override void WritePoint(CoordinateReferenceSystem crs, double[] coordinate) { // no-op }
/// <summary> /// Unlike pointValue(), this method does not enforce consistency between the CRS and coordinate dimensions. /// This can be useful for testing. /// </summary> public static PointValue UnsafePointValue(CoordinateReferenceSystem crs, params double[] coordinate) { return(new PointValue(crs, coordinate)); }
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))); } } }
/// <summary> /// The string representation of this object when indexed in string-only indexes, like lucene, for equality search only. This should normally only /// happen when points are part of composite indexes, because otherwise they are indexed in the spatial index. /// </summary> public virtual string ToIndexableString() { CoordinateReferenceSystem crs = CoordinateReferenceSystem; return(format("P:%d-%d%s", crs.Table.TableId, crs.Code, Arrays.ToString(_coordinate))); }
public override void WritePoint(CoordinateReferenceSystem crs, double[] coordinate) { Buffer.Add(new PointValue(crs, coordinate)); }
/// <summary> /// This contains the logic to decide the default coordinate reference system based on the input fields /// </summary> private static PointValue FromInputFields(PointBuilder fields) { CoordinateReferenceSystem crs = FindSpecifiedCRS(fields); double[] coordinates; if (fields.X != null && fields.Y != null) { coordinates = fields.Z != null ? new double[] { fields.X.Value, fields.Y.Value, fields.Z.Value } : new double[] { fields.X.Value, fields.Y.Value }; if (crs == null) { crs = coordinates.Length == 3 ? CoordinateReferenceSystem.Cartesian_3D : CoordinateReferenceSystem.Cartesian; } } else if (fields.Latitude != null && fields.Longitude != null) { if (fields.Z != null) { coordinates = new double[] { fields.Longitude.Value, fields.Latitude.Value, fields.Z.Value }; } else if (fields.Height != null) { coordinates = new double[] { fields.Longitude.Value, fields.Latitude.Value, fields.Height.Value }; } else { coordinates = new double[] { fields.Longitude.Value, fields.Latitude.Value }; } if (crs == null) { crs = coordinates.Length == 3 ? CoordinateReferenceSystem.Wgs84_3d : CoordinateReferenceSystem.Wgs84; } if (!crs.Geographic) { throw new InvalidValuesArgumentException("Geographic points does not support coordinate reference system: " + crs + ". This is set either in the csv header or the actual data column"); } } else { if (crs == CoordinateReferenceSystem.Cartesian) { throw new InvalidValuesArgumentException("A " + CoordinateReferenceSystem.Cartesian.Name + " point must contain 'x' and 'y'"); } else if (crs == CoordinateReferenceSystem.Cartesian_3D) { throw new InvalidValuesArgumentException("A " + CoordinateReferenceSystem.Cartesian_3D.Name + " point must contain 'x', 'y' and 'z'"); } else if (crs == CoordinateReferenceSystem.Wgs84) { throw new InvalidValuesArgumentException("A " + CoordinateReferenceSystem.Wgs84.Name + " point must contain 'latitude' and 'longitude'"); } else if (crs == CoordinateReferenceSystem.Wgs84_3d) { throw new InvalidValuesArgumentException("A " + CoordinateReferenceSystem.Wgs84_3d.Name + " point must contain 'latitude', 'longitude' and 'height'"); } throw new InvalidValuesArgumentException("A point must contain either 'x' and 'y' or 'latitude' and 'longitude'"); } if (crs.Dimension != coordinates.Length) { throw new InvalidValuesArgumentException("Cannot create point with " + crs.Dimension + "D coordinate reference system and " + coordinates.Length + " coordinates. Please consider using equivalent " + coordinates.Length + "D coordinate reference system"); } return(Values.PointValue(crs, coordinates)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void writePoint(CoordinateReferenceSystem crs, double[] coordinate) throws E public override void WritePoint(CoordinateReferenceSystem crs, double[] coordinate) { throw Exception("writePoint"); }