Ejemplo n.º 1
0
        protected override ISimpleGeometry InitValue(AstContext context, ParseTreeNode treeNode)
        {
            var builder = new Gml.V311.GmlGeometryBuilder();

            builder.Parse(treeNode.Token.Text, CommonServiceLocator.GetCoordinateSystemProvider().Wgs84);
            return(builder.ConstructedGeometry);
        }
Ejemplo n.º 2
0
        public void ShouldParseWkt(string input, string expected)
        {
            var builder = new GmlGeometryBuilder();

            builder.Parse(input, CommonServiceLocator.GetCoordinateSystemProvider().Wgs84);

            var g = builder.ConstructedGeometry;

            Assert.Equal <string>(expected, g.ToString());
        }
Ejemplo n.º 3
0
        public void WriteJson_ShouldGenerateValidGeoJson(string wkt, string expectedJson)
        {
            var builder = new GmlGeometryBuilder(CommonServiceLocator.GetCoordinateSystemProvider().Wgs84);

            builder.Parse(wkt, CommonServiceLocator.GetCoordinateSystemProvider().Wgs84);
            var g = builder.ConstructedGeometry;

            var json = JsonConvert.SerializeObject(g, Formatting.None);

            Assert.Equal(expectedJson, json);
        }
Ejemplo n.º 4
0
            public JsonEnvelopeSink(JsonWriter writer) :
                base(CommonServiceLocator.GetCoordinateSystemProvider().Wgs84)
            {
                Debug.Assert(writer != null);
                if (writer == null)
                {
                    throw new ArgumentNullException("writer");
                }

                _Writer = writer;
            }
Ejemplo n.º 5
0
        public void InitFromGeometry_ShouldCreateValidBoundingBox(string wkt, double east, double north, double south, double west)
        {
            var wgs84   = CommonServiceLocator.GetCoordinateSystemProvider().Wgs84;
            var builder = new Ogc.Gml.V311.GmlGeometryBuilder(wgs84);

            builder.Parse(wkt, wgs84);
            var input = builder.ConstructedGeometry;

            var res = new EX_GeographicBoundingBox();

            res.InitFromGeometry(input);

            Assert.Equal(east, (double)res.eastBoundLongitude.Decimal.TypedValue);
            Assert.Equal(north, (double)res.northBoundLatitude.Decimal.TypedValue);
            Assert.Equal(south, (double)res.southBoundLatitude.Decimal.TypedValue);
            Assert.Equal(west, (double)res.westBoundLongitude.Decimal.TypedValue);
        }
Ejemplo n.º 6
0
            public JsonSink(JsonWriter writer, IGeometryTap tap) :
                base(CommonServiceLocator.GetCoordinateSystemProvider().Wgs84)
            {
                Debug.Assert(writer != null);
                if (writer == null)
                {
                    throw new ArgumentNullException("writer");
                }
                Debug.Assert(tap != null);
                if (tap == null)
                {
                    throw new ArgumentNullException("tap");
                }

                _Writer = writer;
                _Tap    = tap;
            }
Ejemplo n.º 7
0
        /// <summary>Fills the current bounding box with the specified geometry information.</summary>
        /// <param name="g">THe geometry to fill this bounding box with.</param>
        public void InitFromGeometry(ISimpleGeometry g)
        {
            if (g == null)
            {
                westBoundLongitude = null;
                eastBoundLongitude = null;
                southBoundLatitude = null;
                northBoundLatitude = null;
                return;
            }

            var lc = new List <decimal>(2);
            var uc = new List <decimal>(2);

            // Make sure it is WGS 84, and a GML 3.1.1 instance
            var builder = new Ogc.Gml.V311.GmlGeometryBuilder(CommonServiceLocator.GetCoordinateSystemProvider().Wgs84);

            g.Populate(builder);

            var envelope = builder.ConstructedGeometry.Envelope() as Ogc.Gml.V311.Envelope;

            lc.Add(Convert.ToDecimal(envelope.lowerCorner.TypedValue[0]));
            lc.Add(Convert.ToDecimal(envelope.lowerCorner.TypedValue[1]));
            uc.Add(Convert.ToDecimal(envelope.upperCorner.TypedValue[0]));
            uc.Add(Convert.ToDecimal(envelope.upperCorner.TypedValue[1]));

            westBoundLongitude = new Gco.Decimal_PropertyType()
            {
                Decimal = new Gco.Decimal(lc[0])
            };
            eastBoundLongitude = new Gco.Decimal_PropertyType()
            {
                Decimal = new Gco.Decimal(uc[0])
            };
            southBoundLatitude = new Gco.Decimal_PropertyType()
            {
                Decimal = new Gco.Decimal(lc[1])
            };
            northBoundLatitude = new Gco.Decimal_PropertyType()
            {
                Decimal = new Gco.Decimal(uc[1])
            };
        }
