public static System.Data.Entity.Spatial.DbGeometry Reverse(
            this System.Data.Entity.Spatial.DbGeometry linestring)
        {
            var fromWkb = SqlGeometry.STGeomFromWKB(new SqlBytes(linestring.AsBinary()), 0);

            // Create a new Geometry Builder
            var gb = new SqlGeometryBuilder();
            // Set the Spatial Reference ID equal to the supplied linestring
            gb.SetSrid((int) (fromWkb.STSrid));
            // Start the linestring
            gb.BeginGeometry(OpenGisGeometryType.LineString);
            // Add the first point using BeginFigure()
            gb.BeginFigure((double) fromWkb.STEndPoint().STX, (double) fromWkb.STEndPoint().STY);
            // Loop through remaining points in reverse order
            for (var x = (int) fromWkb.STNumPoints() - 1; x > 0; --x)
            {
                gb.AddLine((double) fromWkb.STPointN(x).STX, (double) fromWkb.STPointN(x).STY);
            }
            // End the figure
            gb.EndFigure();
            // End the geometry
            gb.EndGeometry();
            // Return that as a SqlGeometry instance
            return System.Data.Entity.Spatial.DbGeometry.FromBinary(gb.ConstructedGeometry.STAsBinary().Buffer);
        }
示例#2
0
 public static IGeometry Copy(this IGeometry original)
 {
     return Geometry.GeomFromWKB(original.AsBinary());
 }
 public static SqlGeometry ToSqlGeometry(this System.Data.Entity.Spatial.DbGeometry dbGeometry)
 {
     return SqlGeometry.STGeomFromWKB(new SqlBytes(dbGeometry.AsBinary()), 0);
 }
示例#4
0
        // The As*** functions never return null -- if the supplied type does not have the appropriate shape, an encoding of a bad type is returned.
        #region AsPrimitive, AsCollection, AsStructured, ...
        /// <summary>
        /// If this reference is of a primitive type, this will return a valid primitive type reference to the type definition. Otherwise, it will return a bad primitive type reference.
        /// </summary>
        /// <param name="type">Reference to the calling object.</param>
        /// <returns>A valid primitive type reference if the definition of the reference is of a primitive type. Otherwise a bad primitive type reference.</returns>
        public static IEdmPrimitiveTypeReference AsPrimitive(this IEdmTypeReference type)
        {
            EdmUtil.CheckArgumentNull(type, "type");
            IEdmPrimitiveTypeReference reference = type as IEdmPrimitiveTypeReference;
            if (reference != null)
            {
                return reference;
            }

            IEdmType typeDefinition = type.Definition;
            if (typeDefinition.TypeKind == EdmTypeKind.Primitive)
            {
                var primitiveDefinition = typeDefinition as IEdmPrimitiveType;
                if (primitiveDefinition != null)
                {
                    switch (primitiveDefinition.PrimitiveKind)
                    {
                        case EdmPrimitiveTypeKind.Boolean:
                        case EdmPrimitiveTypeKind.Byte:
                        case EdmPrimitiveTypeKind.Date:
                        case EdmPrimitiveTypeKind.Double:
                        case EdmPrimitiveTypeKind.Guid:
                        case EdmPrimitiveTypeKind.Int16:
                        case EdmPrimitiveTypeKind.Int32:
                        case EdmPrimitiveTypeKind.Int64:
                        case EdmPrimitiveTypeKind.SByte:
                        case EdmPrimitiveTypeKind.Single:
                        case EdmPrimitiveTypeKind.Stream:
                            return new EdmPrimitiveTypeReference(primitiveDefinition, type.IsNullable);
                        case EdmPrimitiveTypeKind.Binary:
                            return type.AsBinary();
                        case EdmPrimitiveTypeKind.Decimal:
                            return type.AsDecimal();
                        case EdmPrimitiveTypeKind.String:
                            return type.AsString();
                        case EdmPrimitiveTypeKind.Duration:
                        case EdmPrimitiveTypeKind.DateTimeOffset:
                        case EdmPrimitiveTypeKind.TimeOfDay:
                            return type.AsTemporal();
                        case EdmPrimitiveTypeKind.Geography:
                        case EdmPrimitiveTypeKind.GeographyPoint:
                        case EdmPrimitiveTypeKind.GeographyLineString:
                        case EdmPrimitiveTypeKind.GeographyPolygon:
                        case EdmPrimitiveTypeKind.GeographyCollection:
                        case EdmPrimitiveTypeKind.GeographyMultiPolygon:
                        case EdmPrimitiveTypeKind.GeographyMultiLineString:
                        case EdmPrimitiveTypeKind.GeographyMultiPoint:
                        case EdmPrimitiveTypeKind.Geometry:
                        case EdmPrimitiveTypeKind.GeometryPoint:
                        case EdmPrimitiveTypeKind.GeometryLineString:
                        case EdmPrimitiveTypeKind.GeometryPolygon:
                        case EdmPrimitiveTypeKind.GeometryCollection:
                        case EdmPrimitiveTypeKind.GeometryMultiPolygon:
                        case EdmPrimitiveTypeKind.GeometryMultiLineString:
                        case EdmPrimitiveTypeKind.GeometryMultiPoint:
                            return type.AsSpatial();
                        case EdmPrimitiveTypeKind.None:
                            break;
                    }
                }
            }
            else if (typeDefinition.TypeKind == EdmTypeKind.TypeDefinition)
            {
                return new EdmPrimitiveTypeReference(typeDefinition.UnderlyingType(), type.IsNullable);
            }

            string typeFullName = type.FullName();
            List<EdmError> errors = new List<EdmError>(type.Errors());
            if (errors.Count == 0)
            {
                errors.AddRange(ConversionError(type.Location(), typeFullName, EdmConstants.Type_Primitive));
            }

            return new BadPrimitiveTypeReference(typeFullName, type.IsNullable, errors);
        }
