In Shapely, the 'Point' object itself doesn't inherently possess a Coordinate Reference System (CRS) attribute. However, you can use the 'pyproj' library to change the CRS of a 'Point' object. Here's an example:

import pyproj
from shapely.geometry import Point

# Define the original point with its coordinates
x = 116.4074
y = 39.9042
point = Point(x, y)

# Define the original CRS (e.g., WGS84, EPSG:4326)
original_crs = pyproj.Proj('EPSG:4326')

# Define the desired CRS (e.g., UTM Zone 50N, EPSG:32650)
desired_crs = pyproj.Proj('EPSG:32650')

# Transform the point to the desired CRS
transformed_point = pyproj.transform(original_crs, desired_crs, point)

# Print the transformed point
print(transformed_point)

In this example, we have a 'Point' object called 'point' with the original coordinates (116.4074, 39.9042). We define the original CRS as 'EPSG:4326', which corresponds to the WGS84 coordinate system commonly used for latitude and longitude.

Next, we define the desired CRS as 'EPSG:32650', which corresponds to the UTM Zone 50N coordinate system, using the 'pyproj.Proj()' function.

We then use the 'pyproj.transform()' function to transform the 'point' from the original CRS to the desired CRS. The function takes three arguments: the original CRS, the desired CRS, and the point object to be transformed. The resulting transformed point is stored in the 'transformed_point' variable.

Finally, we print the transformed point to the console, which will now have coordinates in the desired CRS.

Make sure to install the 'pyproj' library before running the code. You can install it using 'pip install pyproj'. Also, ensure that you are using the correct CRS codes for your specific use case.

Change CRS of a Point in Shapely using pyproj

原文地址: https://www.cveoy.top/t/topic/mxL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录