Operand type clash geography is incompatible with float

JHG

I am trying to figure out how to build a function that measures the distance from one location to another in miles, using longitude and latitude. The parameters would be added when EXECUTE is run. I am trying to do this using the "geography::Point()" and the "STDistance" instead of float.

IF OBJECT_ID('dbo.udfDistanceMiles') IS NOT NULL
  DROP FUNCTION dbo.udfDistanceMiles
GO
CREATE FUNCTION dbo.udfDistanceMiles 
(
    @long1 geography,
    @long2 geography,
    @lat1 geography,
    @lat2 geography
)
RETURNS geography
AS
BEGIN
    DECLARE @from geography
    DECLARE @to geography
    DECLARE @kilo geography
    DECLARE @miles as geography

    SET @from = geography::Point(@lat1,@long1,4268);
    SET @to = geography::Point(@lat2,@long2,4268);
    SET @kilo = (SELECT @from.STDistance(@to));
        BEGIN
            SET @miles = (@kilo * '.621371');
        END 

    RETURN @miles

END
GO

This is an assignment for a class I am taking on spatial databases, but I've run into a snag that I cannot figure out. I am running into this Operand type clash when trying to just create the function:

Msg 206, Level 16, State 2, Procedure udfDistanceMiles, Line 19
Operand type clash: geography is incompatible with float
Msg 206, Level 16, State 2, Procedure udfDistanceMiles, Line 19
Operand type clash: geography is incompatible with float
Msg 206, Level 16, State 2, Procedure udfDistanceMiles, Line 20
Operand type clash: geography is incompatible with float
Msg 206, Level 16, State 2, Procedure udfDistanceMiles, Line 20
Operand type clash: geography is incompatible with float
Msg 206, Level 16, State 2, Procedure udfDistanceMiles, Line 21
Operand type clash: float is incompatible with geography
Msg 403, Level 16, State 1, Procedure udfDistanceMiles, Line 23
Invalid operator for data type. Operator equals multiply, type equals geography.

Any help for a newb would be appreciated.

Thanks

John

JHG

Here is the finished Function that worked for me, along with its EXEC to measure miles from SLC, UT to LA, CA.

ALTER FUNCTION [dbo].[udfDistanceMiles] 
(
    @long1 float,
    @long2 float,
    @lat1 float,
    @lat2 float
)
RETURNS float
AS
BEGIN
    DECLARE @from geography
    DECLARE @to geography
    DECLARE @miles as float

    SET @from = geography::Point(@lat1,@long1,4326);
    SET @to = geography::Point(@lat2,@long2,4326);
    SET @miles = (SELECT ((@from.STDistance(@to) * '.001') * '.621371'));
    --SET @miles = (SELECT (@from.STDistance(@to) * '.621371'));

    RETURN @miles

END

And the EXEC:

USE DBM384;
GO

DECLARE @miles float= NULL;

EXEC @miles = dbo.udfDistanceMiles @lat1= 34, @long1= -118, @lat2= 40.758701, @long2= -111.876183;

PRINT @miles;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

TypeError: bad operand type for unary ~: float

From Dev

Operand type clash: text is incompatible with uniqueidentifier

From Dev

Table type parameter in a stored procedure cause operand type clash error

From Dev

TypeError: unsupported operand type(s) for +: 'float' and 'tuple'

From Dev

Sql Server Operand type clash: date is incompatible with int

From Dev

TypeError: unsupported operand type(s) for +: 'decimal' and 'float'

From Dev

Getting error:Operand type clash: nvarchar is incompatible with image

From Dev

Sending float to parameter of incompatible type id

From Dev

Operand type clash: nvarchar is incompatible with Type_WP_Days

From Dev

Unsupported operand type(s) for +: 'float' and 'str' error

From Dev

TypeError: bad operand type for unary ~: float

From Dev

Operand type clash: text is incompatible with uniqueidentifier

From Dev

Operand type clash: bigint is incompatible with time

From Dev

Sql Server Operand type clash: date is incompatible with int

From Dev

TypeError: unsupported operand type(s) for -: 'float' and 'method'

From Dev

Python: unsupported operand type(s) for /: 'tuple' and 'float'

From Dev

TypeError: unsupported operand type(s) for /: 'float' and 'instancemethod'

From Dev

Operand Data Type Clash when executing sp_help_job via VB.Net

From Dev

TypeError: unsupported operand type(s) for -: 'instance' and 'float'

From Dev

Operand type clash: nvarchar is incompatible with Type_WP_Days

From Dev

c# Operand type clash: date is incompatible with int

From Dev

Stored Procedure Operand type clash: date is incompatible with int

From Dev

Operand type clash: date is incompatible with int in dateadd

From Dev

CUDA: argument of type float * is incompatible with parameter of type float (*)[32768]

From Dev

TypeError: unsupported operand type(s) for <<: 'int' and 'float'

From Dev

NHibernate component mapping: Operand type clash: bigint is incompatible with time

From Dev

TypeError: unsupported operand type(s) for +: 'Timestamp' and 'float'

From Dev

Tsql Operand type clash: date is incompatible with int

From Dev

TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

Related Related

  1. 1

    TypeError: bad operand type for unary ~: float

  2. 2

    Operand type clash: text is incompatible with uniqueidentifier

  3. 3

    Table type parameter in a stored procedure cause operand type clash error

  4. 4

    TypeError: unsupported operand type(s) for +: 'float' and 'tuple'

  5. 5

    Sql Server Operand type clash: date is incompatible with int

  6. 6

    TypeError: unsupported operand type(s) for +: 'decimal' and 'float'

  7. 7

    Getting error:Operand type clash: nvarchar is incompatible with image

  8. 8

    Sending float to parameter of incompatible type id

  9. 9

    Operand type clash: nvarchar is incompatible with Type_WP_Days

  10. 10

    Unsupported operand type(s) for +: 'float' and 'str' error

  11. 11

    TypeError: bad operand type for unary ~: float

  12. 12

    Operand type clash: text is incompatible with uniqueidentifier

  13. 13

    Operand type clash: bigint is incompatible with time

  14. 14

    Sql Server Operand type clash: date is incompatible with int

  15. 15

    TypeError: unsupported operand type(s) for -: 'float' and 'method'

  16. 16

    Python: unsupported operand type(s) for /: 'tuple' and 'float'

  17. 17

    TypeError: unsupported operand type(s) for /: 'float' and 'instancemethod'

  18. 18

    Operand Data Type Clash when executing sp_help_job via VB.Net

  19. 19

    TypeError: unsupported operand type(s) for -: 'instance' and 'float'

  20. 20

    Operand type clash: nvarchar is incompatible with Type_WP_Days

  21. 21

    c# Operand type clash: date is incompatible with int

  22. 22

    Stored Procedure Operand type clash: date is incompatible with int

  23. 23

    Operand type clash: date is incompatible with int in dateadd

  24. 24

    CUDA: argument of type float * is incompatible with parameter of type float (*)[32768]

  25. 25

    TypeError: unsupported operand type(s) for <<: 'int' and 'float'

  26. 26

    NHibernate component mapping: Operand type clash: bigint is incompatible with time

  27. 27

    TypeError: unsupported operand type(s) for +: 'Timestamp' and 'float'

  28. 28

    Tsql Operand type clash: date is incompatible with int

  29. 29

    TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

HotTag

Archive