示例#5
0
 /// <summary>
 /// Function to encode <paramref name="self"/> to an array of <see cref="byte"/>s. If assigned, <paramref name="writer"/> is used.
 /// </summary>
 /// <param name="self">The geometry to encode</param>
 /// <param name="writer">The writer to use</param>
 /// <returns>An array of <see cref="byte"/>s, that represent <paramref name="self"/></returns>
 public static byte[] AsBinary(this IGeometry self, GeoAPI.IO.IBinaryGeometryWriter writer)
 {
     return writer == null
         ? self.AsBinary()
         : writer.Write(self);
 }
示例#6
0
		public static IEdmPrimitiveTypeReference AsPrimitive(this IEdmTypeReference type)
		{
			string str;
			List<EdmError> edmErrors;
			EdmUtil.CheckArgumentNull<IEdmTypeReference>(type, "type");
			IEdmPrimitiveTypeReference edmPrimitiveTypeReference = type as IEdmPrimitiveTypeReference;
			if (edmPrimitiveTypeReference == null)
			{
				IEdmType definition = type.Definition;
				if (definition.TypeKind == EdmTypeKind.Primitive)
				{
					IEdmPrimitiveType edmPrimitiveType = definition as IEdmPrimitiveType;
					if (edmPrimitiveType != null)
					{
						EdmPrimitiveTypeKind primitiveKind = edmPrimitiveType.PrimitiveKind;
						if (primitiveKind == EdmPrimitiveTypeKind.None)
						{
							str = type.FullName();
							edmErrors = new List<EdmError>(type.Errors());
							if (edmErrors.Count == 0)
							{
								edmErrors.AddRange(EdmTypeSemantics.ConversionError(type.Location(), str, "Primitive"));
							}
							return new BadPrimitiveTypeReference(str, type.IsNullable, edmErrors);
						}
						else if (primitiveKind == EdmPrimitiveTypeKind.Binary)
						{
							return type.AsBinary();
						}
						else if (primitiveKind == EdmPrimitiveTypeKind.Boolean || primitiveKind == EdmPrimitiveTypeKind.Byte || primitiveKind == EdmPrimitiveTypeKind.Double || primitiveKind == EdmPrimitiveTypeKind.Guid || primitiveKind == EdmPrimitiveTypeKind.Int16 || primitiveKind == EdmPrimitiveTypeKind.Int32 || primitiveKind == EdmPrimitiveTypeKind.Int64 || primitiveKind == EdmPrimitiveTypeKind.SByte || primitiveKind == EdmPrimitiveTypeKind.Single || primitiveKind == EdmPrimitiveTypeKind.Stream)
						{
							return new EdmPrimitiveTypeReference(edmPrimitiveType, type.IsNullable);
						}
						else if (primitiveKind == EdmPrimitiveTypeKind.DateTime || primitiveKind == EdmPrimitiveTypeKind.DateTimeOffset || primitiveKind == EdmPrimitiveTypeKind.Time)
						{
							return type.AsTemporal();
						}
						else if (primitiveKind == EdmPrimitiveTypeKind.Decimal)
						{
							return type.AsDecimal();
						}
						else if (primitiveKind == EdmPrimitiveTypeKind.String)
						{
							return type.AsString();
						}
						else if (primitiveKind == EdmPrimitiveTypeKind.Geography || primitiveKind == EdmPrimitiveTypeKind.GeographyPoint || primitiveKind == EdmPrimitiveTypeKind.GeographyLineString || primitiveKind == EdmPrimitiveTypeKind.GeographyPolygon || primitiveKind == EdmPrimitiveTypeKind.GeographyCollection || primitiveKind == EdmPrimitiveTypeKind.GeographyMultiPolygon || primitiveKind == EdmPrimitiveTypeKind.GeographyMultiLineString || primitiveKind == EdmPrimitiveTypeKind.GeographyMultiPoint || primitiveKind == EdmPrimitiveTypeKind.Geometry || primitiveKind == EdmPrimitiveTypeKind.GeometryPoint || primitiveKind == EdmPrimitiveTypeKind.GeometryLineString || primitiveKind == EdmPrimitiveTypeKind.GeometryPolygon || primitiveKind == EdmPrimitiveTypeKind.GeometryCollection || primitiveKind == EdmPrimitiveTypeKind.GeometryMultiPolygon || primitiveKind == EdmPrimitiveTypeKind.GeometryMultiLineString || primitiveKind == EdmPrimitiveTypeKind.GeometryMultiPoint)
						{
							return type.AsSpatial();
						}
					}
				}
				str = type.FullName();
				edmErrors = new List<EdmError>(type.Errors());
				if (edmErrors.Count == 0)
				{
					edmErrors.AddRange(EdmTypeSemantics.ConversionError(type.Location(), str, "Primitive"));
				}
				return new BadPrimitiveTypeReference(str, type.IsNullable, edmErrors);
			}
			else
			{
				return edmPrimitiveTypeReference;
			}
		}
        private static IEdmPrimitiveTypeReference Nullable(this IEdmPrimitiveTypeReference typeReference, bool isNullable)
        {
            if (typeReference.IsBinary())
            {
                var binary = typeReference.AsBinary();
                return new EdmBinaryTypeReference(typeReference.PrimitiveDefinition(), isNullable, binary.IsUnbounded, binary.MaxLength);
            }
            else if (typeReference.IsDecimal())
            {
                var decimalRef = typeReference.AsDecimal();
                return new EdmDecimalTypeReference(typeReference.PrimitiveDefinition(), isNullable, decimalRef.Precision, decimalRef.Scale);
            }
            else if (typeReference.IsTemporal())
            {
                var temporal = typeReference.AsTemporal();
                return new EdmTemporalTypeReference(typeReference.PrimitiveDefinition(), isNullable, temporal.Precision);
            }
            else if (typeReference.IsString())
            {
                var stringRef = typeReference.AsString();
                return new EdmStringTypeReference(typeReference.PrimitiveDefinition(), isNullable, stringRef.IsUnbounded, stringRef.MaxLength, stringRef.IsUnicode);
            }

            return new EdmPrimitiveTypeReference(typeReference.PrimitiveDefinition(), isNullable);
        }