Convert WGS_1984_UTM and WGS_1984_Mercator coordinates to latitude and longitude coordinates python

Insert image description here

1. What are the PROJECTIONs of remote sensing images?

There are many common projection types for remote sensing images, and the specific projection method chosen depends on the characteristics of the data and usage requirements. The following lists some common remote sensing image projection types:

  1. UTM (Universal Transverse Mercator) projection: One of the most common projection types, the earth is divided into 60 longitudinal projection areas, and each area has a central meridian.

  2. Geographic Coordinate System: Also known as the latitude and longitude coordinate system, it uses longitude and latitude coordinates to represent locations on the earth.

  3. Albers projection: used for larger areas, can maintain equal area characteristics, and is suitable for map drawing and statistical analysis.

  4. Lambert Conformal Conic projection: suitable for large-scale map drawing, especially for areas with large east-west spans.

  5. Mercator projection: Projects the earth's surface onto a cylindrical surface, suitable for navigation and navigation applications.

  6. Sinusoidal projection: Projects the Earth onto a cylinder, equidistant from the equator.

  7. Polar Stereographic projection: Suitable for polar regions, projects the Earth onto a cone between the South Pole or the North Pole.

These are just some common types of remote sensing image projection, and there are actually many other projection methods to choose from. Choosing the right projection type requires consideration of many factors, such as geographic extent, scale, shape-preserving properties, data analysis needs, and more.
Insert image description here

2. What are the PROJECTION parameters of GetProjection for remote sensing images?

The PROJECTION parameter returned by the GetProjection() method of remote sensing images is usually a string representing projection information. The specific format of the PROJECTION parameter may vary depending on the software and data format. Here are some examples of common PROJECTION parameters:

  1. UTM coordinate system (taking WGS 84 as an example):
'PROJCS["WGS 84 / UTM zone 11N",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","32611"]]'
  1. Geographic coordinate system (taking WGS 84 as an example):
'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]'
  1. Mercator projection:
'PROJCS["World_Mercator",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Mercator"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",0.0],PARAMETER["Standard_Parallel_1",0.0],UNIT["Meter",1.0]]'
  1. Albers projection:
'PROJCS["Albers Conical Equal Area",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers_Conic_Equal_Area"],PARAMETER["False_Easting",0],PARAMETER["False_Northing",0],PARAMETER["longitude_of_center",10],PARAMETER["Standard_Parallel_1",43],PARAMETER["Standard_Parallel_2",62],PARAMETER["latitude_of_center",30],UNIT["Meter",1],AUTHORITY["EPSG","102008"]]'
  1. Lambert Conformal Conic projection:
'PROJCS["Lambert Conformal Conic",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["False_Easting",0],PARAMETER["False_Northing",0],PARAMETER["Central_Meridian",-95],PARAMETER["Standard_Parallel_1",25],PARAMETER["Standard_Parallel_2",35],PARAMETER["latitude_of_origin",25],UNIT["Meter",1],AUTHORITY["EPSG","102004"]]'

Please note that the PROJECTION parameter in the above example is for illustration purposes only and the actual PROJECTION parameter may be more complex or contain additional projection-related information. The specific PROJECTION parameters can be determined according to the data format of the remote sensing image and the software library used.

3. Python obtains the projected coordinate system of remote sensing images

To obtain the projected coordinate system of remote sensing images, you can use the GDAL library in Python. GDAL is a powerful library for spatial data conversion and processing. The following is a sample code for using the GDAL library to obtain the projected coordinate system of remote sensing images:

from osgeo import gdal, osr

def get_projection(image_path):
    dataset = gdal.Open(image_path)
    if dataset is None:
        print("无法打开影像文件")
        return None

    projection = dataset.GetProjection()
    spatial_ref = osr.SpatialReference()
    spatial_ref.ImportFromWkt(projection)

    return spatial_ref.ExportToPrettyWkt()

In the above sample code, get_projectionthe function receives the path of a remote sensing image file as an input parameter. This function uses the GDAL library to open an image and obtain its projection information. It then uses the SpatialReference class to convert the projection information into a readable string form and returns it as the result.

You can call get_projectionthe function as follows to obtain the projected coordinate system of the remote sensing image:

image_path = "path/to/your/image.tif"

projection = get_projection(image_path)

if projection is not None:
    print("影像的投影坐标系:")
    print(projection)

Simply replace in the above sample code image_pathwith your own remote sensing image file path, and then run the code to obtain the projected coordinate system information of the image.

4. Python obtains the coordinates of the upper left corner and lower right corner of remote sensing data in the WGS_1984_UTM coordinate system

To obtain the upper left corner and lower right corner coordinates of remote sensing data in the WGS_1984_UTM coordinate system, you can use the GDAL and Proj libraries to obtain metainformation of remote sensing data and perform coordinate conversion. The following is a sample code that uses GDAL and Proj libraries to obtain the coordinates of the upper left corner and lower right corner of WGS_1984_UTM coordinate system remote sensing data:

from osgeo import gdal, osr

# 打开遥感影像文件
file_path = "path/to/your/image.tif"
dataset = gdal.Open(file_path)

# 获取地理转换信息
geo_transform = dataset.GetGeoTransform()

# 创建投影转换对象
source_projection = osr.SpatialReference()
source_projection.ImportFromWkt(dataset.GetProjection())

# 创建目标投影(WGS_1984_UTM)
target_projection = osr.SpatialReference()
target_projection.SetProjCS("WGS 84 / UTM")
target_projection.SetWellKnownGeogCS("WGS84")

# 创建坐标转换对象
coord_transform = osr.CoordinateTransformation(source_projection, target_projection)

# 获取左上角和右下角坐标
left = geo_transform[0]
top = geo_transform[3]
right = left + geo_transform[1] * dataset.RasterXSize
bottom = top + geo_transform[5] * dataset.RasterYSize

# 进行坐标转换
ul_lon, ul_lat, _ = coord_transform.TransformPoint(left, top)
lr_lon, lr_lat, _ = coord_transform.TransformPoint(right, bottom)

# 输出结果
print("左上角坐标:", ul_lon, ul_lat)
print("右下角坐标:", lr_lon, lr_lat)

# 关闭数据集
dataset = None

Please change in the example file_pathto your specific remote sensing image file path. The above code will open the remote sensing image file, use GDAL and Proj libraries to obtain its geographical transformation information and coordinate system information, create a coordinate transformation object, and perform coordinate transformation to obtain the latitude and longitude coordinates of the upper left corner and lower right corner in the WGS_1984_UTM coordinate system.

Please ensure that the GDAL and Proj libraries have been installed, and refer to the documentation of the relevant libraries for appropriate import and settings.

5. How does python determine whether the coordinate system of a remote sensing image is WGS_1984_UTM or WGS_1984_Mercator?

To determine whether the coordinate system of a remote sensing image is WGS_1984_UTM or WGS_1984_Mercator, you can use the GDAL library in Python for processing. GDAL provides a convenient method to obtain and determine the projected coordinate system of an image. The following is an example code for using the GDAL library to determine the coordinate system of remote sensing images:

from osgeo import gdal, osr

def get_coordinate_system(image_path):
    dataset = gdal.Open(image_path)
    if dataset is None:
        print("无法打开影像文件")
        return None

    projection = dataset.GetProjection()
    spatial_ref = osr.SpatialReference()
    spatial_ref.ImportFromWkt(projection)

    if spatial_ref.IsProjected():
        if 'UTM' in spatial_ref.GetAttrValue('PROJECTION'):
            return 'WGS_1984_UTM'
        elif 'Mercator' in spatial_ref.GetAttrValue('PROJECTION'):
            return 'WGS_1984_Mercator'
    else:
        return '未知坐标系'

    return '未知坐标系'

In the above sample code, get_coordinate_systemthe function receives the path of a remote sensing image file as an input parameter. The function uses the GDAL library to open an image and obtain its projection information. It then checks whether the projected coordinate system is a projected coordinate system, and if so, determines the specific projected coordinate system type by looking for keywords in the coordinate system name such as 'UTM' and 'Mercator'.

You can call get_coordinate_systemthe function as follows to determine the coordinate system type of remote sensing images:

image_path = "path/to/your/image.tif"

coordinate_system = get_coordinate_system(image_path)

if coordinate_system is not None:
    print("影像的坐标系类型:")
    print(coordinate_system)

Just replace the above example code image_pathwith your own remote sensing image file path, and then run the code to obtain and determine the coordinate system type of the remote sensing image. The output will appear as 'WGS_1984_UTM', 'WGS_1984_Mercator', or 'Unknown Coordinate System'.

How does python determine whether two data are latitude and longitude coordinates, Mercator projected coordinates or UTM projected coordinates?

In Python, you can use the following method to determine whether two data are latitude and longitude coordinates, Mercator projected coordinates, or UTM projected coordinates:

  1. Latitude and longitude coordinates: Usually, the range of latitude and longitude coordinates is [-180, 180] longitude and [-90, 90] latitude. You can determine whether the data is a latitude and longitude coordinate by judging whether the longitude value is within the range [-180, 180] and the latitude value is within the range [-90, 90].

  2. Mercator Projection Coordinates: Mercator Projection Coordinates are planar coordinate systems usually used over smaller areas. Mercator projected coordinates usually have a large value range. For example, in Web Mercator (EPSG 3857), the usual value range is [-20026376.39, 20026376.39]. You can determine whether the data is Mercator projected coordinates by judging whether the value is within the corresponding range.

  3. UTM projected coordinates: UTM projected coordinates are a commonly used coordinate system that divides the earth into longitudinal projected areas. UTM projected coordinates typically use a wide range of values. You can determine whether the data is UTM projected coordinates by judging whether the value is within the range corresponding to the UTM projection. For example, UTM projected coordinates usually have False Easting and False Northing parameters, which can be judged based on the range of the specific UTM zone.

It should be noted that this method can only make a preliminary judgment through the numerical range, and cannot 100% determine the coordinate type of the data. Correctly determining the data coordinate type may require more precise judgment and processing based on data attributes, metadata, or specialized libraries.

6. What is the projection of Transverse_Mercator?

Transverse Mercator™ is a common planar orthogonal projection used to convert geographic data on the Earth into planar coordinates. It is a transverse projection on some central meridian. The Transverse Mercator projection is tangential at the central meridian and orthoaxial elsewhere. This projection is suitable for smaller geographic areas, such as countries or regions.

There are many variations of the Transverse Mercator projection, the most common of which is the UTM (Universal Transverse Mercator) projection. UTM divides the earth into 60 longitudinal projection areas, each of which has a central meridian. The geographic coordinate system of each longitudinally projected area can be transformed using the Transverse Mercator projection.

The Transverse Mercator projection is widely used in cartography and spatial data processing, especially in large-scale surveying and mapping work. It effectively maintains shapes and angles within an area and provides a smooth projected coordinate system for easy measurement and analysis.

It should be noted that WGS_1984 is an ellipsoid, and Transverse Mercator is a projection method that can be applied to geographic coordinate data using the WGS_1984 ellipsoid. Therefore, WGS_1984 and Transverse Mercator are not directly interchangeable concepts. WGS_1984 is often used in conjunction with UTM projections, such as WGS_1984 UTM Zone 48N, which represents the UTM Zone 48N longitudinal projection area using the WGS_1984 ellipsoid and Transverse Mercator projection.

7. What is the difference between Transverse_Mercator and WGS_1984_UTM?

Transverse Mercator ™ and WGS_1984_UTM are both projected coordinate systems, but there are some differences between them.

Transverse Mercator ™ is a specific projection method used to convert geographic data on the Earth into planar coordinates. The TM projection is tangential at some central meridian and orthoaxial elsewhere. This means that the distance along the central meridian remains constant, and the farther away from the central meridian, the greater the distance distortion. TM projection is usually suitable for smaller areas, such as countries or regions.

WGS_1984_UTM is a specific implementation based on Transverse Mercator projection, which is used to divide the earth into 60 longitudinal projection areas. Each longitudinally projected area has a central meridian that is used to project the geographic coordinates of that area. WGS_1984_UTM uses the WGS_1984 ellipsoid as a datum, which approximately describes the shape of the Earth.

In summary, Transverse Mercator is a specific projection method, and WGS_1984_UTM is a specific implementation of the Transverse Mercator projection method . WGS_1984_UTM divides the earth into longitudinally projected regions and uses the Transverse Mercator projection in each region to process geographic data.

Insert image description here
UTM Zone 50N in the picture above represents eastern China.

8. Use python to convert WGS_1984_UTM coordinates into longitude and latitude coordinates

To convert WGS_1984_UTM coordinates to latitude and longitude coordinates, you can use the pyproj library in Python. The following is sample code to convert WGS_1984_UTM coordinates to latitude and longitude coordinates using the pyproj library:

from pyproj import Proj, transform

def utm_to_lonlat(utm_easting, utm_northing, utm_zone):
    # 定义UTM投影坐标系和WGS84经纬度坐标系
    utm_proj = Proj(proj='utm', zone=utm_zone, ellps='WGS84', preserve_units=False)
    lonlat_proj = Proj(proj='longlat', ellps='WGS84')

    # 将UTM坐标转换为WGS84经纬度
    lon, lat = transform(utm_proj, lonlat_proj, utm_easting, utm_northing)

    return lon, lat

The function in the above example code utm_to_lonlatreceives three parameters: utm_eastingUTM east coordinate, utm_northingUTM north coordinate, utm_zoneand UTM area. The function returns the converted longitude and latitude.

You can call functions to perform coordinate transformations as follows utm_to_lonlat:

utm_easting = 1234567
utm_northing = 9876543
utm_zone = 48

lon, lat = utm_to_lonlat(utm_easting, utm_northing, utm_zone)

print("经度: ", lon)
print("纬度: ", lat)

utm_eastingJust replace the , utm_northingand in the sample code utm_zonewith your own UTM coordinate values, and then run the code to get the converted latitude and longitude coordinates.

9. How does python parse the UTM area of ​​remote sensing image data?

To parse the UTM zones of remote sensing image data, you can use the GDAL library in Python. GDAL is a powerful library for spatial data conversion and processing. The following is a sample code that uses the GDAL library to parse the UTM region of remote sensing image data:

from osgeo import gdal, osr

def get_utm_zone(image_path):
    dataset = gdal.Open(image_path)
    if dataset is None:
        print("无法打开影像文件")
        return None

    # 获取影像的投影信息
    proj_info = dataset.GetProjection()
    spatial_ref = osr.SpatialReference()
    spatial_ref.ImportFromWkt(proj_info)

    # 获取投影信息中的地理坐标系
    geographic_cs = spatial_ref.GetAttrValue('GEOGCS')

    if not geographic_cs.startswith('WGS 84'):
        print("影像投影不是WGS84坐标系")
        return None

    # 获取投影信息中的UTM区域
    utm_zone = spatial_ref.GetUTMZone()

    return utm_zone

In the above sample code, get_utm_zonethe function receives the path of a remote sensing image file as an input parameter. This function uses the GDAL library to open an image and read its projection information. Then, it extracts the geographic coordinate system from the projection information and checks if it is a WGS84 coordinate system. Finally, it gets the UTM zone in the projection information and returns it as a result.

You can call get_utm_zonethe function as follows to parse the UTM zone of remote sensing image data:

image_path = "path/to/your/image.tif"

utm_zone = get_utm_zone(image_path)

if utm_zone is not None:
    print("影像的UTM区域:", utm_zone)

Just replace the above example code image_pathwith your own remote sensing image file path, and then run the code to obtain the UTM zone information of the image data.

10. Use python to convert latitude and longitude coordinates into WGS_1984_UTM coordinate system

To convert latitude and longitude coordinates to WGS_1984_UTM coordinate system, you can continue to use the pyproj library. The following is sample code to convert latitude and longitude coordinates to the WGS_1984_UTM coordinate system using the pyproj library:

from pyproj import Proj, transform

def lonlat_to_utm(lon, lat):
    # 定义WGS84经纬度坐标系和UTM投影坐标系
    lonlat_proj = Proj(proj='longlat', ellps='WGS84', datum='WGS84')
    utm_proj = Proj(proj='utm', zone=None, ellps='WGS84', preserve_units=False)

    # 将经纬度坐标转换为UTM坐标
    utm_easting, utm_northing = transform(lonlat_proj, utm_proj, lon, lat)

    return utm_easting, utm_northing, utm_proj.zone

The function in the above example code lonlat_to_utmreceives two parameters: lonlongitude and latlatitude. The function returns the converted UTM east coordinate, UTM north coordinate and UTM zone.

You can call functions to perform coordinate transformations as follows lonlat_to_utm:

lon = 123.456
lat = 45.678

utm_easting, utm_northing, utm_zone = lonlat_to_utm(lon, lat)

print("UTM东坐标: ", utm_easting)
print("UTM北坐标: ", utm_northing)
print("UTM区域: ", utm_zone)

lonSimply replace the and in the example code latwith your own latitude and longitude coordinates, and then run the code to get the easting, northing, and UTM zones of the converted WGS_1984_UTM coordinate system.

11. Use python to convert WGS_1984_Mercator coordinates into longitude and latitude coordinates

To convert WGS_1984_Mercator coordinates to latitude and longitude coordinates using Python, you can use the PyProj library to perform the projection transformation. Here is a sample code:

import pyproj

