Showing posts with label via. Show all posts
Showing posts with label via. Show all posts
Wednesday, February 11, 2015
Selecting and Downloading Raster Data via ftp using Python
My problem was to browse through a large number of Radarsat-2 images on a ftp-server and download the ones falling into my area of interest. Each image is available as a *.zip file and a corresponding *.tif map projected quicklook
There is two main pieces that help solving this problem:
1) You can in fact use gdalinfo to retrieve information about a raster file on ftp without having to download the file itself. The command (which I found documented here ) is, the output is here redirected to the output_tempfile:
or calling from within Python using os.system with the variables defined before:
2) The second step is then to read the centre coordinate from the output_tempfile and if matching download the file. The ftp download is described here , lets see the whole script, which hopefully is self-explanatory with its comments:
There is two main pieces that help solving this problem:
1) You can in fact use gdalinfo to retrieve information about a raster file on ftp without having to download the file itself. The command (which I found documented here ) is, the output is here redirected to the output_tempfile:
gdalinfo /vsicurl/ftp://username:password@ftp.adress.no/outfolder/filename.tif > output_tempfile
or calling from within Python using os.system with the variables defined before:
os.system(rgdalinfo /vsicurl/ftp:// + username + : + password + "@" + ftpserver + workingfolder + file + > + output_tempfile)
2) The second step is then to read the centre coordinate from the output_tempfile and if matching download the file. The ftp download is described here , lets see the whole script, which hopefully is self-explanatory with its comments:
import ftplib, os
#DEFINE FTP SERVER PARAMETERS
ftpserver = ftp.youradress.no
username = anonymous
password = guest
workingfolder = /Out/max/
#temporary file storing location info from quicklook
output_tempfile = C:UsersmaxDesktop\test.txt
#destinationfolder for download
destination_folder = C:UsersmaxDocuments\
#Open ftp
ftp = ftplib.FTP(ftpserver, username , password)
ftp.cwd(workingfolder)
#Create a file list of all quicklooks
filelist = []
try:
filelist = ftp.nlst(*.tif)
except ftplib.error_perm, resp:
if str(resp) == "550 No files found":
print "No files in this directory"
else:
raise
for file in filelist:
#get quicklook file info and save in temporary file
os.system(rgdalinfo /vsicurl/ftp:// + username + : + password + "@" + ftpserver + workingfolder + file + > + output_tempfile)
#Read from temporary file the centre coordinates of the quicklook
search = open(output_tempfile)
for line in search:
if "Center" in line:
longitude_quicklook = float(line[15:25])
latitude_quicklook = float(line[28:38])
search.close()
print Longitude , longitude_quicklook
print Latitude , latitude_quicklook
#Check if scene is contained in area of interest, divided in two areas since not rectangular
if ((-23.0 < longitude_quicklook < 67.0) and (71.0 < latitude_quicklook < 90.0)):
contained = True
print true
elif ((-33.0 < longitude_quicklook < 14.0) and (66.0 < latitude_quicklook < 71.0)):
contained = True
print true
else:
contained = False
zipfile = file[:-7] + .zip
zipsavefile = destination_folder + file[:-7] + .zip
print zipfile
print zipsavefile
#If file contained in area of interest, download the file
if contained == True:
print transferring , zipfile
ftp.cwd(workingfolder)
ftp.retrbinary(RETR + zipfile, open(zipsavefile, wb).write)
print transferred , zipfile
#Close ftp connection
ftp.quit()
#Remove temporary file
os.remove(rC:UsersmaxDesktop est.txt)
#End
Friday, January 23, 2015
Share your devices mobile data connection via USB Wi Fi or Bluetooth
How to turn your android smartphones into Wi-Fi Router .Share your devices mobile data connection via USB,Wi-Fi or Bluetooth .
Do you know , you can turn your smartphone into portable Wi-Fi hotspot, to share its internet connection with other devices(Laptop,tablets,smartphones ). You can share your Android Device internet with computer , smartphones and tablets.This is amazing built in Android OS feature which allow other users to use your mobile data from different devices.
We will discuss these option step by step.
i) How to turn your Android mobile phone into Wi-Fi Router .
ii) How to turn your Android phone into Internet Modem .
iii) How to share your Android device mobile data via Bluetooth.
We will discuss these option step by step.
i) How to turn your Android mobile phone into Wi-Fi Router .
ii) How to turn your Android phone into Internet Modem .
iii) How to share your Android device mobile data via Bluetooth.
you need few simple steps .
1. How to turn your android smartphones into Wi-Fi Router ?
First you need to activate mobile data. (Wi-fi hotspot will work on 3g,4g and other fast services.)
Go to setting and click on More settings.

Select tethering and portable hotspot.

You will have these 3 options. Turn on Portable Wi-Fi and click on it for further options.

It will automatically turn into hotspot and will allow devices to connect. Your device name will be shown as AndroidAP from other devices .


Your devices will be shown in Wi-Fi connection of other smartphones and tablets as shown in below image.


you can Allow and Disallow other devices by tapping a + sign to be connected or not. You can allow devices to connect manually by configuring other device name and Mac Address.



2. How to turn your android phone into Internet Modem .How to use internet on computer via Android Mobile .
You can also turn your android smartphones into internet modem to use internet on computer. There is nothing difficult to turn your smartphone into internet modem.
Go to setting and click on more setting

Now select Tethering and portable hostpot .

Now select USB tethering and connect your smartphone with computer via data cable.

Computer will recognized attached device ans will start installing drivers. After installing drivers your smartphone will be attach to computer as modem. you can view it by clicking on device manager as highlighted in picture,as " Remote NDIS based Internet Sharing Device ".You can check this connection as well in My Network .

3. How to share your Android device mobile data via Bluetooth.
Following option will not work on lower then 4.3. To share your mobile data via bluetooth to other devices your smartphone or tablet must be on Android OS 4.3 or Higher. Pair your devices via bluetooth first then go to more setting . Turn on Portable Wi-Fi hotspot . Select Bluetooth tethering .

Now go to bluetooth tab. See Desired Paired Device. Click on paired device setting .You will see Internet access with bluetooth sign under Profiles tab. Click on it to allow paired device to start using internet via your device.

Note: The above method is based on Author personal experience . Found nothing harmful .
Subscribe to:
Posts (Atom)