Ejemplo n.º 8
0
        public void ShouldSerializeToWkt(double x, double y, double?z, string expectedWkt)
        {
            var wgs84Mock = new Mock <ICoordinateSystem>(MockBehavior.Loose);

            var coords = new List <double>(new double[] { x, y });

            if (z.HasValue)
            {
                coords.Add(z.Value);
            }

            var point = new Point()
            {
                pos = new pos(),
                CoordinateSystem = CommonServiceLocator.GetCoordinateSystemProvider().Wgs84
            };

            point.pos.Untyped.Value = string.Join(
                " ",
                coords.Select <double, string>(d => d.ToString(CultureInfo.InvariantCulture))
                );

            Assert.Equal <string>(expectedWkt, point.ToString());
        }
Ejemplo n.º 9
0
 void SqlTypes.IGeometrySink.SetSrid(int srid)
 {
     SetCoordinateSystem(
         CommonServiceLocator.GetCoordinateSystemProvider().GetById(new Srid(srid))
         );
 }
Ejemplo n.º 10
0
        /// <summary>Reads the GeoJSON representation of the object. </summary>
        /// <param name="reader">The <see cref="JsonReader" /> to read from.</param>
        /// <param name="objectType">The type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>The object value.</returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }

            var builder = CreateGeometryBuilder();

            if (builder == null)
            {
                throw new InvalidOperationException();
            }

            builder.SetCoordinateSystem(CommonServiceLocator.GetCoordinateSystemProvider().Wgs84);
            if (reader.TokenType != JsonToken.StartObject)
            {
                _ThrowGeoJsonException(reader, JsonToken.StartObject);
            }

            if (!reader.Read() || (reader.TokenType != JsonToken.PropertyName) || (reader.Value.ToString() != "type"))
            {
                _ThrowGeoJsonException(reader, null);
            }

            if (!reader.Read() || (reader.TokenType != JsonToken.String))
            {
                _ThrowGeoJsonException(reader, JsonToken.String);
            }

            GeometryType type = GeometryType.Point;

            try
            {
                type = (GeometryType)Enum.Parse(typeof(GeometryType), reader.Value.ToString(), false);
            } catch (Exception ex)
            {
                throw new JsonReaderException(SR.InvalidGeoJsonException, ex);
            }

            if (!reader.Read() || (reader.TokenType != JsonToken.PropertyName))
            {
                _ThrowGeoJsonException(reader, JsonToken.PropertyName);
            }
            if (reader.Value.ToString() == "bbox")
            {
                if (!reader.Read() || reader.TokenType != JsonToken.StartArray)
                {
                    _ThrowGeoJsonException(reader, JsonToken.StartArray);
                }
                do
                {
                    if (!reader.Read())
                    {
                        _ThrowGeoJsonException(reader, null);
                    }
                } while (reader.TokenType != JsonToken.PropertyName);
            }
            if (type == GeometryType.GeometryCollection)
            {
                if (reader.Value.ToString() != "geometries")
                {
                    _ThrowGeoJsonException(reader, null);
                }
            }
            else
            {
                if (reader.Value.ToString() != "coordinates")
                {
                    _ThrowGeoJsonException(reader, null);
                }
            }

            if (!reader.Read())
            {
                _ThrowGeoJsonException(reader, null);
            }
            _ReadGeometry(reader, builder, type);

            if (reader.TokenType != JsonToken.EndObject)
            {
                _ThrowGeoJsonException(reader, JsonToken.EndObject);
            }

            return(builder.ConstructedGeometry);
        }
Ejemplo n.º 11
0
 public void SetSrid(int srid)
 {
     _Sink.SetCoordinateSystem(
         CommonServiceLocator.GetCoordinateSystemProvider().GetById(new Srid(srid))
         );
 }