2

I have a shapefile which I read with GeoPandas, this shapefile has lat/long coordinates and I want to transform it to UTM coordinates. I tried this:

shapefile = gpd.read_file('example.shp') #CRS = epsg:4326
shapefile.to_crs("+proj=utm +ellps=WGS84 +datum=WGS84 +units=m +no_defs",inplace=True)

But it doesn't transform my coordinates correctly. I think it is because I have to explicitly put in the code the UTM zone with the number and letter which can vary depending on the shapefile I read.

So for calculating the letter and number I tried this:

import utm
utmZones = set()
for p in shapefile.geometry:
    utmZones.add(utm.from_latlon(p.centroid.y,p.centroid.x)[2:4])
print(utmZones)

{(20, 'H'), (20, 'J'), (21, 'H')}

If the polygons fall in three different adjacent UTM zones is there any problem if I choose the UTM zone which is in the middle or should I create three different shapefiles one for each UTM zone?

  • Could it be that your input shape file spans a great area, so that the geometries would actually fall in multiple utm zones? – Johan Sep 26 at 9:37
  • The extent of the shapefile is: -65.7119415675062299,-37.0586312600577870 : -59.4019001867139096,-28.3061813103935407 It could be, but it would be strange. How can I check it? – David1212k Sep 26 at 9:57
  • You can for example download the utm zones grid and open that and your shp in a GIS to see which zones intersect with your shapefile – Johan Sep 26 at 10:33
  • 1
    UTM Zones are six degrees wide. You can determine the zone by adding 183 degrees to longitude, dividing by 6 and rounding (or adding 186 and truncating after division). Data should not be permitted to exceed 3-4 degrees into neighboring zones; if it does, UTM is the wrong projection, and you should use a conic (e.g., Albers Equal Area) instead. – Vince Sep 26 at 11:19
  • Is the data in Argentina or Antarctica/south Atlantic? If the former, it's in zones 20 and 21 south (mostly 20); if the latter, yes, it's in zones 24 - 26 south (mostly 25) so you should add a +south to the PROJ string besides the zone number. – mkennedy Sep 26 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.