I'm trying to convert coordinates from lat/lon into pixel but I lose points in this process.
The code that I'm using is the following:
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
df=pd.read_csv('cords.csv')
cords=df.as_matrix(columns=['x','y'])
gt=[7.6445503225, 5.4065168747250134e-06, 0.0, 45.07436634583334, 0.0, -5.406516856707135e-06]
index=np.zeros(cords.shape)
index[:,1]=((cords[:,1] - gt[3]) / gt[5]).round()
index[:,0]=((cords[:,0] - gt[0]) / gt[1]).round()
index=index.astype(int)
index[:,0]=index[:,0]-min(index[:,0])+1
index[:,1]=index[:,1]-min(index[:,1])+1
row=max(index[:,1])
col=max(index[:,0])
image=np.zeros([row+1,col+1])
for i in range(0,len(index)):
image[index[i,1],index[i,0]]=255
If I plot the cords or the index points I get this:
If I plot the image I get this:
As you can see there are some points that are missing in translating lat/lon in to pixel numbers. Yellow is 255 value and purple is 0 value.
How can this be solved?
Here you find the coordinates that I'm using cords.csv
Here you find the coordinates with the values that need to be set to each pixel. cords_valus.csv
EDIT
In the folowing link you find the raster image from where I have extract the cordinates. It fits to Italy perfectly. raster
Best Answer
I think that there is not any problem in your data. They have values equal zero in that area. Issues are others. When I modified your code for obtaining your points and your raster (by using gdal and PyQGIS python modules), they don't match in Italy area. Your geotransform parameters are wrong (I fixed them with 'Polygon from layer extent' for point layer). Complete code is as follow:
After running above code at Python Console, it can be observed that points and image are shifted. It's due to algorithm to produce image. You need to fix it.
However, you can also rasterize your points by values and get a very quick result; as it observed at next image:
Apparently, there is not lost points in that area; as it showed by above image.