Geodesic Lines to GIS
Computes geodesic lines from start point to end point and stores them in a GIS file (Shapefile and GeoJSON). A geodesic is the shortest path between two points on a curved surface, like an ellipsoid of revolution (Read more on Wikipedia).
This code is builded on top of three libraries: Pyproj, Fiona and Shapely.
There are several libraries to compute geodesic distances solving the geodesic inverse problem (to find the shortest path between two given points). I chose Pyproj because it works fine for this purpose and is an interface to a widely used library in the geospatial industry (Proj4 C library). Actually Proj4 C library (>= v.4.9.0) routines used to compute geodesic distance are a simple transcription from excellent Geographiclib C++ Library developed by Charles Karney. Proj4 C library < v.4.9.0 uses Paul D. Thomas algorithms. You can see more about this here: GeodeticMusings: a little benchmark of three Python libraries to compute geodesic distances.
All computations are performed with WGS84 ellipsoid and the CRS (Coordinate Reference System) of GIS file outputs are EPSG:4326.
In the examples section you can see the problem of calculating lines crossing antimeridian is solved.
Numpy array is supported as inputa data.
Geodesic lines examples
Below are shown different geodesic lines computed with this library on several map projections. Also you can see the relation with rhumb lines (loxodromic) and straight lines between the same points:
Requirements
Pyproj, https://github.com/jswhit/pyproj
Shapely, https://github.com/Toblerity/Shapely
Usage
Usage is very simple. There are two modes: - Single input (one start/end). - Multiple input (more than one start/end).
Single input
Single input usage.
from geodesiclinestogis import GeodesicLine2Gisfile
lons_lats: input coordinates. (start longitude, start latitude, end longitude, end latitude)
lons_lats = (-3.6,40.5,-118.4,33.9)
Folder path to store output file and filename:
folderpath = '/tmp'
layername = "geodesicline"
Create object. You can pass two parameters: - antimeridian: [True, False] to solve antimeridian problem (default is True). - prints: [True, False] print output messages (default is True).
gtg = GeodesicLine2Gisfile()
Launch computations. You can pass two parameter: - lons_lats: input coords returned by gcComp. - km_pts: compute one point each n km (default is 20 km)
cd = gtg.gdlComp(lons_lats, km_pts=30)
Dump geodetic line coords to Linestring Feature and store in a GIS file.
Output formats: “ESRI Shapefile” (default), “GeoJSON”
# shapefile output
gtg.gdlToGisFile(cd, folderpath, layername)
# geojson output
gtg.gdlToGisFile(cd, folderpath, layername, fmt="GeoJSON")
Multiple input
Multiple input usage.
from geodesiclinestogis import GeodesicLine2Gisfile
data = [
(-6.,37.,-145.,11.),
(-150.,37.,140.,11.),
(-6.,37.,120.,50.),
(-3.6,40.5,-118.4,33.9),
(-118.4,33.9,139.8,35.5),
(-118.4,33.9,104.,1.35),
(-118.4,33.9,151.,-33.9),
(-20.4,33.9,178.,-33.9)
]
folderpath = "/tmp/geod_line"
layername = "geodesicline"
gtg = GeodesicLine2Gisfile()
gtg.gdlToGisFileMulti(data, folderpath, layername)
Numpy array (multiple) input
Numpy array input usage.
import numpy as np
from geodesiclinestogis import GeodesicLine2Gisfile
data_ = [
(-6.,37.,-145.,11.),
(-150.,37.,140.,11.),
(-6.,37.,120.,50.),
(-3.6,40.5,-118.4,33.9),
(-118.4,33.9,139.8,35.5),
(-118.4,33.9,104.,1.35),
(-118.4,33.9,151.,-33.9),
(-20.4,33.9,178.,-33.9)
]
data = np.array(data_)
folderpath = "/tmp/geod_line_np"
layername = "geodesicline"
gtg = GeodesicLine2Gisfile()
gtg.gdlToGisFileMulti(data, folderpath, layername)
License
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
Third-Party licenses
You can read Pyproj, Fiona and Shapely licenses in the next links: https://raw.githubusercontent.com/jswhit/pyproj/master/LICENSE https://raw.githubusercontent.com/Toblerity/Shapely/master/LICENSE.txt https://raw.githubusercontent.com/Toblerity/Fiona/master/LICENSE.txt
Metadata
Release files for GeodesicLinesToGIS 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| GeodesicLinesToGIS-0.5.0.tar.gz | 7.4 kB | Without provenance | Details |
Release files / GeodesicLinesToGIS-0.5.0.tar.gz
| Download URL | GeodesicLinesToGIS-0.5.0.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d5af55b7610f80590a698009516f008294c5dafcbeca5c9dfc01d2343a073db5
|
|
BLAKE2b-256 checksum How to use checksums |
d5765953b9d899e8ebb100b1ee1e9db79063417be695e55c5edfdfaee6225751
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for GeodesicLinesToGIS 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.