/// <summary>
		/// Serializes the object to the stream as GeoJson.
		/// </summary>
		/// <param name="type"></param>
		/// <param name="value"></param>
		/// <param name="writeStream"></param>
		/// <param name="content"></param>
		public override void WriteToStream(Type type, object value, Stream writeStream, HttpContent content)
		{
			using (var writer = new StreamWriter(writeStream) { AutoFlush = true })
			{
				var serializer = new GeoJsonSerializer();
				serializer.Serialize(writer, value);
			}
		}
Example #2
0
 public static string GetPolygonAsGeoJSON()
 {
     var poly = GetAPolygon();
     var jsonSerializer = new GeoJsonSerializer();
     var sw = new System.IO.StringWriter();
     jsonSerializer.Serialize(sw, poly);
     return sw.ToString();
 }
 /// <summary>
 /// Writes any specified object.
 /// </summary>
 /// <param name="value">Any object.</param>
 /// <returns></returns>
 public string Write(object value)
 {
     JsonSerializer g = new GeoJsonSerializer();
     StringBuilder sb = new StringBuilder();
     using (StringWriter sw = new StringWriter(sb))
         g.Serialize(sw, value);
     return sb.ToString();
 }
 /// <summary>
 /// Writes the specified feature collection.
 /// </summary>
 /// <param name="featureCollection">The feature collection.</param>
 /// <returns></returns>
 public string Write(FeatureCollection featureCollection)
 {
     JsonSerializer g = new GeoJsonSerializer();
     StringBuilder sb = new StringBuilder();
     using (StringWriter sw = new StringWriter(sb))
         g.Serialize(sw, featureCollection);
     return sb.ToString();
 }
        /// <summary>
        /// Writes any specified object.
        /// </summary>
        /// <param name="value">Any object.</param>
        /// <returns></returns>
        public string Write(object value)
        {
            JsonSerializer g  = new GeoJsonSerializer();
            StringBuilder  sb = new StringBuilder();

            using (StringWriter sw = new StringWriter(sb))
                g.Serialize(sw, value);
            return(sb.ToString());
        }
        /// <summary>
        /// Writes the specified feature collection.
        /// </summary>
        /// <param name="featureCollection">The feature collection.</param>
        /// <returns></returns>
        public string Write(FeatureCollection featureCollection)
        {
            JsonSerializer g  = new GeoJsonSerializer();
            StringBuilder  sb = new StringBuilder();

            using (StringWriter sw = new StringWriter(sb))
                g.Serialize(sw, featureCollection);
            return(sb.ToString());
        }
        /// <summary>
        /// Writes the specified feature.
        /// </summary>
        /// <param name="feature">The feature.</param>
        /// <returns></returns>
        public string Write(IFeature feature)
        {
            GeoJsonSerializer g  = new GeoJsonSerializer();
            StringBuilder     sb = new StringBuilder();

            using (StringWriter sw = new StringWriter(sb))
                g.Serialize(sw, feature);
            return(sb.ToString());
        }
        /// <summary>
        /// Writes the specified geometry.
        /// </summary>
        /// <param name="geometry">The geometry.</param>
        /// <returns></returns>
        public string Write(IGeometry geometry)
        {
            if (geometry == null) 
                throw new ArgumentNullException("geometry");

            JsonSerializer g = new GeoJsonSerializer(geometry.Factory);
            StringBuilder sb = new StringBuilder();
            using (StringWriter sw = new StringWriter(sb))
                g.Serialize(sw, geometry);
            return sb.ToString();
        }
 public static byte[] ToBytes(this FeatureCollection featureCollection)
 {
     using (var outputStream = new MemoryStream())
     {
         var writer = new StreamWriter(outputStream);
         var jsonWriter = new JsonTextWriter(writer);
         var serializer = new GeoJsonSerializer();
         serializer.Serialize(jsonWriter, featureCollection);
         jsonWriter.Flush();
         return outputStream.ToArray();
     }
 }
        /// <summary>
        /// Writes the specified geometry.
        /// </summary>
        /// <param name="geometry">The geometry.</param>
        /// <returns></returns>
        public string Write(IGeometry geometry)
        {
            if (geometry == null)
            {
                throw new ArgumentNullException("geometry");
            }

            JsonSerializer g  = new GeoJsonSerializer(geometry.Factory);
            StringBuilder  sb = new StringBuilder();

            using (StringWriter sw = new StringWriter(sb))
                g.Serialize(sw, geometry);
            return(sb.ToString());
        }