1

Here is what I have done to project shapely points to pixel coordinates :

#shapely list of points
points= ['POINT (656822.0796426814 -185003.7243437266)', 'POINT 
(656917.7545657885 -184985.6672704536)', 'POINT (656997.7888963958 
-185001.578684116)']

#converting shapely list to np array
coords_list = [[geom.xy[0][0], geom.xy[1][0]] for geom in points ]
coords = np.array(coords_list)

# Reproject shapefile points to numpy coordinate system
proj_im = gdal.Open(input.tif')
geoinformation = proj_im.GetGeoTransform()

xorigin = geoinformation[0]
yorigin = geoinformation[3]
pix_size = abs(geoinformation[1])

coords_unp = np.roll(np.column_stack(((coords[:, 0] - xorigin) / pix_size, \
                                      (yorigin - coords[:, 1])/pix_size)),1, 1)
print(coord_unp)
>> [[ 2359.02892404  1537.68823732]
   [ 2085.43690476  2987.30828439]
   [ 2326.51892994  4199.94965723]]

How do I convert back from pixel coordinates to lat,lon?

1

you have to know what your origin projection is to convert coordinates, since you are using python there is a library Pyproj that does this, ( I'll assume in this code that your origin projection is the pseudo mercator EPSG:3857 which unit is the meter )

from pyproj import Proj, transform
import shapely.geometry as geom

inProj = Proj(init='epsg:3857')
outProj = Proj(init='epsg:4326')

points_in_lat_lon = []
for point in points:
     x, y = point.coords[0]
     lat, lon = transform(inProj, outProj, x, y)
     points_in_lat_lon.append(geom.Point([lat, lon])
  • I dnt want to change the projection, I want to convert Cartesian coordinates(x,y) to lat, long values – FJ_Abbasi Aug 22 '17 at 12:13
  • then I think you should change the question to how to convert back from pixel coordinates to x,y coordinates, and have you tried reversing the equation you used in np.roll ? – Hicham Zouarhi Aug 22 '17 at 12:19
  • I Changed the topic of question. yes i have tried reversing that equation, but it didn't work. – FJ_Abbasi Aug 22 '17 at 12:38

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.