コード例 #1
0
def download_images(c_file, image_field,output_dir):

	csv_file = Csv_parser(c_file)
	headers = csv_file.get_header()
	csv_rows = csv_file.csv_rows
	img_index = csv_rows[0].index(image_field)

	#print img_index
	count =1
	for i in csv_rows:
		if (i[img_index] ==image_field) or (i[img_index]=='null'):
			count = count +1
			continue
		else:
			#print i[img_index]
			url = i[img_index]
			f = urllib.urlopen(url)
			localFile = open(output_dir+'/image_'+str(count)+'.jpg', 'wb')
			localFile.write(f.read())
			localFile.close()
			f.close()
			count = count +1


#download_images(full_file, image_f,out_put)
コード例 #2
0
def download_images(c_file, image_field, output_dir):

    csv_file = Csv_parser(c_file)
    headers = csv_file.get_header()
    csv_rows = csv_file.csv_rows
    img_index = csv_rows[0].index(image_field)

    #print img_index
    count = 1
    for i in csv_rows:
        if (i[img_index] == image_field) or (i[img_index] == 'null'):
            count = count + 1
            continue
        else:
            #print i[img_index]
            url = i[img_index]
            f = urllib.urlopen(url)
            localFile = open(output_dir + '/image_' + str(count) + '.jpg',
                             'wb')
            localFile.write(f.read())
            localFile.close()
            f.close()
            count = count + 1


#download_images(full_file, image_f,out_put)
コード例 #3
0
def kmz_main(output_dir,csvfile,lat,lng,output_name):
	output_name= output_name.replace('.csv','')
	output_dir = output_dir + '/'
	x= Csv_parser(csvfile)
	fields = x.get_header()			# Fields is an array of the header attributes

	for i in range(len(fields)):
		if fields[i] == lat:
			lat_index = i
		if fields[i] == lng:
			lng_index = i

	#print lat_index, lng_index # The lat and long index in the array
	kml = simplekml.Kml()

	for j in range(len(x.csv_rows)):
		if (j == 0):
			continue
		else:
			if (x.csv_rows[j][lat_index] !='null') or (x.csv_rows[j][lng_index]!='null'):
				#print x.csv_rows[j][lat_index],x.csv_rows[j][lng_index]

				lat_cord = x.csv_rows[j][lat_index]
				lng_cord = x.csv_rows[j][lng_index]
				pnt = kml.newpoint(coords=[(lng_cord , lat_cord)])
				#pnt.name = 'Point '+str(x.csv_rows[j])
				descript = "<table border=\'1\'><th>Attributes</th><th>Value</th>"
				for h in range(len(x.csv_rows[j])):
					#pnt.description = str(fields[h])+' : '+str(x.csv_rows[j][h])+'<br />'
					descript=descript+'<tr><td><strong>'+fields[h]+'</strong></td>'+'<td>'+x.csv_rows[j][h]+'</td>'+'</tr>'
					#print fields[h]
				pnt.description = descript+'</table>'
	kml.savekmz(output_dir+output_name+'.kmz')
コード例 #4
0
	def get_list(self,index):
	    # get selected line index
	    index = self.file_listbox.selection()[0]
	    current_file= self.file_listbox.item(index)['values'][0]
	    for i in range(len(self.file_tree_full)):
	    	if current_file== self.file_tree_full[i][0]:
	    		filename= self.file_tree_full[i][2]
	    csv_file = Csv_parser(filename)
	    headers = csv_file.get_header()
	    self.add_headers_to_menu(headers)
