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 8736707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:21:40+00:00 2026-06-13T10:21:40+00:00

I am currently using Python/Numpy to deal with geographical/GPS data (loving it!), and I

  • 0

I am currently using Python/Numpy to deal with geographical/GPS data (loving it!), and I am facing the recurring task to calculate distances between geographical points defined by a coordinate pair pn = [lon, lat].

I have a function that I use like this: dist = geodistance(p1, p2) which is analog to euclidean distance in linear algebra (vector subtraction/difference), but occurs in geodesical (spherical) space instead of rectangular euclidean space.

Programmatically, euclidean distance is given by

dist = ((p2[0] - p1[0])**2 + (p2[1] - p1[1])**2)**0.5

Mathematically, this is equivalent to the “idiomatic” (for lack of a better word) sentence

dist = p1 - p1   # the "norm" of the vector difference, subtraction.

Currently, I get my distance like this:

p1 = [-51.598354,-29.953363]
p2 = [-51.598701,-29.953045]
dist = geodistance(p1, p2)
print dist

>> 44.3904032407

I would like to do this:

print p2 - p1  # these points now are from some fancy datatype

>> 44.3904032407

And the final goal:

track = numpy.array([[-51.203018 -29.996149]
                     [-51.203018 -29.99625 ]
                     [-51.20266  -29.996229]
                     [-51.20229  -29.996309]
                     [-51.201519 -29.99416 ]], dtype=fancy)  # (**) or something like

print numpy.diff(track)

>> ndarray([[   0.        ]
            [   7.03531252]
            [  39.82663316]
            [  41.50958596]
            [ 172.49825765]])

A similar thing is: if you take two datetime objects and subtract them, the operation returns a timedelta object. I want to subtract two coordinates and get a geodesic distance as the result.

I wonder if a class would work, but dtype (a “subtype” of float32, for example) would help a lot upon array creation from lists (** which is how I read things from xml files).

Thanks a lot!

  • 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-06-13T10:21:41+00:00Added an answer on June 13, 2026 at 10:21 am

    You can define your own types by creating a class and writing a __add__ or __sub__ method.

    For example:

    class P(object):
        def __init__(self, lon, lat):
            self.lon = lon
            self.lat = lat
    
        def __sub__(self, other):
            dist = ((other.lon - self.lon)**2 + (other.lat - self.lat)**2)**0.5
            return dist
    

    Given that you’re currently getting the coordinates of your points using the list indexing syntax, you could also implement those:

    class P(object):
        def __init__(self, lon, lat):
            self.lon = lon
            self.lat = lat
    
        def __sub__(self, other):
            dist = ((other[0] - self[0])**2 + (other[1] - self[1])**2)**0.5
            return dist
    
        def __getitem__(self, key):
            if key == 0:
                return self.lon
            elif key == 1:
                return self.lat
            else:
                raise IndexError
    
        def __setitem__(self, key, value):
            if key == 0:
                self.lon = value
            elif key == 1:
                self.lat = value
            else:
                raise IndexError
    

    (I realize that the above may not be the most elegant way to do it).

    That way, your new class is a drop-in replacement for the lists you’re currently using.

    The Python documentation contains more information about the double-underscore methods you need to write in order to create your user-defined types. (The information you’re looking for starts about half-way down the page)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Audio processing is pretty new for me. And currently using Python Numpy for processing
I am currently using a Python 2.5 sample from the ANTLR website. I'm actually
I am using python 3.2 currently and I wanted to do write a code
I'm currently learning Python using Zelle's Introductory text, and I'm trying to recreate one
I'm currently making a filesystem using python-fuse and was looking up where file pointers
I am currently using SleekXMPP to build a simple XMPP client in Python. I'm
I'm currently using the toprettyxml() function of the xml.dom module in a Python script
I'm currently working on a project 'email to voice call'. Using python i'v extracted
Is there a way to determine programmatically, using Python, which web page is currently
Is there a way to determine programmatically, using Python, which web page is currently

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.