Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2007
    Posts
    97

    Unanswered: Search for coordinates. Also, float ok for index?

    Hello,

    I have two colums over here, latitute and longitue. Both types are float. My idea is to search datasets, that are inside a given polygon. To test if a coordinate is inside a set of coordinates, i wrote a c# function. Shouldn't be a problem to create a udf for that. But that means, I cannot use an index for searching, right? So I came up with the idea to tranform the polygon in a rectangle, so I can search by using "In Between". At the same time I could use the udf. My where clause would look something like this:
    ...
    Where
    y = 2007 and q = 3
    and latitute between 50.2332123 and 51.6677544
    and longitute between 10.2323 and 11.6323452
    and Poly(latitute,longitute, [comma-separated-list-of-coordinates]) = 1

    Therefore I'd like to create an index on (y,q,latitute ,longitute), with lat and lon as float. Is that a crime? Do you think that will work?

    Thanks!

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Consider writing your C# function as a CLR function, not a UDF.
    Use of a UDF does not preclude the use of indexes. It depends upon the logic in your algorithm.
    It is not a crime to create indexes on float columns.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Feb 2007
    Posts
    62
    Quote Originally Posted by blindman
    It is not a crime to create indexes on float columns.
    Quote Originally Posted by silas
    It is not a crime to create indexes on float columns.
    Is it a crime to have comma separated lists in relational databases?

  4. #4
    Join Date
    Mar 2007
    Posts
    97
    Quote Originally Posted by LoztInSpace
    Is it a crime to have comma separated lists in relational databases?
    I don't think (hope) so. It's like an array with a variable lenght. Furthermore, that data is not from the db itself, it's from the client, the server just does the poly-hittest.

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    poly-hittest ?????????

    yes, Lozt, it is a crime against first normal form
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    I imagine this is probably no use to you but just in case - are you aware of the new geometry data types in SQL 2008?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  7. #7
    Join Date
    Mar 2007
    Posts
    97
    Why

    Polys are not fixed, they do vary. It's like reverse geocoding. You draw a poly on a map, and you get all objects inside that poly. I don't see a problem here.

  8. #8
    Join Date
    Mar 2007
    Posts
    97
    Quote Originally Posted by pootle flump
    I imagine this is probably no use to you but just in case - are you aware of the new geometry data types in SQL 2008?
    No, I didn't know. What types are they? Poly????

  9. #9
    Join Date
    Apr 2007
    Posts
    183
    Use decimal datatype instead.
    FLOAT are not 100% accurate and may "round off" your coordinates.

    DECIMAL(10, 7) would be what you want.

  10. #10
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by silas
    No, I didn't know. What types are they? Poly????
    I've not done any geometry stuff since school so I can't be that specific. I went to a "what's hot in 2008" MS preview and the guy showed some stuff with the new data types that was significantly simpler than in 2005 (and less) T-SQL. For example, identifying the coordinates for overlapping polygon areas.

    If this is a fresh new system and will not be "live" for some time it might be worth at least reading up on these new data types. There is quite a lot on the internet about them.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  11. #11
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    testing this message is too short
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •