Examples¶
Here are some examples of using this library.
Examples of transforming pixel coordinates to latitude and longitude, and vise versa It is not going to be exactly the same value, but it is precise enough for most of the use cases
from coords_transformer.coords_calculation import *
# Get x pixel coordinate from longitude based on the zoom level
convert_lng_zoom_to_x(141.242035, 17)
# return value -> 29941928
# Get y pixel coordinate from latitude based on the zoom level
convert_lat_zoom_to_y(45.178506, 17)
# return value -> 12046803
# Get longitude from x pixel coordinate based on the zoom level
convert_x_zoom_to_lng(29941927, 17)
# return value -> 141.24202609062195
# Get latitude from y pixel coordinate based on the zoom level
convert_y_zoom_to_lat(12046802, 17)
# return value -> 45.17851270178206
An example of the designated filename format
If you’d like to get the latitude and longitude of a certain point within the satellite image, you have to name your satellite image file in the following format. It has an index, longitude and latitude of the center point, image pixel size, and zoom level.
0_long130dot51051050424576-lati33dot25308662907951-size512-zoom17.jpg
An example of getting the point object with pixel coordinates, longitude, and latitude from pixel coordinates within the satellite image.
from coords_transformer.point.factory import create_from_lat_lng_zoom
from coords_transformer.point.service import create_point_from_image_pixel_coords
from coords_transformer.filename.factory import create_from_filename
# Create the Filename object from filename.
filename = "0_long130dot51051050424576-lati33dot25308662907951-size512-zoom17.jpg"
path = "image/"
filename_obj = create_from_filename(filename, path)
# filename_obj -> FileName(lng=130.51051050424576, lat=33.25308662907951, idx=0, size=512, path='image/', zoom=17)
# Create the Point object from latitude, longitude, and zoom level.
# This Point object should be created from the longitude and latitude of the satellite image center point
center_point = create_from_lat_lng_zoom(filename_obj.lat, filename_obj.lng, filename_obj.zoom)
# center_point -> Point(lng=130.51051050424576, lat=33.25308662907951, x=28941677, y=13487547)
# Pass x and y pixel coordinates within the satellite image, center_point, image pixel size, and zoom level
# Then you can get the Point object
create_point_from_image_pixel_coords(5, 10, center_point, filename_obj.size, filename_obj.zoom)
# return value -> Point(lng=130.5078148841858, lat=33.25529597095926, x=28941426, y=13487301)