none
What's the literal format for spatial types in Entity SQL? RRS feed

Answers

  • Hi Tank-Tank,

    There is no literal format for spatial types but there are a number of factory methods among EF canonical functions that you can use to create them from strings in Well-Known Text format.

    For instance, you can use the following function call in an Entity SQL query to create a geometry point:

    GeometryFromText('POINT (43 -73)')

    I was able to find a page in the documentation that enumerates all spatial functions available but unfortunately it is not written from the EntitySQL perspective so for now you will have to dig a bit to find more information about the expected parameter types:

    http://msdn.microsoft.com/en-us/library/hh749531.aspx

    Hope this helps,
    Diego


    This posting is provided "AS IS" with no warranties, and confers no rights.



    Wednesday, February 27, 2013 6:56 PM
    Moderator

All replies

  • I think the idea is to convert it from a text literal.

    geometry::STGeomFromText

    DECLARE @g geography;
    SET @g = geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326);
    SELECT @g.ToString();

    See an example.

    More Entity SQL specific info here.
    • Edited by Wyck Tuesday, February 26, 2013 3:28 PM Added another link.
    Tuesday, February 26, 2013 3:24 PM
  • Hi, it's T-SQL, not Entity SQL
    Wednesday, February 27, 2013 4:39 PM
  • Hi Tank-Tank,

    There is no literal format for spatial types but there are a number of factory methods among EF canonical functions that you can use to create them from strings in Well-Known Text format.

    For instance, you can use the following function call in an Entity SQL query to create a geometry point:

    GeometryFromText('POINT (43 -73)')

    I was able to find a page in the documentation that enumerates all spatial functions available but unfortunately it is not written from the EntitySQL perspective so for now you will have to dig a bit to find more information about the expected parameter types:

    http://msdn.microsoft.com/en-us/library/hh749531.aspx

    Hope this helps,
    Diego


    This posting is provided "AS IS" with no warranties, and confers no rights.



    Wednesday, February 27, 2013 6:56 PM
    Moderator
  • Thanks, Diego, I got it.

    Here's a routine listing all edm canonical functions:

                using (var ctx = new MyEntities()) {
                    var sb = new StringBuilder();
                    foreach (var func in ctx.MetadataWorkspace.GetItems<EdmFunction>(DataSpace.CSpace).Where(i => i.NamespaceName == "Edm")) {
                        sb.Append(func.ReturnParameter.TypeUsage.EdmType.Name + " " + func.Name + "(");
                        for (var i = 0; i < func.Parameters.Count; i++) {
                            if (i > 0) sb.Append(", ");
                            sb.Append(func.Parameters[i].TypeUsage.EdmType.Name + " " + func.Parameters[i].Name);
                        }
                        sb.AppendLine(");");
                    }
                    File.WriteAllText(@"EdmFunctions.txt", sb.ToString());
              }

    results:

    ...

    Geometry GeometryFromText(String geometryText); Geometry GeometryFromText(String geometryText, Int32 srid); Geometry GeometryPointFromText(String pointText, Int32 srid); Geometry GeometryLineFromText(String lineText, Int32 srid); Geometry GeometryPolygonFromText(String polygonText, Int32 srid); Geometry GeometryMultiPointFromText(String multiPointText, Int32 srid); Geometry GeometryMultiLineFromText(String multiLineText, Int32 srid); Geometry GeometryMultiPolygonFromText(String multiPolygonText, Int32 srid); Geometry GeometryCollectionFromText(String geometryCollectionText, Int32 srid); Geometry GeometryFromBinary(Binary geometryBytes); Geometry GeometryFromBinary(Binary geometryBytes, Int32 srid); Geometry GeometryPointFromBinary(Binary pointBytes, Int32 srid); Geometry GeometryLineFromBinary(Binary lineBytes, Int32 srid); Geometry GeometryPolygonFromBinary(Binary polygonBytes, Int32 srid); Geometry GeometryMultiPointFromBinary(Binary multiPointBytes, Int32 srid); Geometry GeometryMultiLineFromBinary(Binary multiLineBytes, Int32 srid); Geometry GeometryMultiPolygonFromBinary(Binary multiPolygonBytes, Int32 srid); Geometry GeometryCollectionFromBinary(Binary geometryCollectionBytes, Int32 srid); Geometry GeometryFromGml(String geometryGml); Geometry GeometryFromGml(String geometryGml, Int32 srid); Int32 CoordinateSystemId(Geometry geometryValue); String SpatialTypeName(Geometry geometryValue); Int32 SpatialDimension(Geometry geometryValue); Geometry SpatialEnvelope(Geometry geometryValue); Binary AsBinary(Geometry geometryValue); String AsGml(Geometry geometryValue); String AsText(Geometry geometryValue); Boolean IsEmptySpatial(Geometry geometryValue); Boolean IsSimpleGeometry(Geometry geometryValue); Geometry SpatialBoundary(Geometry geometryValue); Boolean IsValidGeometry(Geometry geometryValue); Boolean SpatialEquals(Geometry geometryValue1, Geometry geometryValue2); Boolean SpatialDisjoint(Geometry geometryValue1, Geometry geometryValue2); Boolean SpatialIntersects(Geometry geometryValue1, Geometry geometryValue2); Boolean SpatialTouches(Geometry geometryValue1, Geometry geometryValue2); Boolean SpatialCrosses(Geometry geometryValue1, Geometry geometryValue2); Boolean SpatialWithin(Geometry geometryValue1, Geometry geometryValue2); Boolean SpatialContains(Geometry geometryValue1, Geometry geometryValue2); Boolean SpatialOverlaps(Geometry geometryValue1, Geometry geometryValue2); Boolean SpatialRelate(Geometry geometryValue1, Geometry geometryValue2, String matrix); Geometry SpatialBuffer(Geometry geometryValue, Double distance); Double Distance(Geometry geometryValue1, Geometry geometryValue2); Geometry SpatialConvexHull(Geometry geometryValue); Geometry SpatialIntersection(Geometry geometryValue1, Geometry geometryValue2); Geometry SpatialUnion(Geometry geometryValue1, Geometry geometryValue2); Geometry SpatialDifference(Geometry geometryValue1, Geometry geometryValue2); Geometry SpatialSymmetricDifference(Geometry geometryValue1, Geometry geometryValue2); Int32 SpatialElementCount(Geometry geometryValue); Geometry SpatialElementAt(Geometry geometryValue, Int32 nValue); Double XCoordinate(Geometry geometryValue); Double YCoordinate(Geometry geometryValue); Double Elevation(Geometry geometryValue); Double Measure(Geometry geometryValue); Double SpatialLength(Geometry geometryValue); Geometry StartPoint(Geometry geometryValue); Geometry EndPoint(Geometry geometryValue); Boolean IsClosedSpatial(Geometry geometryValue); Boolean IsRing(Geometry geometryValue); Int32 PointCount(Geometry geometryValue); Geometry PointAt(Geometry geometryValue, Int32 nValue); Double Area(Geometry geometryValue); Geometry Centroid(Geometry geometryValue); Geometry PointOnSurface(Geometry geometryValue); Geometry ExteriorRing(Geometry geometryValue); Int32 InteriorRingCount(Geometry geometryValue); Geometry InteriorRingAt(Geometry geometryValue, Int32 nValue); Geography GeographyFromText(String geographyText); Geography GeographyFromText(String geographyText, Int32 srid); Geography GeographyPointFromText(String pointText, Int32 srid); Geography GeographyLineFromText(String lineText, Int32 srid); Geography GeographyPolygonFromText(String polygonText, Int32 srid); Geography GeographyMultiPointFromText(String multiPointText, Int32 srid); Geography GeographyMultiLineFromText(String multiLineText, Int32 srid); Geography GeographyMultiPolygonFromText(String multiPolygonText, Int32 srid); Geography GeographyCollectionFromText(String geographyCollectionText, Int32 srid); Geography GeographyFromBinary(Binary geographyBytes, Int32 srid); Geography GeographyFromBinary(Binary geographyBytes); Geography GeographyPointFromBinary(Binary pointBytes, Int32 srid); Geography GeographyLineFromBinary(Binary lineBytes, Int32 srid); Geography GeographyPolygonFromBinary(Binary polygonBytes, Int32 srid); Geography GeographyMultiPointFromBinary(Binary multiPointBytes, Int32 srid); Geography GeographyMultiLineFromBinary(Binary multiLineBytes, Int32 srid); Geography GeographyMultiPolygonFromBinary(Binary multiPolygonBytes, Int32 srid); Geography GeographyCollectionFromBinary(Binary geographyCollectionBytes, Int32 srid); Geography GeographyFromGml(String geographyGml); Geography GeographyFromGml(String geographyGml, Int32 srid); Int32 CoordinateSystemId(Geography geographyValue); String SpatialTypeName(Geography geographyValue); Int32 SpatialDimension(Geography geographyValue); Binary AsBinary(Geography geographyValue); String AsGml(Geography geographyValue); String AsText(Geography geographyValue); Boolean IsEmptySpatial(Geography geographyValue); Boolean SpatialEquals(Geography geographyValue1, Geography geographyValue2); Boolean SpatialDisjoint(Geography geographyValue1, Geography geographyValue2); Boolean SpatialIntersects(Geography geographyValue1, Geography geographyValue2); Geography SpatialBuffer(Geography geographyValue, Double distance); Double Distance(Geography geographyValue1, Geography geographyValue2); Geography SpatialIntersection(Geography geographyValue1, Geography geographyValue2); Geography SpatialUnion(Geography geographyValue1, Geography geographyValue2); Geography SpatialDifference(Geography geometryValue1, Geography geometryValue2); Geography SpatialSymmetricDifference(Geography geometryValue1, Geography geometryValue2); Int32 SpatialElementCount(Geography geographyValue); Geography SpatialElementAt(Geography geographyValue, Int32 nValue); Double Latitude(Geography geographyValue); Double Longitude(Geography geographyValue); Double Elevation(Geography geographyValue); Double Measure(Geography geographyValue); Double SpatialLength(Geography geographyValue); Geography StartPoint(Geography geographyValue); Geography EndPoint(Geography geographyValue); Boolean IsClosedSpatial(Geography geographyValue); Int32 PointCount(Geography geographyValue); Geography PointAt(Geography geographyValue, Int32 nValue); Double Area(Geography geographyValue);


    MSDN docs is not up to date.
    • Edited by Tank-Tank Thursday, February 28, 2013 9:27 AM
    Thursday, February 28, 2013 9:26 AM