Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5961525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:58:36+00:00 2026-05-22T18:58:36+00:00

Currently i have a table looking something like this _ID DeviceID Timestamp Latitude Longitude

  • 0

Currently i have a table looking something like this

_ID    DeviceID   Timestamp          Latitude Longitude
4      13         1.1.2011 10:00:13  30.234   24.953
5      13         1.1.2011 10:00:17  30.235   24.953
6      13         1.1.2011 10:00:20  30.235   24.954
7      14         1.1.2011 10:00:21  54.532   13.256
8      13         1.1.2011 10:00:22  30.235   24.955
9      13         1.1.2011 10:00:24  30.234   24.954
  • _ID
    • Primary Key
    • int
  • DeviceID
    • int
    • not null
  • Timestamp
    • datetime
    • not null
  • Latitude
    • real
    • not null
  • Longitude
    • real
    • not null

After a little searching (also here on SO) i’ll find a lot of solutions about calculating the distance between two points. But i’d like to calculate the distance out of a list of points.

So i search a little more and i found the STLength method which seems to should do what i want. The problem is that i need to construct a geometry out of the list of points i have and that the help page about constructing geometry instances doesn’t tell me how to do exactly this. (At least it doesn’t tell it in a way that i could understand it.)

Can anyone tell me how to create a geometry out of a list of lat/lng?

Update

Ok, there is one thing i missed in my question till now:

I have a lot of points for one distance to calculate (normally somewhere between 1,000 and 20,000 but one or two times up to 40,000 points).

Also maybe i’m simply taking the complete false approach to get the distance out of it. So let me know if you have any other idea to get the distance out of the data.

Also don’t care about ordering, adding or deletion of points. When the query runs the data is stable in these terms.

To answers Chris comment:
Yes, the connection is from 4 – 5 – 6 – 8 – 9 (determined by the timestamp). Within the table are the values of different devices (like 7) but those can easily be sort out with a where clause. The distance i’d like to get is the length of the line you would get if you connect the points from the above list.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:58:37+00:00Added an answer on May 22, 2026 at 6:58 pm

    Here’s a script that creates a basic table with the data you outlined, makes it into a valid LINESTRING string, then calculates the length on it:

    declare @yourTable table (latitude decimal(10,7), longitude decimal(10,7))
    insert into @yourTable select 30.234, 24.953
    insert into @yourTable select 30.235, 24.953
    insert into @yourTable select 30.235, 24.954
    insert into @yourTable select 54.532, 13.256
    insert into @yourTable select 30.235, 24.955
    insert into @yourTable select 30.234, 24.954
    
    DECLARE @LINE VARCHAR(MAX) = 'LINESTRING (';    
    SELECT @LINE = @LINE+ convert(varchar(20),latitude) + ' ' + convert(varchar(20),longitude) + ','
    FROM @yourTable
    
    select @LINE = LEFT(@LINE,LEN(@LINE)-1)+')'
    
    DECLARE @g geography;
    SET @g = geography::STGeomFromText(@LINE, 4326);
    SELECT @g.STLength();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a table structure that looks something like this(some details omitted): ColumnName
I have a table with a composite Primary Key, arranged something like this: CREATE
I currently have the following row in my table: course_data: user_id days <-- This
I have a table which looks something like Event ID Date Instructor 1 1/1/2000
if i have a table like this tbl_attributes --------------- id_attrib (auto incremented, primary key)
I currently have a Table [org.eclipse.swt.widgets.Table] with several TableColumns; however, due to UI space
I currently have a table with a nested table in it: <table class=datagrid id=report>
I currently have a table which only has a single editable column. I have
Say I have a table with a unique positive integer field. I currently have
I'm trying to normalize a mysql database.... I currently have a table that contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.