コード例 #5
0
def create_shape(cfile,lat_field,lng_field,output_dir,file_full):
	output_shape = cfile.replace('.csv','')
	output_dir = output_dir +'/'
	projection = 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]'
	csv_file = Csv_parser(file_full)
	headers = csv_file.get_header()
	headers_char = [0]*len(headers)
	csv_rows=csv_file.csv_rows
	lat_index = csv_rows[0].index(lat_field)
	lng_index = csv_rows[0].index(lng_field)
	#print lat_index, lng_index
	
	shape_file = shapefile.Writer(shapefile.POINT)

	for h in csv_rows:
		for g in range(len(h)):
			if len(h[g]) >headers_char[g]:
				headers_char[g] = len(h[g])

	for i in range(len(headers)):
		shape_file.field(headers[i], 'C', headers_char[i])

	for row in csv_rows:
		if (row[lat_index] =="null" or row[lng_index]=="null"):
			continue
		else:
			if row !=headers:
				shape_file.point(float(row[lng_index]), float(row[lat_index]))
				shape_file.recordFromList(row)

	
	shape_file.save(output_dir+output_shape)
	proj_file = open(output_dir+output_shape+'.prj','w')
	proj_file.write(projection)
	proj_file.close()



#create_shape(output_name,lat,lng,output_dir,file_full)
コード例 #6
0
def create_shape(cfile, lat_field, lng_field, output_dir, file_full):
    output_shape = cfile.replace('.csv', '')
    output_dir = output_dir + '/'
    projection = 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]'
    csv_file = Csv_parser(file_full)
    headers = csv_file.get_header()
    headers_char = [0] * len(headers)
    csv_rows = csv_file.csv_rows
    lat_index = csv_rows[0].index(lat_field)
    lng_index = csv_rows[0].index(lng_field)
    #print lat_index, lng_index

    shape_file = shapefile.Writer(shapefile.POINT)

    for h in csv_rows:
        for g in range(len(h)):
            if len(h[g]) > headers_char[g]:
                headers_char[g] = len(h[g])

    for i in range(len(headers)):
        shape_file.field(headers[i], 'C', headers_char[i])

    for row in csv_rows:
        if (row[lat_index] == "null" or row[lng_index] == "null"):
            continue
        else:
            if row != headers:
                shape_file.point(float(row[lng_index]), float(row[lat_index]))
                shape_file.recordFromList(row)

    shape_file.save(output_dir + output_shape)
    proj_file = open(output_dir + output_shape + '.prj', 'w')
    proj_file.write(projection)
    proj_file.close()


#create_shape(output_name,lat,lng,output_dir,file_full)
コード例 #7
0
def kmz_main(output_dir, csvfile, lat, lng, output_name):
    output_name = output_name.replace('.csv', '')
    output_dir = output_dir + '/'
    x = Csv_parser(csvfile)
    fields = x.get_header()  # Fields is an array of the header attributes

    for i in range(len(fields)):
        if fields[i] == lat:
            lat_index = i
        if fields[i] == lng:
            lng_index = i

    #print lat_index, lng_index # The lat and long index in the array
    kml = simplekml.Kml()

    for j in range(len(x.csv_rows)):
        if (j == 0):
            continue
        else:
            if (x.csv_rows[j][lat_index] !=
                    'null') or (x.csv_rows[j][lng_index] != 'null'):
                #print x.csv_rows[j][lat_index],x.csv_rows[j][lng_index]

                lat_cord = x.csv_rows[j][lat_index]
                lng_cord = x.csv_rows[j][lng_index]
                pnt = kml.newpoint(coords=[(lng_cord, lat_cord)])
                #pnt.name = 'Point '+str(x.csv_rows[j])
                descript = "<table border=\'1\'><th>Attributes</th><th>Value</th>"
                for h in range(len(x.csv_rows[j])):
                    #pnt.description = str(fields[h])+' : '+str(x.csv_rows[j][h])+'<br />'
                    descript = descript + '<tr><td><strong>' + fields[
                        h] + '</strong></td>' + '<td>' + x.csv_rows[j][
                            h] + '</td>' + '</tr>'
                    #print fields[h]
                pnt.description = descript + '</table>'
    kml.savekmz(output_dir + output_name + '.kmz')