0

I have one shapefile with XY coordinates in meters. Now, I want to develop one script in Python which converts meters to decimal degrees.

Can you help me to develop this?

0

4 Answers 4

4

Sounds like you are looking to project your shapefile. Look at Project (Data Management) which:

Projects spatial data from one coordinate system to another.

It has examples of how to do it using Python.

0
1

The easiest way to do it is using GDAL command line calls from Python.

So, using the line from above (ogr2ogr ...) along with a GDAL install (see Installing GDAL with Python on windows?) you can sort out a method which will do it for you.

The more comprehensive way is to find a shapefile importing tool and then using pyproj to do it natively in Python. I would try the former for a script, and the latter if you want something embedded in a portable application.

1

It would really help if you would write what do you want to do exactly. You can use GDAL to do this or call a web service if you would find one. For example you can try using this http://www.opencts.org/guidedwcts.php in your python code.

If you want to write it completely on your own, convert this java code to python. There is also some theory on what really happens there.

0
0

This should give you a good starting point:

# Import necessary modules
import shapefile
from pyproj import Proj, transform

# Read in the shapefile
sf = shapefile.Reader("path/to/shapefile.shp")

# Define the projection for the shapefile
inProj = Proj(init="epsg:3857")

# Define the projection for decimal degrees
outProj = Proj(init="epsg:4326")

# Loop through each feature in the shapefile
for feature in sf.shapeRecords():
    # Get the coordinates of the feature
    coords = feature.shape.points

    # Convert the coordinates from meters to decimal degrees
    coords_dd = transform(inProj, outProj, coords[0], coords[1])

This code uses the pyproj module to convert the coordinates from meters to decimal degrees. It loops through each feature in the shapefile and converts the coordinates using the transform() function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.