def upload(request): 'Upload waypoints' # If the form contains an upload, if 'gpx' in request.FILES: # Get gpxFile = request.FILES['gpx'] # Save targetPath = tempfile.mkstemp()[1] destination = open(targetPath, 'wt') for chunk in gpxFile.chunks(): destination.write(chunk) destination.close() # Parse dataSource = DataSource(targetPath) layer = dataSource[0] waypointNames = layer.get_fields('name') waypointGeometries = layer.get_geoms() for waypointName, waypointGeometry in itertools.izip( waypointNames, waypointGeometries): waypoint = Waypoint(name=waypointName, geometry=waypointGeometry.wkt) waypoint.save() # Clean up os.remove(targetPath) # Redirect return HttpResponseRedirect(reverse('waypoints-index'))
def save_waypoint(request, d): # try: # Waypoint User = d['User'] gefFile = d['gefFile'] gefFileNaam = d['gefFileNaam'] CompanyID = d['CompanyID'] ProjectID = d['ProjectID'] ProjectNaam = d['ProjectNaam'] StartDatum = d['StartDatum'] SoortGef = d['SoortGef'] Hyperlink_root = d['Hyperlink_root'] PointGeom = d['PointGeom'] X = d['X'] Y = d['Y'] Z = d['Z'] # Check of waypoint al bestaat if Waypoint.objects.filter(name=gefFileNaam).exists(): print ("Waypoint %s bestaat al"%(gefFileNaam)) w = Waypoint.objects.get(name=gefFileNaam) w.name=gefFileNaam w.download_gef=(Hyperlink_root+gefFileNaam) w.company=CompanyID w.projectid=ProjectID w.project_naam = ProjectNaam w.startdatum=StartDatum w.username=User w.soortgef=SoortGef w.x=X w.y=Y w.z=Z w.geometry=PointGeom w.save() print_log(request, "SUCCESS", '%s: succesvol overschreven!'%gefFile) # Waypoint bestaat nog niet. nieuw object opslaan else: waypoint = Waypoint( name=gefFileNaam, download_gef=(Hyperlink_root+gefFileNaam), company=CompanyID, project_id=ProjectID, project_naam = ProjectNaam, startdatum=StartDatum, username=User, soortgef=SoortGef, x=X, y=Y, z=Z, geometry=PointGeom) waypoint.save() print_log(request, "SUCCESS", '%s: upload succesvol!'%(gefFileNaam))
def upload(request): 'Upload waypoints' # If the form contains an upload, if 'gpx' in request.FILES: # Get gpxFile = request.FILES['gpx'] # Save targetPath = tempfile.mkstemp()[1] destination = open(targetPath, 'wt') for chunk in gpxFile.chunks(): destination.write(chunk) destination.close() # Parse dataSource = DataSource(targetPath) layer = dataSource[0] waypointNames = layer.get_fields('name') waypointGeometries = layer.get_geoms() for waypointName, waypointGeometry in itertools.izip(waypointNames, waypointGeometries): waypoint = Waypoint(name=waypointName, geometry=waypointGeometry.wkt) waypoint.save() # Clean up os.remove(targetPath) # Redirect return HttpResponseRedirect(reverse('waypoints-index'))
def upload(request): if 'gpx' in request.FILES: # Get try: gpxFile = request.FILES['gpx'] except IOError: print("gpx") handle, targetPath = tempfile.mkstemp() destination = os.fdopen(handle, 'wb') for chunk in gpxFile.chunks(): destination.write(chunk) destination.close() # Parse dataSource = DataSource(targetPath) layer = dataSource[0] waypointNames = layer.get_fields('name') waypointGeometries = layer.get_geoms() # name change from Python 2 to 3 try: zip_longest = itertools.zip_longest # Python 3 except AttributeError: zip_longest = itertools.izip_longest # Python 2 for waypointName, waypointGeometry in zip_longest( waypointNames, waypointGeometries): waypoint = Waypoint(name=waypointName, geometry=waypointGeometry.wkt) waypoint.save() # Clean up: took out the os.remove(targetPath) return HttpResponseRedirect(reverse('waypoints-index'))
def upload(request): if 'gpx' in request.FILES: # Get try: gpxFile = request.FILES['gpx'] except IOError: print("gpx") handle, targetPath = tempfile.mkstemp() destination = os.fdopen(handle, 'wb') for chunk in gpxFile.chunks(): destination.write(chunk) destination.close() # Parse dataSource = DataSource(targetPath) layer = dataSource[0] waypointNames = layer.get_fields('name') waypointGeometries = layer.get_geoms() # name change from Python 2 to 3 try: zip_longest = itertools.zip_longest # Python 3 except AttributeError: zip_longest = itertools.izip_longest # Python 2 for waypointName, waypointGeometry in zip_longest(waypointNames, waypointGeometries): waypoint = Waypoint(name=waypointName, geometry=waypointGeometry.wkt) waypoint.save() # Clean up: took out the os.remove(targetPath) return HttpResponseRedirect(reverse('waypoints-index'))