GithubHelp home page GithubHelp logo

cafawo / nautipy Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 0.0 46 KB

NautiPy is an open-source Python library for nautical navigation applications.

License: MIT License

Python 100.00%
navigation python gps location geolocation distance multilateration triangulation coordinates

nautipy's Introduction

nauitpy

NautiPy

NautiPy is an open-source Python library for nautical navigation applications.

ISO 6709 Coordinates

The library uses a float representation of GPS coordinates, based on the ISO 6709 standard (without left padding zeros), i.e.

  • Latitude: ±DD.D (e.g. +50.12257)
  • Longitude: ±DDD.D (e.g. +8.66370)

Coordinate Conversion

The convert_coordinates function allows for conversion between various GPS input formats to ISO 6709 decimal degrees. Supported input formats include:

  • Degrees, Minutes, Seconds (DMS): e.g. "N 50° 7' 20.9122", "W 8° 39' 56.52"
  • Degrees and Decimal Minutes (DMM): e.g. "50° 7.34854N", "8° 39.942W"
  • Decimal Degrees (DD): e.g. "+50.12257", "-8.66570"

Example usage:

# Convert different formats to ISO 6709 (decimal degrees)
print(convert_coordinates("+50.12257", "-8.66570", "DD"))
print(convert_coordinates("N 50° 7' 20.9122", "W 8° 39' 56.52", "DMS"))
print(convert_coordinates("50° 7.34854N", "8° 39.942W", "DMM"))

Functionalities

Basics

# Store and descibe your position
work = Pos(50.127198, 8.665562, desc='Campus building')
print(f'Work is here: {work.coordinates()}')

# Get relative position, e.g. heading 90 degrees 12 kilometers away
work_displaced = work.displace(90, 12)

# Get bearing to or from position
bearing(work, work_displaced)

# Get distance to position
haversine(work, work_displaced)

# Consider the following known stations
stations = [Pos(50.116135, 8.670277, 'Opernturm'),
            Pos(50.112836, 8.666753, 'Deka tower'),
            Pos(50.110347, 8.659873, 'Volksbank tower')
            ]

# Get the nearest stations within a radius around your position
nearest = nearest_stations(work, stations, radius=1.7)
print(f'{[(p.desc, d) for p, d in nearest]}')

Triangulation and Multilateration

To fix a position both methods rely on knowledge about the position and bearing to 2 (triangulation) or position and distance to 3 (multilateration) stations.

In trigonometry and geometry, triangulation is the process of determining the location of a point by forming triangles to it from known points. (Wikipedia)

# Get your position from bearings to two stations
triangulate(stations[0], 164.71, stations[2], 192.22).coordinates()

True range multilateration is a method to determine the location of a movable vehicle or stationary point in space using multiple ranges (stations) between the vehicle/point and multiple spatially-separated known locations. (Wikipedia)

# Get your position from distances to at least 3 stations (you can use more)
#               position,      distance
multilaterate([(stations[0],  1.275251),  
               (stations[1],  1.599237),  
               (stations[2],  1.917145)]).coordinates()

Compare both positions to work, i.e. (50.127198, 8.665562).

Importing and exporting

NautiPy includes export_positions and import_positions functions to convert position data into GeoJSON format for easy use in GIS software and mapping services. It can save the output to a file or return the GeoJSON string.

Example Usage

# Export and save to a file
export_positions(stations, save_as="positions.geojson")

# Load positions from a GeoJSON file
stations_reloaded = import_positions('positions.geojson')

nautipy's People

Contributors

cafawo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nautipy's Issues

Implement export Function for Position Data in Various Formats

Is your feature request related to a problem? Please describe.
I'm always frustrated when I need to manually convert and save position data from our navigation software into different data formats for sharing and visualization. Currently, our application does not support exporting position data in common geographic data formats like GeoJSON, which limits the ease of integration with other geospatial tools and platforms.

Describe the solution you'd like
I would like an export function implemented in our codebase that can automatically convert a list of Pos objects to different formats, starting with GeoJSON. This function should also support saving the output directly to a file. The function should handle multiple position entries and include relevant metadata (like descriptions and unique position IDs) in the output.

Describe alternatives you've considered
An alternative could be to use external tools or libraries to perform the conversion outside our application. However, this requires additional steps for the users and might not seamlessly integrate with our internal data structures.

Additional context
Integrating this function would streamline workflows for users who need to export positional data for use in GIS software, web mapping services, or for data sharing with other platforms that accept GeoJSON or similar formats. This could significantly enhance the usability of our software in geospatial analysis and collaborative environments.

Encrypted proximity matching

Is your feature request related to a problem? Please describe.
Anonymous position matching. Its easy to implement but I'm not sure if it is useful, so I leave it here for future reference.

Basic idea, two entities submit their encrypted position. The receiver can match entities by proximity but will never know their position.

Describe the solution you'd like

  1. Choose matching area/precision, e.g. by rounding coordinates (see table below)
  2. Use hash algorithm to encrypt position.
  3. Match entities by hash
decimal
places   degrees          distance N/S or E/W at equator
-------  -------          --------
0        1                111  km
1        0.1              11.1 km
2        0.01             1.11 km
3        0.001            111  m
4        0.0001           11.1 m
5        0.00001          1.11 m
6        0.000001         11.1 cm
7        0.0000001        1.11 cm
8        0.00000001       1.11 mm

Describe alternatives you've considered
Some useful discussion on accuracy and precision: https://gis.stackexchange.com/questions/8650/measuring-accuracy-of-latitude-and-longitude

Additional context
Possible use cases:

  • Collision avoidance without revealing positions
  • Social distancing applications (however GPS is probably not precise enough)

Conversion function for coordinates

There exists a number of formats for geo coordinates, including:

image

It would be useful to have a function that recognizes alternative formats and returns the ISO 6709 standard for GPS coordinates, i.e.:

  • Latitude: ±DD.D (e.g. +50.12257)
  • Longitude: ±DDD.D (e.g. +8.66370)

This function could also include the possibility to convert from ISO 6709 to the desired output string format.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.