6 votos

Buscando un módulo de Python para hacer cálculos de lat lon

Estoy buscando un módulo de Python que pueda proporcionar algunos / todos los siguientes servicios utilizando la latitud / longitud para definir los puntos:

Distance between two points
Point in polygon 
Distance along a multi-point path 
Identifier of closest point from a dict of points with identifiers 
Distance from a point to each point in a dict containing points with identifiers
etc

Ya te haces una idea... ¿Alguna sugerencia?

12voto

Peter and the wolf Puntos 121

Puede utilizar el Enlaces GDAL Python . Ejemplos de cómo usarlo puedes encontrar aquí .

Por ejemplo, se crean puntos con lat/lon así

from osgeo import ogr                   # first import the library
point1 = ogr.Geometry(ogr.wkbPoint)
point1.AddPoint(13.381348,52.536273)    # Berlin

point2 = ogr.Geometry(ogr.wkbPoint)
point2.AddPoint(11.557617,48.136767)    # Munich

enter image description here

Crear una transformación de EPSG:4326 (lat/long) a EPSG:3035 (Sistema de coordenadas proyectado para Europa en metros)

inSpatialRef = osr.SpatialReference()
inSpatialRef.ImportFromEPSG(4326)
outSpatialRef = osr.SpatialReference()
outSpatialRef.ImportFromEPSG(3035)
coordTransform = osr.CoordinateTransformation(inSpatialRef, outSpatialRef)

Transformar nuestros puntos

point1.Transform(coordTransform)
>> POINT (4550348.379724434576929 3275002.535206703934819 0) 

point2.Transform(coordTransform)
>>POINT (4436977.705661337822676 2781579.793173507787287 0)

Y obtener la distancia así

point1.Distance(point2)             # Distance in meter from Munich to Berlin
>>> 506279.480221                   # roughly 506 km

O puede crear un polígono

ring = ogr.Geometry(ogr.wkbLinearRing)
ring.AddPoint(-23.378906,68.974164)     # North West Corner of Europe
ring.AddPoint(-23.378906,34.307144)     # South West Corner of Europe
ring.AddPoint(31.464844,34.307144)      # South East Corner of Europe
ring.AddPoint(31.464844,68.974164)      # North East Corner of Europe
ring.AddPoint(-23.378906,68.974164)     # North West Corner of Europe (to close to polygon)

polygon = ogr.Geometry(ogr.wkbPolygon)  
polygon.AddGeometry(ring)               # rough bounding box around Europe
polygon.Transform(coordTransform)       # transform it

enter image description here

Y comprueba si el polígono contiene el punto

polygon.Contains(point1)                    # Does Europe contain Berlin?
>>> True                                    # It does ;)

enter image description here

Y para el resto puedes escribir funciones para hacer lo que quieras.

1voto

Chris Kloberdanz Puntos 1871

GDAL/OGR debería ser suficiente para ti.

http://www.gdal.org/ogr/classOGRGeometry.html

i-Ciencias.com

I-Ciencias es una comunidad de estudiantes y amantes de la ciencia en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.

Powered by:

X