How do I find a location specified in lat/long on a GeoTiff image (epsg:32643) in python? - geospatial

My overall task is to find a point of interest (specified in lat, lon) on a large .tif satellite image and crop the .tif image such that the point of interest is in the center of a nxn tile.
I am not too well-versed in geospatial programming so I'm kind of lost but I am currently unable to figure out how to find the point of interest on the .tif file. I tried using dataset.index(lon, lat) from rasterio but the output of that exceeded the width and height of the image (i.e dataset.index(lon, lat) gives something like 1063976, -234685 but the tif file is only 800x800) so I don't know what to make of it.
Any direction you could point me to would be super useful at this point!
Alternately, I'm thinking of constructing a shapefile with the lon, lat and a radius of n, and then clipping the .tif file with this shapefile using gdal, but I don't expect that to be straightforward either. So any thoughts at all would be super useful.

Related

Does vtk mesh generation change coordinates?

I converted nifti file to vtk using python-implemented vtk. The main function was vtkMarchingCubes.
contour=vtk.vtkMarchingCubes()
The result vtk meshes have proper shape but their locations seem changed.
For example, when I load them with the pial surface made from exactly the same nifti image using different pipelines (freesurfer) in the same scene, the result is like below.
Does vtk converting of nifti changes the coordinate of vertices or somehow 'reset' them?
VTK's MarchingCubes filter should produce triangles in the same coordinate system as the volume. The only issue is that the Nifti image also includes a coordinate system of the image, and VTK is probably not correctly using it. I'd guess there's a transform in the Nifti that VTK isn't properly using.
Try using either Slicer (slicer.org) or ITK-Snap (itksnap.org). They do better at maintaining coordinate systems for medical images.
Yes, VTK changes the coordinate when read nifti.
-get Q-matrix using GetQFormMatrix()
-transform coordinate using vtkTransform()
is reqiured.

How to rotate an Image with nearest neighbor and bilinear interpolations without using any OpenCv library?

I want to know any basic mathematics based algorithm to rotate an image using the nearest neighbor and bilinear interpolation without using OpenCV library and imrotate.
The image won't be cropped after rotation and full image must be displayed.
A rotation corresponds to an affine transformation of the coordinates and is easily described using matrix/vectors. It is no great deal to find the formulas on the Web.
Now the important thing to know, is that rather than taking the pixels of the original image an mapping them to the transformed image, you must work backwards.
Scan every pixel of the transformed image and by applying the inverse transform, find the corresponding coordinates in the original image. You need to do this using real coordinates.
Then
for the nearest-neighbor method, round the coordinates and just copy the source pixel value to the destination;
for the bilinear method, consider the four pixels around the obtained coordinates (you will perform a truncation to integer). Finally, compute the destination pixel as a bilinear combination of the four source pixels, using the fractional part of the coordinates as the weights to perform the interpolation.
Check the figures here: http://wtlab.iis.u-tokyo.ac.jp/wataru/lecture/rsgis/rsnote/cp9/cp9-7.htm

Android- use image view as map and put marker at given x,y coord

I am a newbie in Android UI stuff. I tried looking for approach for going forward with this problem but could not get success, my apologies if this has been answered already.
I have a png image of a map, whose corner's points latitude and longitudes are known. Now given a lat long which lies inside the map, I want to put a marker on map for the given location say pointx. this requires two steps:
1. converting lat long to x,y for the pointx based on known point's x,y coordinates
2. drawing an image view for map and then putting the marker at the given x,y location
I can not use google maps here as the T&C doesn't allow. any pointers will be really helpful.

Reducing the size of pdf figure file in matplotlib

In matplotlib, I am using LineCollection to draw and color the countries, where the boundaries of the counties are given. When I am saving the figure as a pdf file:
fig.savefig('filename.pdf',dpi=300)
the figure size are quite big. However, on saving them as png file:
fig.savefig('filename.png',dpi=300)
and then converting them to pdf using linux convert command the files are small. I tried reducing the dpi, however that do not change the pdf file size. Is there a way the figures can be saved directly as smaller-pdf files from matplotlib?
The PDF is larger, since it contains all the vector information. By saving a PNG, you produce a rasterized image. It seems that in your case, you can produce a smaller PDF by rasterizing the plot directly:
plt.plot(x, y, 'r-', rasterized=True)
Here, x, y are some plot coordinates. You basically have to use the additionally keyword argument raterized to achieve the effect.
I think using "rasterized = True" effectively saves the image similarly to png format. When you zoom in, you will see blurring pixels.
If you want the figures to be high quality, my suggestion is to sample from the data and make a plot. The pdf file size is roughly the amount of data points it need to remember.

Google Earth KML with polygones with longitudes greater than 180deg?

I use polygones in kml files for displaying a rocket's flightpath from ground into orbit in google earth kml files.
the problem is, that google earth can't handle longitued greater than 180deg, so when a rocket will circle more than ones around the globe the longitued values has to be recalculated.
Is there a way in using longitudes like 720deg and google can translate this by itself? I would prefer this, because I don'thave to change my programme and you can directly see the revolutions of the rocket around earth by its coordinates.
The KML definition indeed only allows arguments
between -180 and 180 for longitude
between -90 and 90 for latitude
see KML Reference - element "coordinates"
So I am afraid you will need to normalize your lon by introducing an angle function.
As mentioned by MikeD you will need to normalize to fit in the specs. Here is a site from Chris Veness with spherical formulas for doing lots of calculations that otherwise boggle the mind.

Resources