Skip to main content

Computes geodesic lines from start point to end point and stores them in a GIS file (Shapefile and GeoJSON). The problem of geodesic lines crossing antimeridian is solved.

Project description

https://travis-ci.org/GeographicaGS/GeodesicLinesToGIS.svg?branch=master

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:

https://github.com/GeographicaGS/GeodesicLinesToGIS

Requirements

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)

About author

Developed by Cayetano Benavent. GIS Analyst at Geographica.

http://www.geographica.gs

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

GeodesicLinesToGIS-0.5.0.tar.gz (7.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page