1

I am processing shapefiles in python using standard library functions like Python “shapefile” library and GeoPandas. I have two shapefiles having the same projected co-ordinate system-> WGS_1984_UTM_Zone_44N.

But the first shapefile has lat-long values in “Degree decimal” format and the second shapefile has lat-long values in “Degree minutes seconds” format.

In order to proceed with further processing (merging the information from the two shapefiles) I need both shapefiles to be of the same format (either Degree decimal or degree minutes seconds format).

SHAPEFILE 1(LAT-LONG VALUES):

bbox =[300827.06, 2347377.51977153, 302414.939109026, 2348912.5], 
parts =[0], shapeTypeName =POLYGON ('number of points in shape ', 45)

bbox =[301663.127583958, 2345705.27205747, 303118.13, 2348567.5722892], 
parts =[0, 755], shapeTypeName =POLYGON ('number of points in shape ', 760)

SHAPEFILE 2(LAT-LONG VALUES):

bbox =[78.97802486855807, 21.102058250837672, 78.98699067762817, 21.107654743123476], 
parts =[0], shapeTypeName =POLYGON ('number of points in shape ', 28)

bbox =[79.1842653948201, 21.090100785102777, 79.18754905100815, 21.092718192209304], 
parts =[0], shapeTypeName =POLYGON ('number of points in shape ', 10)

Is there some function that can be applied on the shapefile for this conversion?

1

What you need is that both shapefiles are in the same projection and not in the same format because

Therefore, using pyproj and shapely (shapely: Other Transformations) here (but you can do it directly with GeoPandas: re-projecting or Pyshp (shapefile) in Reproject a Polygon Shapefile using PyShp and PyProj)

import pyproj
from functools import partial
from shapely.geometry import box
from shapely.ops import transform
project = partial(
      pyproj.transform,
      pyproj.Proj(init='epsg:32644'), # WGS 84 / UTM zone 44N
      pyproj.Proj(init='epsg:4326'))  # WGS 84 
# shapefile 1: polygon from bbox
poly1 = box(300827.06, 2347377.51977153, 302414.939109026, 2348912.5)
print(poly1.wkt)
POLYGON ((302414.939109026 2347377.51977153, 302414.939109026 2348912.5, 300827.06 2348912.5, 300827.06 2347377.51977153, 302414.939109026 2347377.51977153))
# convert to WGS84 degrees
print(transform(project, poly1))
POLYGON ((79.09633427339337 21.21722921309659, 79.09615638055131 21.23109069447097, 79.08086274438327 21.23091739451839, 79.08104206411475 21.21705603696002, 79.09633427339337 21.21722921309659))

Or the the reverse:

project2 = partial(
  pyproj.transform,
  pyproj.Proj(init='epsg:4326'),  # WGS 84 
  pyproj.Proj(init='epsg:32644')) # WGS 84 / UTM zone 44N
# shapefile 2: polygon from bbox
poly2 =box(78.97802486855807, 21.102058250837672, 78.98699067762817, 21.107654743123476)
print(poly2.wkt)
POLYGON ((78.98699067762817 21.10205825083767, 78.98699067762817 21.10765474312348, 78.97802486855807 21.10765474312348, 78.97802486855807 21.10205825083767, 78.98699067762817 21.10205825083767))
# convert to WGS 84 / UTM zone 44N meters
print(transform(project2, poly2))
POLYGON ((290900.7896485617 2334765.616623482, 290908.6322568275 2335385.288572263, 289977.0655666431 2335397.106313651, 289969.1879661513 2334777.43181831, 290900.7896485617 2334765.616623482))
  • Thanks, this does the required conversion. But what I have observed is that both shapefiles have the same CRS. I used GeoPandas to read the shapefiles and the .crs attribute to display the current coordinate reference system. The output is as follows: CRS of shapefile 1 : {'init': u'epsg:32644'} CRS of shapefile 2 : {'init': u'epsg:32644'} But the transformation still works, could you please elaborate on this? – Manaswini Muralidaran Mar 4 at 5:03
  • 1
    For me, It is a mistake because the projection of shapefile 2 is not epsg:32644 – gene Mar 4 at 16:10

Your Answer

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

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