/// <summary>
        /// Converts from GeoAPI geometry type to database geometry type.
        /// </summary>
        /// <param name="value">The GeoAPI geometry value.</param>
        /// <returns></returns>
        protected override byte[] FromGeometry(object value)
        {
            IGeometry geometry = value as IGeometry;

            if (geometry == null)
            {
                return(null);
            }
            // MySQL parses empty geometry as NULL
            if (geometry.IsEmpty)
            {
                return(null);
            }

            this.SetDefaultSRID(geometry);
            byte[] bytes = new MySQLWriter().Write(geometry);
            return(bytes);
        }
Exemple #2
0
        /// <summary>
        /// Converts from GeoAPI geometry type to database geometry type.
        /// </summary>
        /// <param name="value">The GeoAPI geometry value.</param>
        /// <returns></returns>
        protected override MySqlGeometry?FromGeometry(object value)
        {
            IGeometry geometry = value as IGeometry;

            if (geometry == null)
            {
                return(null);
            }
            // MySQL parses empty geometry as NULL
            if (geometry.IsEmpty)
            {
                return(null);    // TODO: Somehow specify an empty geometry and not just null.
                                 // MySqlGeometry does not support empty geometry collections
                                 // so we simply return null for now. At some point we should to
                                 // use GeometryCollection.Empty here, when MySQL supports it.
            }

            SetDefaultSRID(geometry);
            byte[] bytes = new MySQLWriter().Write(geometry);
            return(new MySqlGeometry(MySqlDbType.Geometry, bytes));
        }