Conversion de latitudes et longitude en index en python
Bonjour à tous,
Je suis débutant sur Python, et je m'initie actuellement via un site
Je bloque sur une procédure servant à convertir des latitudes & longitudes en index, pour faciliter les recherches.
Quelqu'un peut il m'expliquer la logique de fonctionnement svp ?
Mon problème est avec le code suivant:
"
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
class Zone:
ZONES = []
MIN_LONGITUDE_DEGREES = -180
MAX_LONGITUDE_DEGREES = 180
MIN_LATITUDE_DEGREES = -90
MAX_LATITUDE_DEGREES = 90
WIDTH_DEGREES = 1 # degrees of longitude
HEIGHT_DEGREES = 1 # degrees of latitude
def __init__(self, corner1, corner2):
self.corner1 = corner1
self.corner2 = corner2
self.inhabitants = []
@property
def population(self):
return len(self.inhabitants)
def add_inhabitant(self, inhabitant):
self.inhabitants.append(inhabitant)
def contains(self, position):
return position.longitude >= min(self.corner1.longitude, self.corner2.longitude) and \
position.longitude < max(self.corner1.longitude, self.corner2.longitude) and \
position.latitude >= min(self.corner1.latitude, self.corner2.latitude) and \
position.latitude < max(self.corner1.latitude, self.corner2.latitude)
@classmethod
def find_zone_that_contains(cls, position):
# Compute the index in the ZONES array that contains the given position
longitude_index = int((position.longitude_degrees - cls.MIN_LONGITUDE_DEGREES)/ cls.WIDTH_DEGREES)
latitude_index = int((position.latitude_degrees - cls.MIN_LATITUDE_DEGREES)/ cls.HEIGHT_DEGREES)
longitude_bins = int((cls.MAX_LONGITUDE_DEGREES - cls.MIN_LONGITUDE_DEGREES) / cls.WIDTH_DEGREES) # 180-(-180) / 1
zone_index = latitude_index * longitude_bins + longitude_index
# Just checking that the index is correct
zone = cls.ZONES[zone_index]
assert zone.contains(position)
return zone
" |
Par avance merci de vos lumieres :-)
Cédric