# 创建投影转换器
mercator = pyproj.CRS.from_string("EPSG:3857")  # WGS_1984_Mercator
wgs84 = pyproj.CRS.from_string("EPSG:4326")    # WGS84 经纬度坐标系
transformer = pyproj.Transformer.from_crs(mercator, wgs84, always_xy=True)

# 定义要转换的坐标点
x = 20037508.34  # 示例坐标 x
y = 20037508.34  # 示例坐标 y

# 执行坐标转换
lon, lat = transformer.transform(x, y)

# 输出结果
print("经度:", lon)
print("纬度:", lat)

In the example above, we first create a projection converter. EPSG:3857It is the coordinate reference system of WGS_1984_Mercator EPSG:4326and the WGS84 latitude and longitude coordinate system. Then, we pyproj.Transformer.from_crs()create a converter object using the function. Finally, we provide the example coordinates of points xand to be converted and convert them to longitude and latitude yusing the converter's method.transform()

Please make sure you have installed the PyProj library, and appropriately introduce the library and set up the EPSG code of the reference system in your code.

12. python converts latitude and longitude coordinates into WGS_1984_Mercator coordinates

To convert latitude and longitude coordinates to WGS_1984_Mercator coordinates using Python, you can use the PyProj library to perform the projection transformation. Here is a sample code:

import pyproj

# 创建投影转换器
wgs84 = pyproj.CRS.from_string("EPSG:4326")    # WGS84 经纬度坐标系
mercator = pyproj.CRS.from_string("EPSG:3857")  # WGS_1984_Mercator
transformer = pyproj.Transformer.from_crs(wgs84, mercator, always_xy=True)

# 定义要转换的经纬度坐标
lon = 116.396728   # 示例经度
lat = 39.909604    # 示例纬度

# 执行坐标转换
x, y = transformer.transform(lon, lat)

# 输出结果
print("X 坐标:", x)
print("Y 坐标:", y)

In the example above, we first create a projection converter. EPSG:4326is the WGS84 latitude and longitude coordinate system, and EPSG:3857is the coordinate reference system of WGS_1984_Mercator. Then, we pyproj.Transformer.from_crs()create a converter object using the function. lonFinally, we provide the sample latitude and longitude coordinates and to be converted and convert them to WGS_1984_Mercator coordinates latusing the converter's method.transform()

Please make sure you have installed the PyProj library, and appropriately introduce the library and set up the EPSG code of the reference system in your code.

13. Use python to convert WGS_1984_UTM coordinates into WGS_1984_Mercator coordinate system

To convert WGS_1984_UTM coordinates to WGS_1984_Mercator coordinate system, you can use the pyproj library in Python. First, make sure you have the pyproj library installed. If it is not installed, you can install it with the following command:

pip install pyproj

Then, you can use the following sample code to perform coordinate transformation:

from pyproj import Proj, transform

def utm_to_mercator(utm_easting, utm_northing, utm_zone):
    # 定义UTM投影坐标系和WGS84 Mercator投影坐标系
    utm_proj = Proj(proj='utm', zone=utm_zone, ellps='WGS84', preserve_units=False)
    mercator_proj = Proj(proj='merc', lon_0=0, lat_ts=0, ellps='WGS84')

    # 将UTM坐标转换为WGS84经纬度
    lon, lat = utm_proj(utm_easting, utm_northing, inverse=True)

    # 将WGS84经纬度转换为WGS84 Mercator坐标
    mercator_easting, mercator_northing = transform(mercator_proj, utm_proj, lon, lat)

    return mercator_easting, mercator_northing

The example uses two functions for coordinate transformation. utm_to_mercatorThe function receives three parameters: utm_eastingUTM east coordinate, utm_northingUTM north coordinate, utm_zoneand UTM area. This function returns the easting and northing coordinates of the converted WGS_1984_Mercator coordinate system.

You can call this function as follows to perform coordinate conversion:

utm_easting = 1234567
utm_northing = 9876543
utm_zone = 48

mercator_easting, mercator_northing = utm_to_mercator(utm_easting, utm_northing, utm_zone)

print("WGS_1984_Mercator坐标系坐标:")
print("East: ", mercator_easting)
print("North: ", mercator_northing)

utm_eastingJust replace the , utm_northingand in the above example code utm_zonewith your own UTM coordinate values, and then run the code to get the coordinates of the converted WGS_1984_Mercator coordinate system.

Guess you like

Origin blog.csdn.net/qq_44442727/article/details/132157054